简介:我想连接到我的VPN,并有权访问某些服务器,但对于所有其他stream量,我想使用我的常规networking。
我已经在我的VPS上安装了一个OpenVPN服务器,我的server.conf文件看起来像这样:
port 1194 proto udp dev tun ca ca.crt cert server.crt key server.key # This file should be kept secret dh dh2048.pem server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt keepalive 10 120 comp-lzo user nobody group nogroup persist-key persist-tun status openvpn-status.log log /var/log/openvpn.log verb 4 push "route 10.132.0.0 255.255.0.0"
我使用下面的.ovpn文件来设置VPN连接:
client dev tun proto udp remote <my.vpn.server.com> 1194 nobind user nobody group nogroup persist-key persist-tun remote-cert-tls server comp-lzo verb 3 <ca>....</ca> <cert>...</cert> <key>...</key>
最后,在VPN连接的networkingpipe理器中,在IPv4设置下,我确保将“方法”设置为“仅自动(VPN)地址”。
VPN连接正常,我可以访问我需要的所有内部服务器(10.132.xx),但是我无法访问任何其他内容(如google.com)。 我希望我的eth0设置被用于除了10.132.xx IP之外的任何事情,我想通过VPN路由。
聚苯乙烯基于其他文章我已经尝试使用.ovpn文件中的no-pull ,并添加在我的route设置,但无济于事。
编辑1 :
连接到VPN时运行ip a和traceroute结果:
$ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:dc:a6:ef brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0 valid_lft 86320sec preferred_lft 86320sec inet6 fe80::f3d1:6eb3:e13e:d61b/64 scope link valid_lft forever preferred_lft forever 15: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 100 link/none inet 10.8.0.6 peer 10.8.0.5/32 brd 10.8.0.6 scope global tun0 valid_lft forever preferred_lft forever $ traceroute google.com google.com: Temporary failure in name resolution Cannot handle "host" cmdline arg `google.com' on position 1 (argc 1)
编辑2 : ip r结果
$ ip r default via 10.8.0.5 dev tun0 proto static metric 50 default via 10.0.2.2 dev eth0 proto static metric 100 10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100 10.8.0.1 via 10.8.0.5 dev tun0 proto static metric 50 10.8.0.5 dev tun0 proto kernel scope link src 10.8.0.6 metric 50 10.132.0.0/16 via 10.8.0.5 dev tun0 proto static metric 50 104.236.239.153 via 10.0.2.2 dev eth0 proto static metric 100 169.254.0.0/16 dev eth0 scope link metric 1000
我设法通过玩客户端GUI(Ubuntu NetworkManager)来获得所需的效果。 我必须确保IPv4 Settings -> Routes为“使用此连接仅用于其networking上的资源”checkbox被选中:
我不完全确定在.ovpn文件中需要做什么来复制这个。
我的路由performance在如下所示:
$ sudo netstat -r -n Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 10.8.0.1 10.8.0.5 255.255.255.255 UGH 0 0 0 tun0 10.8.0.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun0 10.132.0.0 10.8.0.5 255.255.0.0 UG 0 0 0 tun0 104.236.239.153 10.0.2.2 255.255.255.255 UGH 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
请记住,我在我的server.conf push "route 10.132.0.0 255.255.0.0" ,以便解释10.132.0.0的条目,从而为什么我现在可以访问我的服务器,而其他的东西都是在VPN之外路由(即0.0.0.0入口)
如果没有在GUI中检查这个设置,我的路由表就像这样:
$ sudo netstat -r -n Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.8.0.5 0.0.0.0 UG 0 0 0 tun0 0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 10.8.0.1 10.8.0.5 255.255.255.255 UGH 0 0 0 tun0 10.8.0.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun0 10.132.0.0 10.8.0.5 255.255.0.0 UG 0 0 0 tun0 104.236.239.153 10.0.2.2 255.255.255.255 UGH 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
我的猜测是,第一个0.0.0.0条目(默认路由)搞乱了一切。
nm-connection-editor中的“ 仅对其networking中的资源使用此连接 ”checkbox控制NetworkManager是否应通过VPN添加默认路由。 如果检查与您一样,只有指向VPN子网的数据包将通过VPN网关,系统将使用现有的默认路由用于其他目的地。
您可以使用nmcli从命令行更改相同的设置:
nmcli connection modify <VPN connection> ipv4.never-default yes
如果你的服务器是/ 24 ( 10.8.0.X )
服务器10.8.0.0 255.255.255.0
和路由为您的客户是/ 16 ( 10.132.XX )
推“路由10.132.0.0 255.255.0.0”
也许这不会是一个冲突?
为了阐述jdmorei的答案,你需要所谓的“分离隧道”的VPN – 你实际上几乎有解决scheme,当你说: PS based on other articles I've tried using no-pull in the .ovpn file and adding in my route settings there but to no avail. 。
你会在你的ovpn文件中需要以下内容:
route-nopull # Make sure not to pull the default routes route 10.8.0.0 255.255.255.0 # Route the /24 of 10.8.0.0 across the VPN route 192.168.2.2 255.255.255.255 # Route the /32 (single IP) across the VPN
现在关键在于,由于您正在运行Windows,因此您必须以pipe理员身份运行openvpn应用程序。 如果你不这样做,你会看到日志中的条目,如:
Sat Nov 13 11:31:05 2010 ROUTE: route addition failed using CreateIpForwardEntry : Access denied. [status=5 if_index=11] The requested operation requires elevation. Sat Nov 13 11:31:05 2010 ERROR: Windows route add command failed [adaptive]: ret urned error code 1 Sat Nov 13 11:31:05 2010 Initialization Sequence Completed