buy VPN with paypal Buy VPN with Paypal & Credit Card. To purchase VPN with PayPal & Credit Card, please contact us: sales [at] rapidvpn.com

How to create L2TP/IPSec VPN connection on Ubuntu?

1Note: this is for advance Users or Admins with a strong understanding of terminal commands and txt editors. First you need to write down your server IP, and your L2TP Preshared Key. You get this by login here and going to configuration tab.
2Open Terminal and Install Packages run the command:
sudo apt-get install -y strongswan xl2tpd
3After we need to create and edit some files use the command:
sudo nano /etc/ipsec.conf
The file will look the same as below, if there is txt already in the file, delete it and copy the txt bellow.

# ipsec.conf - strongSwan IPsec configuration file

# basic configuration

config setup
force_keepalive=yes
keep_alive=60


conn %default
ikelifetime=60m
keylife=20m
rekeymargin=3m
keyingtries=1
keyexchange=ikev1
authby=secret
ike=aes128-sha1-modp1024,3des-sha1-modp1024!
esp=aes128-sha1-modp1024,3des-sha1-modp1024!

conn RapidVPN
keyexchange=ikev1
left=%defaultroute
auto=add
authby=secret
type=transport
right=XXX.XXX.XXX.XXX (Set this to your sever IP, where the Xs are)
dpddelay=10
dpdtimeout=20
dpdaction=clear
4Edit the secrets file and add your PSK (shared key or L2TP KEY) Use Command Bellow and make sure file looks the same with your info.
sudo nano /etc/ipsec.secrets
: PSK "Your pre-shared key here"
5Edit the xl2tpd.conf file,Use Command Bellow and make sure file looks the same with your info:

sudo nano /etc/xl2tpd/xl2tpd.conf
[lac RapidVPN]
lns = XXX.XXX.XXX.XXX(Set this to your sever IP, where the Xs are)
ppp debug = yes
pppoptfile = /etc/ppp/options.l2tpd.client
length bit = yes
6Now edit ppp configuration Use Command Bellow and make sure file looks the same:

sudo nano /etc/ppp/options.l2tpd.client

ipcp-accept-local
ipcp-accept-remote
refuse-eap
require-mschap-v2
noccp
noauth
idle 1800
mtu 1410
mru 1410
defaultroute
usepeerdns
debug
lock
connect-delay 5000
7Next use the commands bellow to create directory and file and change its permissions:

sudo mkdir -p /var/run/xl2tpd

sudo touch /var/run/xl2tpd/l2tp-control

sudo chmod o+rwx /var/run/xl2tpd/l2tp-control
8After restart the services with these commands:

sudo service strongswan restart

sudo service xl2tpd restart
9Bring up the l2tp tunnel interface and authenticate using the username and password with the commands below:

sudo ipsec up RapidVPN

sudo echo "c RapidVPN username password" > /var/run/xl2tpd/l2tp-control
10Add routing information into the routing table so that things are actually going through the VPN. To do this, first add a route to the Internet IP of the VPN server, through your local gateway. (To find local gateway use the command “route -n”)

sudo route add <Server IP> gw <local gateway>
11Finally make the default route, the one which goes through the VPN (the local IP of the VPN server, which can find with the command “ifconfig”(it will be the P-t-P ip address). Usually, this value is 10.1.0.1. Then use it in the command bellow:

sudo route del default
sudo route add -net default gw 10.1.0.1

Please do not forget, when disconnect, you will need to re-add your default gateway to make your internet connection to work.