我需要设置一个 VirtualBox 虚拟机来充当 VPN。我使用 Vagrant 在 Ubuntu 14.04 LTS 客户端上创建 VM。我使用 OpenVPN 作为 Ubuntu 14.04 LTS 服务器上的 VPN 服务器。
OpenVPN 配置为在 10.8.0.0/255.255.255.0 网络上工作。VPN 服务器本身是 10.8.0.1。启动 OpenVPN 并连接到它时,任何日志文件中均未显示任何错误。
如果我将 Vagrant 配置为使用“公共网络”,那么我就可以连接到 VPN,并且可以 ping VPN 服务器:
ping 10.8.0.1 # ok
如果我将 Vagrant 配置为使用“私有网络”(具有静态定义的 192.168.50.42 IP),那么我仍然可以连接到 VPN,但无法再 ping 通 VPN 服务器. 任何尝试使用 VPN 地址 (10.8.0.1) 的操作(SSH、HTTP...)都会失败。
ping 10.8.0.1 # ko
VPN 客户端上的 ifconfig:
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:10278 errors:0 dropped:0 overruns:0 frame:0
TX packets:10278 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:920543 (920.5 KB) TX bytes:920543 (920.5 KB)
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.6 P-t-P:10.8.0.5 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:21 errors:0 dropped:0 overruns:0 frame:0
TX packets:140 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:7192 (7.1 KB) TX bytes:87424 (87.4 KB)
vboxnet0 Link encap:Ethernet HWaddr 0a:00:27:00:00:00
inet addr:192.168.50.1 Bcast:192.168.50.255 Mask:255.255.255.0
inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:486 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:63895 (63.8 KB)
wlan0 Link encap:Ethernet HWaddr 34:68:95:ee:01:75
inet addr:192.168.40.45 Bcast:192.168.40.255 Mask:255.255.255.0
inet6 addr: fe80::3668:95ff:feee:175/64 Scope:Link
inet6 addr: 2a01:e35:8af4:2240:ad1b:a074:194:ce3f/64 Scope:Global
inet6 addr: 2a01:e35:8af4:2240:3668:95ff:feee:175/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:38051 errors:0 dropped:0 overruns:0 frame:26967
TX packets:26737 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:43426256 (43.4 MB) TX bytes:3423106 (3.4 MB)
Interrupt:19
VPN 客户端上的路由:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.40.254 0.0.0.0 UG 0 0 0 wlan0
10.8.0.1 10.8.0.5 255.255.255.255 UGH 0 0 0 tun0
10.8.0.5 * 255.255.255.255 UH 0 0 0 tun0
192.168.40.0 * 255.255.255.0 U 9 0 0 wlan0
192.168.50.0 * 255.255.255.0 U 0 0 0 vboxnet0
192.168.50.42 192.168.40.254 255.255.255.255 UGH 0 0 0 wlan0
接下来是有趣的部分:删除最后一条路由使得 ping 可以正常工作:
route del -net 192.168.50.42 gw 192.168.40.254 netmask 255.255.255.255 dev wlan0
问题在于:
- this route is back everytime I reset the VM (everytime I do a vagrant up I think)
- I don't know how that would behave on a Windows client
- I need this to be as automated as possible
Questions:
- Why do I need to delete what looks like a completely unrelated route on another network for my VPN server to be reachable ? (I'm guessing this has something to do with the IP I use to connect to the VPN server...)
- How can I fix this?
Thank you,