For those wishing to connect a VPN inside their Virtual Machine you will notice that once you connect your session gets disconnected. This is due to the VPN making changes to the routing table and more specifically the gateway.
There is a simple solution which can be used for any Virtual Machine.
Firstly we need to create a script and add it to our network /etc/network/if-up.d configuration so the routes that we add get added after a reboot as using iproute does not persist reboots so we use a script to overcome this or you can use the commands on a per use basis...the script is NOT a requirement for getting the VPN to work.
So follow these commands to create the script.
sudo nano /etc/network/if-up.d/vpn-up
Enter the information below into the configuration editor
#! /bin/sh ip rule add table 128 from YOUR INTERNAL IP ip route add table 128 to 192.168.1.0/24 dev eth0 ip route add table 128 default via 192.168.1.1 exit 0
Please note that you will need to replace the IP addresses with your own internal IP and NOT your public IP as OneHost Cloud is using NAT our customers need to use the internal IP. You can find your IP details and gateway by
Once you add the script you will need to make it executable
sudo chmod +x /etc/network/if-up.d/vpn-up
This will make it executable and because it is in the if-up-.d directory it will get executed after every reboot.
Now reboot and the script will execute and add the routes to the routing table. This will make all traffic exiting your VM to go via the VPN and enable you to still connect using your public IP address.
If you are using the OpenVPN that we provide you will need to browse to the directory where your onehost-openvpn.ovpn file is located and enter that directory. Once in that directory enter the following
Lastly if your Instance is not using Google's DNS you can change it by doing the following:-
sudo nano /etc/resolv.conf
Change the entry to 188.8.131.52 and 184.108.40.206
sudo openvpn --config customers.ovpn
This will connect your VPN and still providing access to your VPS via the public IP.
Please note that the VPN will ONLY work in our VPS Instances and NOT outside on your own PC's
As you are now using a VPN inside your VM you will receive a performance hit but this can be overcome by using SSH as most Kali Linux commands and tools can be executed via the command line. All you need to do is open 2 terminal sessions and leave one connected to the VPN and the other you connect to do your work. Alternately you can login using NoMachine and connect the VPN then exit and use SSH.....its up to your how you wish to do it.
If you wish to download out script you can find it in the restricted section of our forum which is available only for registered users. Registration is free