VPN on Ubuntu server

14,425

Solution 1

Your problem is likely to be related to routing. Connecting to a VPN almost always involves changing the system's route table in some way. Please remember that a routing table applies to all connections, and is global to the system.

You probably need to add a static route that allows your RDP traffic to continue to use the original gateway, before the VPN changed it.

Without knowing your current route tables, and network addressing for the various systems I can't make any specific suggestions about what you need to change.

Solution 2

Most likely what happens is that establishing the VPN alters your routing table, so that now a reply to your remote position goes thru the VPN server. But since your remote position has been trying to contact your home, not your VPN server, it will discard the replies going thru the VPN server.

You may solve this problem by establishing, simultaneously to the VPN, a route to your remote station which does not use the VPN server. For instance, suppose your remote station has IP address 1.1.1.1, your normal home gateway/router is 192.168.0.1, while your VPN re-routes everything thru a VPN server at 2.2.2.2. Then what you need is that the VPN sets the following new route:

       ip route add 1.1.1.1/32 via 192.168.0.1 dev eth0

The problem with this is that you should do this before setting up the VPN. Most VPNs that I know leave these extremely specific routes in place, so you may try the following order of operations:

  1. Give the command above;

  2. start your VPN;

  3. keep your fingers crossed.

If this does not work (because the VPN rewrites your routing table completely), you should try, as sudo:

   cmd_VPN; sleep 10;   ip route add 1.1.1.1/32 via 192.168.0.1 dev eth0

where cmd_VPN is whichever command you use to setup your VPN connection. The advantage of this is that the new route which you need is established after the VPN comes up. The sleep 10 is necessary to allow the VPN to change the routing table. For 10 seconds, you will be cutoff, but openssh is perfectly capable of resisting this.

You cannot test this from within your LAN: the normal route for the local lan is always left in place by all VPNs, so the above trick will work no matter what.

Share:
14,425

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I have an Linux server running Ubuntu 14.04. On it, I have xfce installed to act as a desktop. Additionally, I have xrdp installed so I can remote into the machine.

    Once a remote session is started, I'd like to connect to a VPN. Currently, I have PIA VPN installed but every time I connect, my remote session disconnects. I've tried tinkering with settings but the same result applies.

    Please reply with recommended settings or a different VPN service if this is possible.

    Thanks!

    • OneCricketeer
      OneCricketeer over 8 years
      When you use a VPN like PIA, it will disconnect your current network in order to clear the DNS cache. I don't think there is a solution for this...
    • Tmanok
      Tmanok about 6 years
      As everyone has stated, learn routing. What nobody else has stated, there are methods to send particular traffic to the VPN and other traffic through the original route. Also note that making your XRDP connection after your VPN connection is established would be more secure and just dandy.