centos7设置静态IP连接外网

本小妞迷上赌 提交于 2019-12-07 02:55:50

ISO镜像的centos7系统刚装好,网络可能不通,所以要检查网络。
ping 外网检测

# ping www.baidu.com

如果未能ping通,请依次检测ip,route

# vi /etc/sysconfig/network-script/ifcfg-eth0

可以先将dhcp动态分配IP改为静态IP

#cgls 
#BOOTPROTO=dhcp
BOOTPROTO=static
IPADDR=172.16.5.133
GATEWAY=172.16.1.1
NETMASK=255.255.0.0
ONBOOT=yes

重启网卡使其生效

# service network restart

检查路由

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.1.1      0.0.0.0         UG    100    0        0 eth0
169.254.169.254 172.16.88.100   255.255.255.255 UGH   100    0        0 eth0
172.16.0.0      0.0.0.0         255.255.0.0     U     100    0        0 eth0 

如果你缺失第一个路由,是肯定无法ping通外网的这里写代码片
添加dns

# vim /etc/resolv.conf
nameserver 114.114.114.114

添加路由

# route add default gw 172.16.1.1

试一下ping百度

# ping www.baidu.com
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!