连接到 AWS EC2 Ubuntu 上的 OpenVPN 服务器时无法访问互联网

连接到 AWS EC2 Ubuntu 上的 OpenVPN 服务器时无法访问互联网

将我的 Linux 机器连接到 AWS ec2 实例上的 Ubuntu 16.04 VPN 服务器后,我失去了互联网连接,但可以 ping VPN 服务器。

服务器配置:

port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh2048.pem
topology subnet
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
client-config-dir ccd
route 10.8.0.0 255.255.255.252
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
client-to-client
keepalive 10 120
tls-auth ta.key 0 # This file is secret
key-direction 0
cipher AES-128-CBC   # AES
auth SHA256
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3

客户端配置:

client
dev tun
proto udp
remote myserver 1194
resolv-retry infinite
nobind
user nobody
group nogroup
persist-key
persist-tun
remote-cert-tls server
cipher AES-128-CBC
auth SHA256
key-direction 1
comp-lzo
verb 3
Cerificates...

ccd/客户端:

ifconfig-push 10.8.0.26 255.255.255.0

route -n当连接到 VPN 时:

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.8.0.1        128.0.0.0       UG    0      0        0 tun0
0.0.0.0         172.29.25.1     0.0.0.0         UG    100    0        0 eth0
10.8.0.0        0.0.0.0         255.255.255.0   U     0      0        0 tun0
vpnserverIP   172.29.25.1     255.255.255.255 UGH   0      0        0 eth0
128.0.0.0       10.8.0.1        128.0.0.0       UG    0      0        0 tun0
172.29.25.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0

ifconfig tun0

tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
    inet 10.8.0.26  netmask 255.255.255.0  destination 10.8.0.26
    inet6 fe80::c922:ab77:1b0c:5095  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 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 1039  bytes 129116 (126.0 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

答案1

最后在将我的 pi 设置为 wifi 路由器时找到了解决方案,我知道存在防火墙问题,因此这几行解决了流量问题:

-A POSTROUTING -s 10.8.0.0/16 -o eth0 -j MASQUERADE -A FORWARD -i eth0 -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT -A FORWARD -i tun0 -o eth0 -j ACCEPT

如果使用 ufw 请相应转移此规则!

相关内容