路由问题 OpenVPN / KVM

路由问题 OpenVPN / KVM

我已经使用 KVM 和 OpenVPN 设置了一台租用的根服务器。为了管理没有公共 IP 的虚拟机,虚拟机客户机连接到主机/客户机专用网络:10.10.10.0。

现在我想通过 OpenVPN 访问 VM 客户机,ovpn 配置正常(已在 ovpn 论坛中询问)。我可以连接到 KVM 主机/ovpn 服务器并 ping 10.10.10.1 (virbr1)。

但是我无法通过 VPN 隧道 ping 通 10.10.10.2(虚拟机客户机),我已将推送“路由 10.10.10.0 255.255.255.0”添加到 ovpn 配置中。

我认为我有一个路由问题,但我无法解决它。

kvm/ovpn服务器的路由:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         148.251.139.129 0.0.0.0         UG    0      0        0 eth0
10.8.0.0        10.8.0.2        255.255.255.0   UG    0      0        0 tun0
10.8.0.2        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
10.10.10.0      0.0.0.0         255.255.255.0   U     0      0        0 virbr1
148.251.139.128 148.251.139.129 255.255.255.224 UG    0      0        0 eth0
148.251.139.128 0.0.0.0         255.255.255.224 U     0      0        0 eth0
148.251.164.152 0.0.0.0         255.255.255.255 UH    0      0        0 br0
148.251.164.153 0.0.0.0         255.255.255.255 UH    0      0        0 br0
148.251.164.154 0.0.0.0         255.255.255.255 UH    0      0        0 br0
148.251.164.155 0.0.0.0         255.255.255.255 UH    0      0        0 br0
148.251.164.156 0.0.0.0         255.255.255.255 UH    0      0        0 br0
148.251.164.157 0.0.0.0         255.255.255.255 UH    0      0        0 br0
148.251.164.158 0.0.0.0         255.255.255.255 UH    0      0        0 br0
148.251.164.159 0.0.0.0         255.255.255.255 UH    0      0        0 br0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

我想要连接的虚拟机的路由:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.122.1   0.0.0.0         UG    0      0        0 eth0
10.10.10.0      0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0

kvm/ovpn 服务器的 ifconfig:

br0       Link encap:Ethernet  HWaddr 06:56:c4:f6:f4:75  
          inet addr:148.251.139.133  Bcast:148.251.139.133  Mask:255.255.255.255
          inet6 addr: fe80::456:c4ff:fef6:f475/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:175793 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:7383498 (7.3 MB)

eth0      Link encap:Ethernet  HWaddr 44:8a:5b:9b:a0:7d  
          inet addr:148.251.139.133  Bcast:148.251.139.159  Mask:255.255.255.224
          inet6 addr: 2a01:4f8:210:4384::2/64 Scope:Global
          inet6 addr: fe80::468a:5bff:fe9b:a07d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:285513 errors:0 dropped:0 overruns:0 frame:0
          TX packets:224255 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:87609913 (87.6 MB)  TX bytes:67108015 (67.1 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:28895 errors:0 dropped:0 overruns:0 frame:0
          TX packets:28895 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:50248836 (50.2 MB)  TX bytes:50248836 (50.2 MB)

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.8.0.1  P-t-P:10.8.0.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:180 errors:0 dropped:0 overruns:0 frame:0
          TX packets:242 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:14408 (14.4 KB)  TX bytes:23872 (23.8 KB)

virbr0    Link encap:Ethernet  HWaddr 52:54:00:76:9b:d5  
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:233 errors:0 dropped:0 overruns:0 frame:0
          TX packets:218 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:32877 (32.8 KB)  TX bytes:35360 (35.3 KB)

virbr1    Link encap:Ethernet  HWaddr 52:54:00:4c:37:b5  
          inet addr:10.10.10.1  Bcast:10.10.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1067 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1414 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:145911 (145.9 KB)  TX bytes:127823 (127.8 KB)

vnet0     Link encap:Ethernet  HWaddr fe:54:00:15:93:50  
          inet6 addr: fe80::fc54:ff:fe15:9350/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:233 errors:0 dropped:0 overruns:0 frame:0
          TX packets:54016 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:36139 (36.1 KB)  TX bytes:2833008 (2.8 MB)

vnet1     Link encap:Ethernet  HWaddr fe:54:00:ff:e6:3e  
          inet6 addr: fe80::fc54:ff:feff:e63e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1067 errors:0 dropped:0 overruns:0 frame:0
          TX packets:55212 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:160849 (160.8 KB)  TX bytes:2925471 (2.9 MB)

如果我通过 tun0 设备 ping 虚拟机,什么也不会发生:

ping -I tun0 10.10.10.2
PING 10.10.10.2 (10.10.10.2) from 10.8.0.1 tun0: 56(84) bytes of data.

如果我通过 vpn 隧道和 tcpdump tun0 从我的笔记本电脑进行 ping 操作:

15:58:52.723495 IP (tos 0xc0, ttl 64, id 20421, offset 0, flags [none], proto ICMP (1), length 112)
    10.8.0.1 > 10.8.0.6: ICMP 10.10.10.2 protocol 1 port 24859 unreachable, length 92
    IP (tos 0x0, ttl 63, id 53773, offset 0, flags [none], proto ICMP (1), length 84)
    10.8.0.6 > 10.10.10.2: ICMP echo request, id 44339, seq 4, length 64

如果在从 ovpn 客户机 ping 时使用 tcpdump virbr1,则根本不会显示任何内容(icmp)

但是我可以从虚拟机 ping 10.8.0.6(我的笔记本电脑),因此系统似乎知道返回的路由。我假设我在某处缺少一条路由,它将 tun0 连接到 virbr1。但我尝试的一切都改变了一切。

感谢您的帮助。

编辑:测试期间,UFW 在 KVM 主机和客户机上被禁用

答案1

好的,问题解决了:

问题出在 libvirt 中的配置错误。虚拟网桥配置为隔离模式,切换到路由虚拟网络并将路由:10.8.0.0/24 gw 1​​0.10.10.1 添加到 VM 客户机后,一切正常。

相关内容