几天来,我一直在尝试找出如何正确更改 Ubuntu 的 IP 路由。我知道我必须编辑/etc/network/interfaces
,但找不到如何正确执行此操作。
我的网络有点复杂。我连接了数据棒,用于另一台计算机。但我不喜欢 Ubuntu 自己使用它们。
换句话说,我希望始终使用enp31s0
(局域网)而不使用任何其他方式。因此,如果局域网出现故障,ubuntu 将无法连接互联网。
ip route
default via 192.168.0.1 dev enp31s0 src 192.168.0.107 metric 202
default via 192.168.30.1 dev eth0 src 192.168.30.2 metric 203
default via 192.168.30.5 dev eth1 src 192.168.30.6 metric 204
default via 192.168.30.53 dev eth2 src 192.168.30.54 metric 205
default via 192.168.30.9 dev eth3 src 192.168.30.10 metric 206
default via 192.168.30.61 dev eth7 src 192.168.30.62 metric 210
default via 192.168.30.13 dev eth9 src 192.168.30.14 metric 212
default via 192.168.30.17 dev eth10 src 192.168.30.18 metric 213
default via 192.168.30.29 dev eth13 src 192.168.30.30 metric 216
default via 192.168.30.21 dev eth14 src 192.168.30.22 metric 218
default via 192.168.30.25 dev eth17 src 192.168.30.26 metric 222
default via 192.168.30.37 dev eth18 src 192.168.30.38 metric 223
default via 192.168.30.33 dev eth19 src 192.168.30.34 metric 224
default via 192.168.30.41 dev eth20 src 192.168.30.42 metric 225
default via 192.168.30.45 dev eth21 src 192.168.30.46 metric 227
default via 192.168.30.49 dev rename28 src 192.168.30.50 metric 228
default via 192.168.30.57 dev eth4 src 192.168.30.58 metric 264
default via 192.168.30.93 dev rename82 src 192.168.30.94 metric 282
default via 192.168.30.97 dev rename94 src 192.168.30.98 metric 294
default via 192.168.30.73 dev rename95 src 192.168.30.74 metric 295
default via 192.168.30.77 dev rename96 src 192.168.30.78 metric 296
default via 192.168.30.69 dev rename97 src 192.168.30.70 metric 297
default via 192.168.30.85 dev enx001e101f0000 src 192.168.30.86 metric 298
default via 192.168.30.81 dev rename100 src 192.168.30.82 metric 300
default via 192.168.30.89 dev rename101 src 192.168.30.90 metric 301
10.8.0.0/24 dev tun1 proto kernel scope link src 10.8.0.5
10.8.1.0/24 dev tun0 proto kernel scope link src 10.8.1.2
10.8.6.0/24 dev tun2 proto kernel scope link src 10.8.6.6
169.254.0.0/16 dev tun1 scope link metric 1000
192.168.0.0/24 dev enp31s0 proto kernel scope link src 192.168.0.107 metric 202
192.168.30.0/30 dev eth0 proto kernel scope link src 192.168.30.2 metric 203
192.168.30.4/30 dev eth1 proto kernel scope link src 192.168.30.6 metric 204
192.168.30.8/30 dev eth3 proto kernel scope link src 192.168.30.10 metric 206
192.168.30.12/30 dev eth9 proto kernel scope link src 192.168.30.14 metric 212
192.168.30.16/30 dev eth10 proto kernel scope link src 192.168.30.18 metric 213
192.168.30.20/30 dev eth14 proto kernel scope link src 192.168.30.22 metric 218
192.168.30.24/30 dev eth17 proto kernel scope link src 192.168.30.26 metric 222
192.168.30.28/30 dev eth13 proto kernel scope link src 192.168.30.30 metric 216
192.168.30.32/30 dev eth19 proto kernel scope link src 192.168.30.34 metric 224
192.168.30.36/30 dev eth18 proto kernel scope link src 192.168.30.38 metric 223
192.168.30.40/30 dev eth20 proto kernel scope link src 192.168.30.42 metric 225
192.168.30.44/30 dev eth21 proto kernel scope link src 192.168.30.46 metric 227
192.168.30.48/30 dev rename28 proto kernel scope link src 192.168.30.50 metric 228
192.168.30.52/30 dev eth2 proto kernel scope link src 192.168.30.54 metric 205
192.168.30.56/30 dev eth4 proto kernel scope link src 192.168.30.58 metric 100
192.168.30.56/30 dev eth4 proto kernel scope link src 192.168.30.58 metric 264
192.168.30.60/30 dev eth7 proto kernel scope link src 192.168.30.62 metric 210
192.168.30.64/30 dev rename102 proto kernel scope link src 192.168.30.66 metric 302
192.168.30.68/30 dev rename97 proto kernel scope link src 192.168.30.70 metric 297
192.168.30.72/30 dev rename95 proto kernel scope link src 192.168.30.74 metric 295
192.168.30.76/30 dev rename96 proto kernel scope link src 192.168.30.78 metric 296
192.168.30.80/30 dev rename100 proto kernel scope link src 192.168.30.82 metric 300
192.168.30.84/30 dev enx001e101f0000 proto kernel scope link src 192.168.30.86 metric 298
192.168.30.88/30 dev rename101 proto kernel scope link src 192.168.30.90 metric 301
192.168.30.92/30 dev rename82 proto kernel scope link src 192.168.30.94 metric 282
192.168.30.96/30 dev rename94 proto kernel scope link src 192.168.30.98 metric 294
答案1
您应该选择路由default via 192.168.0.1 dev enp31s0
并删除路由表中的所有其他路由。使用ip route del
删除它们。如果其他路由为您提供互联网访问并且通过不同的度量连接,那么最好的方法是断开接口。
另一个选择是使用 iptables 将数据包丢弃0.0.0.0
到特定接口,这会使事情变得更加复杂。