Networking

帶有 Amazon Linux 的 AWS EC2 安裝了執行良好的 OpenVPN,但重新啟動後它就無法執行 - 為什麼?

  • May 14, 2017

我在Google上搜尋過,但我沒有找到我的問題的答案。

**問題:**我有一台執行 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                                      

我希望我能在你的幫助下找到解決辦法。

我沒有看到 OpenVPN 配置有任何問題,所以我認為 iptables 配置有問題。部署後可能無法保存,現在您的 nat 部分為空,這就是您無法訪問任何網站的原因。

更新問題與禁用轉發有關。需要添加到/etc/sysctl.confstring net.ipv4.ip_forward=1,到持久轉發設置。

引用自:https://serverfault.com/questions/850054