centos7设置静态IP连接外网

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

# ping www.baidu.com
  • 1

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

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

可以先将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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

重启网卡使其生效

# service network restart
  • 1

检查路由

# route -n
  • 1
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 
  • 1
  • 2
  • 3
  • 4
  • 5

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

# vim /etc/resolv.conf
  • 1
nameserver 114.114.114.114
  • 1

添加路由

# route add default gw 172.16.1.1
  • 1

试一下ping百度

# ping www.baidu.com
  • 1

猜你喜欢

转载自blog.csdn.net/ruthywei/article/details/79746840