通过虚拟机路由流量

通过虚拟机路由流量

我有OpenWRT在虚拟机中运行。其网络适配器桥接到主机。

主机 ifconfig

root@michael-VirtualBox:/home/michael/Scripts/python# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:8c:1b:c3  
          inet addr:10.0.2.16  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe8c:1bc3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:784199 errors:0 dropped:0 overruns:0 frame:0
          TX packets:452028 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:953595278 (953.5 MB)  TX bytes:30390503 (30.3 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:4393 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4393 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:386626 (386.6 KB)  TX bytes:386626 (386.6 KB)

OpenWRT ifconfig

root@OpenWrt:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:8A:24:52  
          inet addr:10.0.2.18  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe8a:2452/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5241 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5130 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:461014 (450.2 KiB)  TX bytes:1198305 (1.1 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:262 errors:0 dropped:0 overruns:0 frame:0
          TX packets:262 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:20416 (19.9 KiB)  TX bytes:20416 (19.9 KiB)

如果我想说,ping8.8.8.8从我的主机,并通过虚拟机进行路由,我可以从主机执行以下操作吗?

route add 8.8.8.8 gw 10.0.2.18

tcpdump如果是这样,我是否应该能够看到虚拟机端的ping 消息?

当我在 OpenWRT VM 上执行操作时tcpdump,它似乎并没有在主机端输出每次 ping 的信息。

在我这样做之后route add 8.8.8.8 gw 10.0.2.18,我每次 ping 都会收到回复。

有什么方法可以验证 ping 是否被正确路由?

更新

输出tracepath 8.8.8.8

root@michael-VirtualBox:/home/michael/Scripts/python# tracepath 8.8.8.8
 1:  michael-VirtualBox.local                              0.189ms pmtu 1500
 1:  10.0.2.2                                              0.393ms 
 1:  10.0.2.2                                              0.539ms 
 2:  no reply
 3:  no reply
 4:  no reply
 5:  no reply
 6:  no reply
 7:  no reply
 8:  no reply
 9:  no reply
10:  no reply
11:  no reply
12:  no reply
13:  no reply
14:  no reply
15:  no reply
16:  no reply
17:  no reply
18:  no reply
19:  no reply
20:  no reply
21:  no reply
22:  no reply
23:  no reply
24:  no reply
25:  no reply
26:  no reply
27:  no reply
28:  no reply
29:  no reply
30:  no reply
31:  no reply
     Too many hops: pmtu 1500
     Resume: pmtu 1500

附言root@michael-VirtualBox 是我的主机(也在虚拟机中运行:P)

答案1

为此,您可以使用tracepath。它将显示您 ping 所经过的每个主机。

别忘了检查防火墙!

相关内容