centos6 内网可达,外网不可达 Network is unreachable

错误内容

[root@djx-2 yum.repos.d]# ping 3.0.82.21
connect: Network is unreachable
[root@djx-2 yum.repos.d]# ping www.baidu.com
connect: Network is unreachable

局域网和ping网关都是通的,ping外网就出现 Network is unreachable
检查配置文件 ,dns设置没有问题,onboot也设置为yes.

问题原因

本地没有默认路由。

正常的默认网络设置是有默认路由的。

[root@djx-2 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.1.254   0.0.0.0         UG    0      0        0 eth0
[root@djx-2 ~]# ip route
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.201 
169.254.0.0/16 dev eth0  scope link  metric 1002 
default via 192.168.1.254 dev eth0 

以default开头的就是默认的。

而我们出错的网络配置默认是没有默认路由的。如下图。

[root@djx-2 ~]# ip route
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.201 
169.254.0.0/16 dev eth0  scope link  metric 1002 
[root@djx-2 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0

解决方法

添加默认路由:

route add default  gw  192.168.1.254 (这个ip地址是网关地址)

我们再查看下我们默认的配置。

[root@djx-2 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.1.254   0.0.0.0         UG    0      0        0 eth0
[root@djx-2 ~]# ip route
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.201 
169.254.0.0/16 dev eth0  scope link  metric 1002 
default via 192.168.1.254 dev eth0 

我们可以查看到我们的默认配置已经添加上去了。我们再去ping www.baidu.com .
就可以了。

转载于:https://www.cnblogs.com/operationhome/p/10207257.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值