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
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :0c::6e:: brd ff:ff:ff:ff:ff:ff
inet 192.168.178.132/ brd 192.168.178.255 scope global eth0
inet6 fe80::20c:29ff:fe6e:/ scope link
valid_lft forever preferred_lft forever
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (115.239.211.112) () bytes of data.
bytes from www.baidu.com (115.239.211.112): icmp_seq= ttl= time=7.45 ms
bytes from www.baidu.com (115.239.211.112): icmp_seq= ttl= time=8.32 ms
bytes from www.baidu.com (115.239.211.112): icmp_seq= ttl= time=8.09 ms
完成!