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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM