宗炳煌-PHP程序猿

欢迎各位朋友前来,如果我的文章中有不对的地方,还望指正;如需转载,请注明原处

怎么将linux的动态IP设置成静态IP

例如我的eth0网卡信息如下

eth0      Link encap:Ethernet  HWaddr 00:0C:29:AA:B2:CA  
          inet addr:192.168.79.135  Bcast:192.168.79.255  Mask:255.255.254.0
          inet6 addr: fe80::20c:29ff:feaa:b2ca/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:208685 errors:0 dropped:0 overruns:0 frame:0
          TX packets:53443 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:42393010 (40.4 MiB)  TX bytes:18010745 (17.1 MiB)

现在我想把我的本地IP固定成192.168.79.133(用虚拟机的童鞋都知道,IP老是变化好麻烦)

1.查看网关地址,我的是192.168.79.2

[root@zongbh-centos6 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.78.0    0.0.0.0         255.255.254.0   U     1      0        0 eth0
0.0.0.0         192.168.79.2    0.0.0.0         UG    0      0        0 eth0

2.查看DNS,我的是192.168.79.2

[root@zongbh-centos6 ~]#  cat /etc/resolv.conf
# Generated by NetworkManager
search 7
nameserver 192.168.79.2

3.配置网卡信息,我的是 vim /etc/sysconfig/network-scripts/ifcfg-eth0

   配置信息如下

DEVICE="eth0"IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"BOOTPROTO=static
DNS1=192.168.79.2
IPADDR=192.168.79.133
NETMASK=255.255.254.0
GATEWAY=192.168.79.2

 

posted @ 2017-06-23 15:12  宗炳煌  阅读(...)  评论(...编辑  收藏