1. 程式人生 > 其它 >linux 區域網內通外網不通gateway不生效解決方案

linux 區域網內通外網不通gateway不生效解決方案

當前作業系統未debian 10

interface內容

auto eth1
allow-hotplug eth1
iface eth1 inet static
address 192.168.6.218
netmask 255.255.0.0
gateway 192.168.6.1
dns-nameservers 202.96.128.86
hwaddress ether ca:9f:57:40:45:7d

 

問題:ping內網通,跨網段也同,ping 192.168.6.1 192.168.1.1 也通 ,百度ip   ping 202.108.22.5 不通

檢視問題原因:

ip地址跟dns無關,但是ping下dns發現 8.8.8.8 114.114.114.114  202.96.128.86都不通,說明本機資訊路由不到外網

1.有限制得情況下檢視到外網得路由器是否繫結內網ip和對應mac

2.檢視本地路由是否有到閘道器得資訊

netstat -rn 檢視本地路由表顯示

Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.0.0  0.0.0.0  255.255.0.0      U 0 0 0 eth1

沒有本地到192.168.6.1路由資訊,增加一條對應路由

 route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.6.1

netstat -rn 檢視本地路由表顯示

Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.6.1 0.0.0.0 UG 0 0 0 eth1
192.168.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1

有了一條到gateway的路由

再ping 202.108.22.5 通了