我刚刚在租用的根服务器上设置了一个 OpenVPN 服务器。我可以 ping OpenVPN 服务器 IP,但无法连接或 ping OpenVPN 服务器网络上的其他机器 (VM)。根据官方 OpenVPN doku,我在 server.conf 中添加了“推送路由”,以便能够访问服务器网络上的其他机器。
服务器.conf:
port 1194
proto udp
dev tun
ca ca.crt
cert ex1.crt
key ex1.key # This file should be kept secret
dh dh2048.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "route 10.10.10.0 255.255.255.0"
keepalive 10 120
tls-auth ta.key 0 # This file is secret
cipher AES-256-CBC-HMAC-SHA1
cipher AES-256-CBC
tls-cipher TLS-DHE-RSA-WITH-AES-256-CBC-SHA
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
来自 openvpn 服务器的 ifconfig:
br0 Link encap:Ethernet HWaddr 62:e6:d9:07:46:c2
inet addr:148.251.139.133 Bcast:148.251.139.133 Mask:255.255.255.255
inet6 addr: fe80::60e6:d9ff:fe07:46c2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:69028 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:2899368 (2.8 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:78430 errors:0 dropped:0 overruns:0 frame:0
TX packets:82129 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6908929 (6.9 MB) TX bytes:52446354 (52.4 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:21482 errors:0 dropped:0 overruns:0 frame:0
TX packets:21482 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:47236296 (47.2 MB) TX bytes:47236296 (47.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:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:672 (672.0 B) TX bytes:728 (728.0 B)
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:277 errors:0 dropped:0 overruns:0 frame:0
TX packets:269 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:41733 (41.7 KB) TX bytes:45532 (45.5 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:2258 errors:0 dropped:0 overruns:0 frame:0
TX packets:2446 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:370903 (370.9 KB) TX bytes:197319 (197.3 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:277 errors:0 dropped:0 overruns:0 frame:0
TX packets:75139 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:45611 (45.6 KB) TX bytes:3938924 (3.9 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:2258 errors:0 dropped:0 overruns:0 frame:0
TX packets:77316 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:402515 (402.5 KB) TX bytes:4090711 (4.0 MB)
我尝试连接的服务器网络上的机器是 KVM VM,其 IP 为:10.10.10.2。我可以 ping 10.10.10.1(virbr1 的 IP)。ovpn/kvm 服务器上的 Ipv4 转发已启用。测试时,我还停用了 ovpn 服务器和 VM 的 ufw 防火墙。
如果我从 ovpn 客户端 ping 10.10.10.2,我会在服务器上得到以下 tcpdump(tun0):
11:54:46.002533 IP 10.8.0.6 > 10.10.10.2:ICMP 回显请求,id 17629,序号 0,长度 64 11:54:46.002602 IP 10.8.0.1 > 10.8.0.6:ICMP 10.10.10.2 协议 1 端口 10088 无法访问,长度 92
而 virbr1 桥(虚拟机网络:10.10.10.2)的 tcpdump 什么都没显示。我假设 openvpn 服务器没有将数据包转发到 virbr1。
openvpn服务器的路由:
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
我真的被这个问题难住了,如果能够理解这个问题并解决它那就太好了。
答案1
好的,问题解决了:
问题出在 libvirt 中的配置错误。虚拟网桥配置为隔离模式,切换到路由虚拟网络并将路由:10.8.0.0/24 gw 10.10.10.1 添加到 VM 客户机后,一切正常。