天天看點

linux 修改ip後不能通路大網的問題解決

這幾天研究修改linux的臨時IP遇到的問題:

自動配置設定ip時可以正常通路大網,修改ip後,就不能通路大網。

搜尋網上許多解決方法,基本都是說DNS沒正确解析,是以不上網了。

可這些都沒解決我的問題。

後來對比修改ip前後的route的結果,發現default的網關消失了。

修改ip前

route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1   0.0.0.0         UG    0      0        0 wlan0
192.168.1.0   *               255.255.255.0   U     0      0        0 wlan0
           
#修改ip後
ifconfig eth0 192.168.1.120 netmask 255.255.255.0

route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0   *               255.255.255.0   U     0      0        0 wlan0
           

 重新設定網關後,就可正常通路大網了。

route add default gw 192.168.1.1 

#ping測試一下
ping 8.8.8.8

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=148 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=111 time=141 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=111 time=152 ms
64 bytes from 8.8.8.8: icmp_seq=7 ttl=111 time=143 ms

           

上面的網關位址192.168.1.1 根據你自己的系統決定。

意外收獲,原來改ip後 PuTTY就不能連接配接,一直郁悶ing,

重新設定網關後PuTTY 居然可以連接配接了。

繼續閱讀