美文网首页操作系统
ubuntu 有线和无线同时存在时,通过命令行设置默认网关

ubuntu 有线和无线同时存在时,通过命令行设置默认网关

作者: xiaocai888 | 来源:发表于2018-09-11 09:50 被阅读1次

场景:开发板通过网线连接到本地的测试电脑,又连接wifi,从Internet下载文件,比如git clone , git pull。但是,一般开机会有两个默认网关。一个是有线的,一个是无线的。会导致电脑不知道从哪个发送网络数据。

1. 查看当前的网关命令 ip route show

如果你的开发版同时连接了两个网络,就会有类似下面的输出:

default via 192.168.137.1 dev eth0  proto static  metric 100 
default via 192.168.198.1 dev wlan0  proto static  metric 600 
169.254.0.0/16 dev wlan0  scope link  metric 1000 
192.168.137.0/24 dev eth0  proto kernel  scope link  src 192.168.137.4  metric 100 
192.168.198.0/24 dev wlan0  proto kernel  scope link  src 192.168.198.176  metric 600 

2. 删除有线的默认网关sudo route del default gw 192.168.137.1

删除后,可以发现只有一个默认网关了。

default via 192.168.198.1 dev wlan0  proto static  metric 600 
169.254.0.0/16 dev wlan0  scope link  metric 1000 
192.168.137.0/24 dev eth0  proto kernel  scope link  src 192.168.137.4  metric 100 
192.168.198.0/24 dev wlan0  proto kernel  scope link  src 192.168.198.176  metric 600 

相关文章

网友评论

    本文标题:ubuntu 有线和无线同时存在时,通过命令行设置默认网关

    本文链接:https://www.haomeiwen.com/subject/ouuygftx.html