Ubuntu
VPN 客戶端沒有網際網路連接
我在 AWS 上使用 Ubuntu 18.04 LTS,我正在嘗試使用商業 VPN (PIA) 設置拆分隧道。
我無法立即使用他們的 .opvn 配置,因為當我這樣做時,我的 SSH 連接斷開,我必須重新啟動伺服器才能恢復,所以我添加了
pull-filter ignore redirect-gateway
(這是route-nopull
.我的 .opvn 文件 (NYC.opvn) 包含以下內容:
client dev tun proto udp remote us-newyorkcity.privateinternetaccess.com 1198 resolv-retry infinite nobind persist-key persist-tun cipher aes-128-cbc auth sha1 tls-client remote-cert-tls server pull-filter ignore redirect-gateway auth-user-pass login.conf compress verb 1 reneg-sec 0
我開始隧道
sudo openvpn NYC.opvn
並得到這個:Wed Nov 20 17:34:52 2019 OpenVPN 2.4.4 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on May 14 2019 Wed Nov 20 17:34:52 2019 library versions: OpenSSL 1.1.1d 10 Sep 2019, LZO 2.08 Wed Nov 20 17:34:52 2019 TCP/UDP: Preserving recently used remote address: [AF_INET]209.95.50.11:1198 Wed Nov 20 17:34:52 2019 UDP link local: (not bound) Wed Nov 20 17:34:52 2019 UDP link remote: [AF_INET]209.95.50.11:1198 Wed Nov 20 17:34:52 2019 [8d26667dabcc2a9cc7b10009813a306a] Peer Connection Initiated with [AF_INET]209.95.50.11:1198 Wed Nov 20 17:34:53 2019 TUN/TAP device tun0 opened Wed Nov 20 17:34:53 2019 do_ifconfig, tt->did_ifconfig_ipv6_setup=0 Wed Nov 20 17:34:53 2019 /sbin/ip link set dev tun0 up mtu 1500 Wed Nov 20 17:34:53 2019 /sbin/ip addr add dev tun0 local 10.43.11.6 peer 10.43.11.5 Wed Nov 20 17:34:53 2019 Initialization Sequence Completed
但是,我在 tun0 上沒有網際網路訪問權限:
curl --interface tun0 -v ipinfo.io * Rebuilt URL to: ipinfo.io/ * Trying 216.239.38.21... * TCP_NODELAY set * Local Interface tun0 is ip 10.43.11.6 using address family 2 * Local port: 0
它只是掛起(
curl --interface ens5 -v ipinfo.io
工作正常)。關於網路(VPN啟動後):
route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.31.32.1 0.0.0.0 UG 100 0 0 ens5 10.43.11.1 10.43.11.5 255.255.255.255 UGH 0 0 0 tun0 10.43.11.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun0 172.31.32.0 0.0.0.0 255.255.240.0 U 0 0 0 ens5 172.31.32.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens5 ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000 link/ether 0e:a7:57:4c:36:ab brd ff:ff:ff:ff:ff:ff inet 172.31.47.214/20 brd 172.31.47.255 scope global dynamic ens5 valid_lft 3359sec preferred_lft 3359sec inet6 fe80::ca7:57ff:fe4c:36ab/64 scope link valid_lft forever preferred_lft forever 19: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 100 link/none inet 10.43.11.6 peer 10.43.11.5/32 scope global tun0 valid_lft forever preferred_lft forever inet6 fe80::2444:7d65:81eb:af01/64 scope link stable-privacy valid_lft forever preferred_lft forever
如何讓網際網路在 tun0 上工作,以便可以將它與 cURL 一起使用?
非常感謝
編輯
一位網路管理員告訴我,我必須執行以下操作:
- 再創建一張路由表
- 通過 10.43.11.5 將預設路由添加到該自定義表 0.0.0.0/0
- 為來自 tun0 的數據包添加規則以從該新路由表中查找路由
所以我做了:
(注意: tun0 IP 自原始發布以來已更改,現在是
inet 10.55.10.6 netmask 255.255.255.255 destination 10.55.10.5
)echo "1000 vpn" >> /etc/iproute2/rt_tables ip route add default via 10.55.10.5 dev tun0 table vpn ip rule add iif tun0 lookup vpn ip route add 255.255.255.255 dev tun0 proto kernel src 10.55.10.6 table vpn
不幸的是,cURL 仍然掛起:
curl -v --interface tun0 http://ipinfo.io * Rebuilt URL to: http://ipinfo.io/ * Trying 216.239.36.21... * TCP_NODELAY set * Local Interface tun0 is ip 10.55.10.6 using address family 2 * Local port: 0
以下是更多調試數據:
ubuntu@ip-172-31-47-214:~$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.31.32.1 0.0.0.0 UG 100 0 0 ens5 10.55.10.1 10.55.10.5 255.255.255.255 UGH 0 0 0 tun0 10.55.10.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun0 172.31.32.0 0.0.0.0 255.255.240.0 U 0 0 0 ens5 172.31.32.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens5 ubuntu@ip-172-31-47-214:~$ ifconfig ens5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001 inet 172.31.47.214 netmask 255.255.240.0 broadcast 172.31.47.255 inet6 fe80::ca7:57ff:fe4c:36ab prefixlen 64 scopeid 0x20<link> ether 0e:a7:57:4c:36:ab txqueuelen 1000 (Ethernet) RX packets 1188 bytes 117537 (117.5 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 841 bytes 109924 (109.9 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 168 bytes 13034 (13.0 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 168 bytes 13034 (13.0 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500 inet 10.55.10.6 netmask 255.255.255.255 destination 10.55.10.5 inet6 fe80::28a:e5f2:9cdf:b63 prefixlen 64 scopeid 0x20<link> unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC) RX packets 10 bytes 600 (600.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 13 bytes 684 (684.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ubuntu@ip-172-31-47-214:~$ ip rule show 0: from all lookup local 32765: from all iif tun0 lookup vpn 32766: from all lookup main 32767: from all lookup default
man ip-rule
:“……oif NAME — 選擇要匹配的傳出設備。傳出介面僅適用於源自綁定到設備的本地套接字的數據包。
……”
因此,而不是
ip rule add iif tun0 lookup vpn
你應該使用:ip rule add oif tun0 lookup vpn
但實際上它不會起作用 ,因為輸出介面之前會被主路由表選擇。所以,唯一可行的選擇是
ip rule
基於源IP使用。例如,如果您確定 VPN 的 IP 將保留在網路10/8
中,就像10.43.11.6
它一樣簡單ip rule add from 10.0.0.0/8 lookup vpn