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. If your not familiar with the nano txt editor, Google it to learn more about it.

# ipsec.conf - strongSwan IPsec configuration file

# basic configuration

config setup
# strictcrlpolicy=yes
# uniqueids = no

# Add connections here.

# Sample VPN connections

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 XXX-RAPID-VPN-XXX(Input connection name desired where RAPID-VPN is)
keyexchange=ikev1
left=%defaultroute
auto=add
authby=secret
type=transport
leftprotoport=17/1701
rightprotoport=17/170
right=XXX.XXX.XXX.XXX (Set this to your sever IP, where the Xs are)
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 XXX-RAPID-VPN-XXX](Use same connection name. Case Sensitive.)
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 XXX-RAPID-VPN-XXX

sudo echo "c XXX-RAPID-VPN-XXX 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)Then use it in the command bellow:

sudo route add -net default gw