There are various pages that advise on setting up an Open VPN Server on Amazon EC2, but all I need is to setup a client (so any internet access is routed through the VPN rather than coming directly from AWS IPs). I can transfer the .ovpn file to it and start it with

openvpn --config client.ovpn

But as soon as I do this I lose my ssh connection and therefore cant do anything with it. Googled extensively and found various suggestions that claim to bypass either certain ports or certain IP addresses. Either would be fine, i.e. I am happy to be restricted to certain IPs to connect via ssh when its running.

However, none of these seem to work in Amazons environment, e.g. see OpenVPN client on Amazon EC2. Its a new instance, so sits in VPC if this helps.

  • Note that my ovpn file doesnt contain a redirect-gateway directive.
    – Rob
    Commented Feb 6, 2016 at 18:06

2 Answers 2


In my case, executing the following successfully started the openvpn connection without losing ssh functionality:


sudo route add -host gw
openvpn --config newvpnconfigfile1.ovpn

where the ip following host is our office network's public IP (you can get this by just typing "what's my ip" into Google on your own pc) and the ip following gw is the ec2 instance's gateway IP (seen on the first line, second column of the output of netstat -anr when you execute it on your AWS server).

Checking the reported public ip before and after executing the above showed that it had changed from reporting as our normal IP address to reporting as the IP address of the VPN server.

Some more background information can be found here: Prevent SSH connection lost after logging into VPN on server machine


In my case I only needed to route a certain IP through the VPN connection, so I added those lines to the OpenVPN's configuration file:

route The.IP.To.Go

And then:

sudo openvpn --config vpnconfigfile.ovpn

Taken from https://serverfault.com/a/747828 and https://superuser.com/a/628488

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .