0

Windows和Linux系统设置静态IP

 1 year ago
source link: https://www.daguanren.cc/post/config_static_ip.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ubuntu系统设置静态ip

设置静态ip的方法如下:

1.编辑 /etc/network/interfaces

#auto lo#iface lo inet loopback

并在下面添加如下:

# The primary network interfaceauto eth0

继续添加和静态ip有关的参数:

# The primary network interfaceiface eth0 inet staticaddress 172.17.194.*netmask 255.255.255.0gateway 192.17.194.1routeros

2.编辑 /etc/resolv.conf,设置dns

nameserver 172.16.100.7nameserver 172.16.100.8nameserver 172.16.100.9

3.执行下面两个命令,启用新设置

$sudo ifup eth0

(关闭:$sudo ifdown eth0)

sudo /etc/init.d/networking restart

注意:重启后,/etc/resolv.conf此文件配置的 dns 又被自动修改为默认值。所以需要永久性修改DNS。方法如下:

cd /etc/resolvconf/resolv.conf.d/

修改base

nameserver 172.16.100.7nameserver 172.16.100.8nameserver 172.16.100.9

Centos系统设置静态ip

1.查看网络MAC地址

[root@centos ~]# cat /etc/udev/rules.d/70-persistent-net.rules

显示如下信息

# PCI device 0x15ad:0x07b0 (vmxnet3)SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:94:04:3c", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"# PCI device 0x15ad:0x07b0 (vmxnet3)  SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:94:53:24", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"routeros

eth0:对应第一张网卡,eth1:对就第二张网卡。当前使用eth0连接路由器,eth1保留(服务器一般用来,连接其它主机)

2.修改网卡(只要修改HWADDR就可以了)  

[root@centos ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

   打开文件,修改以下内容并保存   

DEVICE=eth0          #对应第一张网卡  TYPE=Ethernet  ONBOOT=yes          #是否启动时运行  NM_CONTROLLED=yes  BOOTPROTO=static       #使用静态IP,而不是由DHCP分配IP  DEFROUTE=yes  IPV4_FAILURE_FATAL=yes  IPV6INIT=no  NAME="System eth0"      #名称  HWADDR=00:50:56:94:04:3C  #必须对应eth0的MAC地址(/etc/udev/rules.d/70-persistent-net.rules)  PEERDNS=yes  PEERROUTES=yes  IPADDR=172.17.194.*     #指定本机IP地址  NETMASK=255.255.255.0    #指定子网掩码  GATEWAY=192.17.194.1     #指定网关routeros
3.设置DNS服务器/etc/resolv.conf(如果不能自动生成则需要设置)
nameserver 172.16.100.7nameserver 172.16.100.9nameserver 172.17.193.82nameserver 172.16.100.8css

4.重启网络服务

service network restart

Win7系统设置静态ip

具体配置方法如下图所示:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK