CentOS 6.5、6.7 设置静态 ip 教程,可以ping通外网:www.baidu.com
①. 网络适配器(VMware Network Adapter) 选择NAT模式
②. 设置静态 ip
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #描述网卡对应的设备别名 BOOTPROTO=static #设置网卡获得 ip 的方式,选项:static【静态指定】、dhcp【协议】、bootp【协议】 HWADDR=00:0c:29:24:e2:1b IPV6INIT=no NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet UUID="e6ecacb0-4608-47f9-b56c-49c5d2f61e2a" IPADDR=192.168.178.131 #设置自己喜欢的ip地址,保持在同一个网段 NETMASK=255.255.255.0 #网卡对应的网络掩码 GATEWAY=192.168.178.2 #保持在同一网段,末尾设置为2 DNS1=192.168.178.2 #DNS1服务器的地址,保持在同一网段,末尾设置为2 USERCTL=no
③. vi /etc/sysconfig/network
NETWORKING=yes #确认是否设置为yes
④. 重启服务
service network restart
⑤. 验证
[root@localhost ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:6e:49:33 brd ff:ff:ff:ff:ff:ff inet 192.168.178.132/24 brd 192.168.178.255 scope global eth0 inet6 fe80::20c:29ff:fe6e:4933/64 scope link valid_lft forever preferred_lft forever
[root@localhost ~]# ping www.baidu.com PING www.a.shifen.com (115.239.211.112) 56(84) bytes of data. 64 bytes from www.baidu.com (115.239.211.112): icmp_seq=1 ttl=128 time=7.45 ms 64 bytes from www.baidu.com (115.239.211.112): icmp_seq=2 ttl=128 time=8.32 ms 64 bytes from www.baidu.com (115.239.211.112): icmp_seq=3 ttl=128 time=8.09 ms
完成!