I have an account with an OpenVPN service, and I'd like to get that running on my EC2 instance running Ubuntu 12.04.

I have my config file in /etc/openvpn, and it connects fine when I run sudo openvpn --config matt.ovpn. However, I then lose connectivity to the EC2 machine, and I can't SSH back to it until I reboot.

Previously I have done things like sudo ip rule add from IP_ADDRESS table 10 and then sudo ip route add default via GATEWAY_IP table 10, but that's not working on EC2.

Any ideas? My private IP address right now is 10.209.29.XXX and my gateway is

  • I'm forming a bridge from computers to the Internet, to provide access to items they wouldn't ordinarily have. – Matt Culbreth Jul 3 '12 at 19:12

Your OpenVPN configuration probably has the redirect-gateway directive, which will change the default route to point to the VPN once the VPN has started. Remove or comment out this line to prevent this from happening.

  • Ok, that's close! Now I just need to get default traffic to use this VPN connection. It looks like the OpenVPN provider is using the TUN device and giving me a new IP address. Do I just change my default gateway to something else now? – Matt Culbreth Jul 3 '12 at 19:25
  • Yeah, I just did this from a "regular" (non-AWS EC2) VPS and it worked fine. So...it's an EC2 thing with their IP addresses or routing. Hmm. – Matt Culbreth Jul 3 '12 at 20:00
  • @MattCulbreth did you solve that problem? I'm also trying to initiate a vpn connection from an EC2 – Moataz Elmasry Dec 10 '15 at 23:47

What you are trying to do ?

Most likely openvpn overwrites your routing table so you lose connectivity. There may be other script that run the time you start openvpn.

Post your openvpn configuration and log files. It is not possible to tell more without them.

EDIT Set up specific routes for the sites you want to access via openvpn.

ip ro add someip/32 via dev tun0

If this works for you you can put this in a start script or even better in you vpn configuration file.

  • The last bit of the openvpn log looks like this: – Matt Culbreth Jul 3 '12 at 19:13
  • us=691717 ROUTE default_gateway= us=692220 TUN/TAP device tun0 opened us=692244 TUN/TAP TX queue length set to 100 us=692263 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0 us=692302 /sbin/ifconfig tun0 pointopoint mtu 1500 us=928987 /sbin/route add -net WWW.XXX.YYY.1 netmask gw us=931566 /sbin/route add -net netmask gw – Matt Culbreth Jul 3 '12 at 19:18
  • Did not work. Hmm. Using curl --interface tun0 works just fine, but adding this routing rule did not. – Matt Culbreth Jul 3 '12 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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