Ubuntu 中的多网关路由

Ubuntu 中的多网关路由

我想在我的 Ubuntu 机器上设置多网关。1 个用于以太网,另一个用于 USB 网络共享。浏览后,从以下参考资料

https://www.thomas-krenn.com/en/wiki/Two_Default_Gateways_on_One_System

我已经根据该配置了我的系统。

配置 :

  1. 以太网作为我的默认路由
  2. USB 通过 iproute2 配置,参考上述网站

问题是我无法通过 USB 接口 ping 通。

$ ping -I usb0 www.google.co.in
PING www.google.co.in (173.194.117.88) from 192.168.42.122 usb0: 56(84) bytes of data.
icmp_seq=1 Destination Host Unreachable

但 traceroute 无法正确显示两个 USB 的网关

$ traceroute -i usb0 173.194.117.88
traceroute to 173.194.117.88 (173.194.117.88), 30 hops max, 60 byte packets
1 192.168.200.254 (192.168.200.254)  1.956 ms  2.817 ms *
2 * * *
3 * * *


$ traceroute -i eth0 173.194.117.88
traceroute to 173.194.117.88 (173.194.117.88), 30 hops max, 60 byte packets
1  192.168.200.254 (192.168.200.254)  2.020 ms  2.870 ms  3.568 ms
2  10.251.0.1 (10.251.0.1)  21.041 ms  21.437 ms  21.988 ms

路由信息

$ ip rou
default via 192.168.200.254 dev eth0  proto static 
169.254.0.0/16 dev eth0  scope link  metric 1000 
192.168.42.0/24 dev usb0  proto kernel  scope link  src 192.168.42.122      metric 1 
192.168.200.0/24 dev eth0  proto kernel  scope link  src 192.168.200.102    metric 1

$ ip route list table usbrt
default via 192.168.42.129 dev usb0 
192.168.42.0/24 dev usb0  scope link  src 192.168.42.122 

$ ip route list table usbrt
default via 192.168.42.129 dev usb0 
192.168.42.0/24 dev usb0  scope link  src 192.168.42.122 

$ ip -4 addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
 inet 192.168.200.102/24 brd 192.168.200.255 scope global eth0
4: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
inet 192.168.42.122/24 brd 192.168.42.255 scope global usb0


$ ip rule show
0:  from all lookup local 
32764:  from all to 192.168.42.122 lookup usbrt 
32765:  from 192.168.42.122 lookup usbrt 
32766:  from all lookup main 
32767:  from all lookup default

答案1

最后我得到了答案。在 ping 时使用“Interface_IP”而不是“Interface_name”
例子 :
使用

ping -i 192.168.42.122 www.google.co.in 

代替

ping -i eth0 www.google.co.in 

相关内容