我已经在谷歌上搜索过,但没有找到我的问题的答案。
问题:我有一台运行 Open VPN 的 AWS EC2 服务器。我有一个 Windows 10 客户端。我使用“sudo reboot”重新启动了整个 AWS EC2 服务器,重新启动后客户端(Windows 10)可以连接,但我无法打开任何网站,出现超时。
(重启 EC2 服务器后,OpenVPN 允许我连接(客户端),但我无法打开任何网站)。现在我在这里尝试一下。
我在客户端上收到以下日志:
Sun May 14 20:10:28 2017 disabling NCP mode (--ncp-disable) because not in P2MP client or server mode
Sun May 14 20:10:28 2017 OpenVPN 2.4.2 x86_64-w64-mingw32 [SSL (OpenSSL)] [LZO] [LZ4] [PKCS11] [AEAD] built on May 11 2017
Sun May 14 20:10:28 2017 Windows version 6.2 (Windows 8 or greater) 64bit
Sun May 14 20:10:28 2017 library versions: OpenSSL 1.0.2k 26 Jan 2017, LZO 2.10
Enter Management Password:
Sun May 14 20:10:28 2017 open_tun
Sun May 14 20:10:28 2017 TAP-WIN32 device [Ethernet 2] opened: \\.\Global\{5E768F9D-FF78-47F1-A881-B6F6132019B6}.tap
Sun May 14 20:10:28 2017 Notified TAP-Windows driver to set a DHCP IP/netmask of 10.4.0.2/255.255.255.252 on interface {5E768F9D-FF78-47F1-A881-B6F6132019B6} [DHCP-serv: 10.4.0.1, lease-time: 31536000]
Sun May 14 20:10:29 2017 Successful ARP Flush on interface [8] {5E768F9D-FF78-47F1-A881-B6F6132019B6}
Sun May 14 20:10:29 2017 do_ifconfig, tt->did_ifconfig_ipv6_setup=0
Sun May 14 20:10:29 2017 TCP/UDP: Preserving recently used remote address: [AF_INET]ec2-ip:1194
Sun May 14 20:10:29 2017 Attempting to establish TCP connection with [AF_INET]ec2-ip:1194 [nonblock]
Sun May 14 20:10:30 2017 TCP connection established with [AF_INET]ec2-ip:1194
Sun May 14 20:10:30 2017 TCP_CLIENT link local: (not bound)
Sun May 14 20:10:30 2017 TCP_CLIENT link remote: [AF_INET]ec2-ip:1194
Sun May 14 20:10:39 2017 Peer Connection Initiated with [AF_INET]ec2-ip:1194
Sun May 14 20:10:45 2017 Initialization Sequence Completed
我的配置与http://envyandroid.com/setup-free-private-vpn-on-amazon-ec2/
port 1194
proto tcp-server
dev tun1
ifconfig 10.4.0.1 10.4.0.2
status server-tcp.log
verb 3
secret ovpn.key
push dhcp-option DNS 8.8.8.8
push dhcp-option DNS 8.8.4.4
cipher AES-256-CBC
客户端配置是:
proto tcp-client
remote ec2-ip
port 1194
dev tun
secret ovpn.key
redirect-gateway def1
ifconfig 10.4.0.2 10.4.0.1
cipher AES-256-CBC
服务器日志:
Sun May 14 21:23:10 2017 disabling NCP mode (--ncp-disable) because not in P2MP client or server mode
Sun May 14 21:23:10 2017 OpenVPN 2.4.1 x86_64-redhat-linux-gnu [Fedora EPEL patched] [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Apr 3 2017
Sun May 14 21:23:10 2017 library versions: OpenSSL 1.0.1e-fips 11 Feb 2013, LZO 2.06
Sun May 14 21:23:10 2017 Outgoing Static Key Encryption: Cipher 'AES-256-CBC' initialized with 256 bit key
Sun May 14 21:23:10 2017 Outgoing Static Key Encryption: Using 160 bit message hash 'SHA1' for HMAC authentication
Sun May 14 21:23:10 2017 Incoming Static Key Encryption: Cipher 'AES-256-CBC' initialized with 256 bit key
Sun May 14 21:23:10 2017 Incoming Static Key Encryption: Using 160 bit message hash 'SHA1' for HMAC authentication
Sun May 14 21:23:10 2017 TUN/TAP device tun1 opened
Sun May 14 21:23:10 2017 TUN/TAP TX queue length set to 100
Sun May 14 21:23:10 2017 do_ifconfig, tt->did_ifconfig_ipv6_setup=0
Sun May 14 21:23:10 2017 /sbin/ip link set dev tun1 up mtu 1500
Sun May 14 21:23:10 2017 /sbin/ip addr add dev tun1 local 10.4.0.1 peer 10.4.0.2
Sun May 14 21:23:10 2017 Could not determine IPv4/IPv6 protocol. Using AF_INET
Sun May 14 21:23:10 2017 Socket Buffers: R=[87380->87380] S=[16384->16384]
Sun May 14 21:23:10 2017 Listening for incoming TCP connection on [AF_INET][undef]:1194
Sun May 14 21:24:32 2017 TCP connection established with [AF_INET]:50479
Sun May 14 21:24:32 2017 TCPv4_SERVER link local (bound): [AF_INET][undef]:1194
Sun May 14 21:24:32 2017 TCPv4_SERVER link remote: [AF_INET]my-windows10-local-ip:50479
Sun May 14 21:24:32 2017 Peer Connection Initiated with [AF_INET]my-windows10-local-ip:50479
Sun May 14 21:24:33 2017 Initialization Sequence Completed
命令“iptables-save”的输出:
# Generated by iptables-save v1.4.18 on Sun May 14 23:02:24 2017
*nat
:PREROUTING ACCEPT [122:6630]
:INPUT ACCEPT [7:360]
:OUTPUT ACCEPT [95:6264]
:POSTROUTING ACCEPT [95:6264]
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
-A POSTROUTING -s 0.0.0.0/2 -o eth0 -j MASQUERADE
COMMIT
# Completed on Sun May 14 23:02:24 2017
# Generated by iptables-save v1.4.18 on Sun May 14 23:02:24 2017
*filter
:INPUT ACCEPT [634:91381]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [639:54866]
COMMIT
# Completed on Sun May 14 23:02:24 2017
“sysctl -a | grep forward” 的输出:
net.ipv4.conf.all.forwarding = 0
net.ipv4.conf.all.mc_forwarding = 0
net.ipv4.conf.default.forwarding = 0
net.ipv4.conf.default.mc_forwarding = 0
net.ipv4.conf.eth0.forwarding = 0
net.ipv4.conf.eth0.mc_forwarding = 0
net.ipv4.conf.lo.forwarding = 0
net.ipv4.conf.lo.mc_forwarding = 0
net.ipv4.conf.tun1.forwarding = 0
net.ipv4.conf.tun1.mc_forwarding = 0
net.ipv4.ip_forward = 0
net.ipv4.ip_forward_use_pmtu = 0
error: "Input/output error" reading key "net.ipv6.conf.all.stable_secret"
net.ipv6.conf.all.forwarding = 0
net.ipv6.conf.all.mc_forwarding = 0
error: "Input/output error" reading key "net.ipv6.conf.default.stable_secret"
error: "Input/output error" reading key "net.ipv6.conf.eth0.stable_secret"
net.ipv6.conf.default.forwarding = 0
net.ipv6.conf.default.mc_forwarding = 0
net.ipv6.conf.eth0.forwarding = 0
net.ipv6.conf.eth0.mc_forwarding = 0
error: "Input/output error" reading key "net.ipv6.conf.lo.stable_secret"
net.ipv6.conf.lo.forwarding = 0
net.ipv6.conf.lo.mc_forwarding = 0
net.ipv6.conf.tun1.forwarding = 0
net.ipv6.conf.tun1.mc_forwarding = 0
我希望在您的帮助下能够找到解决方案。
答案1
我没有发现 OpenVPN 配置存在任何问题,所以我认为 iptables 配置存在问题。部署后可能无法保存,现在您的 nat 部分为空,这就是您无法访问任何网站的原因。
更新问题出在禁用转发上。需要将 添加到/etc/sysctl.conf
字符串net.ipv4.ip_forward=1
,以进行持久转发设置。