I am running Ubuntu 14.04 on Amazon EC2. I'm trying to connect the EC2 instance to OpenVPN so the traffic routes through the VPN.

When I run the following: sudo openvpn --config <config>.ovpn, the SSH connection disconnects, and I'm unable to connect to it anymore.

Below is the OpenVPN config file:

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

Below is the output of the OpenVPN connection or what I last see of it..

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]

Wed Jul 15 10:23:15 2015 PUSH: Received control message: 'PUSH_REPLY,sndbuf 262144,rcvbuf 262144,redirect-gateway def1

redirect-gateway def1 means the tun dev that openvpn creates is set as the default gateway of your main routing table. So if 45.64.105.207 is not the address of the host that your ssh connection is coming from, you are probably losing your ssh connection because the return ssh traffic from the ec2 instance is going through 45.64.105.207 and your ssh client/router is dropping the traffic.

If that's the case, you can make an exception for ssh traffic back to your host prior to launching openvpn on the ec2 instance:

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

where x.x.x.x is the address from which you are trying to ssh into the ec2 instance and y.y.y.y is he default gateway prior to launching openvpn.

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

will show you which is the default gateway.

  • Totally agree - unfortunately the original poster whilst giving a great description of the issue including logs and config, did not state the aims of the exercise. A route will either be needed to management IP('s) or to sites that are to be secured over VPN, but sadly the current solution negates SSH management because traffic routing is asymmetric. If the OP wants to manage from a dynamic IP then this is going to be more difficult and may require a different solution. – James Freeman Jul 5 at 10:53

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.