Fork me on GitHub

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 .
就可以了。

posted @   自由早晚乱余生  阅读(4163)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
点击右上角即可分享
微信分享提示