Amazon EC2 上的 OpenVPN 客户端导致 SSH 断开连接

Amazon EC2 上的 OpenVPN 客户端导致 SSH 断开连接

我在 Amazon EC2 上运行 Ubuntu 14.04。我尝试将 EC2 实例连接到 OpenVPN,以便流量通过 VPN 路由。

当我运行以下命令时:sudo openvpn --config <config>.ovpn,SSH 连接断开,并且我无法再连接它。

以下是 OpenVPN 配置文件:

setenv FORWARD_COMPATIBLE 1
setenv UV_SERVERID 581
client
dev tun
proto udp
remote 45.64.105.207 8292
nobind
persist-key
persist-tun
ns-cert-type server
key-direction 1
push-peer-info
comp-lzo
explicit-exit-notify
verb 3
mute 20
reneg-sec 86400
mute-replay-warnings
max-routes 1000

以下是 OpenVPN 连接的输出或我最后看到的内容。

Wed Jul 15 10:23:05 2015 OpenVPN 2.3.2 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [eurephia] [MH] [IPv6] built on Dec  1 2014
Wed Jul 15 10:23:05 2015 Control Channel Authentication: tls-auth using INLINE static key file
Wed Jul 15 10:23:05 2015 Outgoing Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
Wed Jul 15 10:23:05 2015 Incoming Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
Wed Jul 15 10:23:05 2015 Socket Buffers: R=[212992->131072] S=[212992->131072]
Wed Jul 15 10:23:05 2015 UDPv4 link local: [undef]
Wed Jul 15 10:23:05 2015 UDPv4 link remote: [AF_INET]182.18.155.184:8292
Wed Jul 15 10:23:05 2015 TLS: Initial packet from [AF_INET]182.18.155.184:8292, sid=c67100ed 4ce7c879
Wed Jul 15 10:23:07 2015 VERIFY OK: depth=1, C=.., ST=.., L=.., O=.., OU=.., CN=ASCA, emailAddress=..
Wed Jul 15 10:23:07 2015 VERIFY OK: nsCertType=SERVER
Wed Jul 15 10:23:07 2015 VERIFY OK: depth=0, C=.., ST=.., L=.., O=.., OU=.., CN=SERVER195, emailAddress=..
Wed Jul 15 10:23:12 2015 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Wed Jul 15 10:23:12 2015 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Wed Jul 15 10:23:12 2015 Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Wed Jul 15 10:23:12 2015 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Wed Jul 15 10:23:12 2015 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 2048 bit RSA
Wed Jul 15 10:23:12 2015 [SERVER195] Peer Connection Initiated with [AF_INET]182.18.155.184:8292
Wed Jul 15 10:23:14 2015 SENT CONTROL [SERVER195]: 'PUSH_REQUEST' (status=1)
Wed Jul 15 10:23:15 2015 PUSH: Received control message: 'PUSH_REPLY,sndbuf 262144,rcvbuf 262144,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 198.18.0.1,ping 10,ping-restart 90,comp-lzo no,route-gateway 198.18.0.1,topology subnet,ifconfig 198.18.1.134 255.255.240.0'
Wed Jul 15 10:23:15 2015 OPTIONS IMPORT: timers and/or timeouts modified
Wed Jul 15 10:23:15 2015 OPTIONS IMPORT: LZO parms modified
Wed Jul 15 10:23:15 2015 OPTIONS IMPORT: --sndbuf/--rcvbuf options modified
Wed Jul 15 10:23:15 2015 Socket Buffers: R=[131072->425984] S=[131072->425984]

答案1

2015 年 7 月 15 日星期三 10:23:15 PUSH:收到控制消息:'PUSH_REPLY,sndbuf 262144,rcvbuf 262144,redirect-gateway def1

重定向网关 def1意味着 openvpn 创建的 tun dev 被设置为主路由表的默认网关。因此,如果 45.64.105.207 不是您的 ssh 连接所来自的主机的地址,则您可能丢失了 ssh 连接,因为来自 ec2 实例的返回 ssh 流量要经过 45.64.105.207,而您的 ssh 客户端/路由器会丢弃流量。

如果是这种情况,您可以在 ec2 实例上启动 openvpn 之前将 ssh 流量例外返回到您的主机:

username@ec2-host:~$sudo ip route add x.x.x.x/32 via y.y.y.y dev eth0

其中 xxxx 是您尝试通过 ssh 连接到 ec2 实例的地址,yyyy 是启动 openvpn 之前的默认网关。

username@ec2-host:~$ip route show | grep default

将显示哪个是默认网关。

相关内容