例如我的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