Never Ending Security

It starts all here

Setup and Configure a L2TPServer on Linux Ubuntu

Ubuntu: L2TPServer

This Guide will walk you through the process of installing a L2TP VPN Server on Ubuntu Server This configuration has been successfully tested with Android, Windows, and iOS devices.


sudo apt-get install xl2tpd openswan ppp

IPSec / Openswan

In the /etc/ipsec.conf file copy:

config setup
    #contains the networks that are allowed as subnet= for the remote client. In other words, the address ranges that may live behind a NAT router through which a client connects.


conn L2TP-PSK-noNAT
    # Apple iOS doesn't send delete notify so we need dead peer detection
    # to detect vanishing clients
    # Set ikelifetime and keylife to same defaults windows has
    # Replace IP address with your local IP (private, behind NAT IP is okay as well)
    # For updated Windows 2000/XP clients,
    # to support old clients as well, use leftprotoport=17/%any
    #force all to be nat'ed. because of iOS

Make sure you follow the setup in the ipsec.conf file, the part “config setup” and “conn l2tp-psk” should be to the very left while the other text 8 spaces to the right.

In the “/etc/ipsec.secrets” file copy:

x.x.x.x   %any:  PSK "somegoodpassword"

Replace x.x.x.x with your Server’s IP

Start the IPSEC service with

/etc/init.d/ipsec start

Please verify the IPSEC service with :

sudo ipsec verify

you must get no errors.

Checking your system to see if IPsec got installed and started correctly:
Version check and ipsec on-path                                 [OK]
Linux Openswan U2.6.28/K2.6.32-32-generic-pae (netkey)
Checking for IPsec support in kernel                            [OK]
NETKEY detected, testing for disabled ICMP send_redirects       [OK]
NETKEY detected, testing for disabled ICMP accept_redirects     [OK]
Checking that pluto is running                                  [OK]
Pluto listening for IKE on udp 500                              [OK]
Pluto listening for NAT-T on udp 4500                           [OK]
Checking for 'ip' command                                       [OK]
Checking for 'iptables' command                                 [OK]
Opportunistic Encryption Support                                [DISABLED]

Create a file called “ipsec.vpn” in “/etc/init.d/”

case "$1" in
echo "Starting my Ipsec VPN"
iptables  -t nat   -A POSTROUTING -o eth0 -s -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
for each in /proc/sys/net/ipv4/conf/*
    echo 0 > $each/accept_redirects
    echo 0 > $each/send_redirects
/etc/init.d/ipsec start
/etc/init.d/xl2tpd start
echo "Stopping my Ipsec VPN"
iptables --table nat --flush
echo 0 > /proc/sys/net/ipv4/ip_forward
/etc/init.d/ipsec stop
/etc/init.d/xl2tpd stop
echo "Restarting my Ipsec VPN"
iptables  -t nat   -A POSTROUTING -o eth0 -s -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
for each in /proc/sys/net/ipv4/conf/*
    echo 0 > $each/accept_redirects
    echo 0 > $each/send_redirects
/etc/init.d/ipsec restart
/etc/init.d/xl2tpd restart

 echo "Usage: /etc/init.d/ipsec.vpn  {start|stop|restart}"
 exit 1

This will configure the firewall forwarding. If you use a local IP pool other than 10.152.2, be sure to update it.

Then set the permission to execute:

sudo chmod 755 ipsec.vpn

Disable the ipsec default init script with

#update-rc.d -f ipsec remove

And enable the custom one.

#update-rc.d ipsec.vpn defaults


In the file /etc/xl2tpd/xl2tpd.conf

ipsec saref = no

[lns default]
ip range =
local ip =
require chap = yes
refuse pap = yes
require authentication = yes
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
  • ip range = range of IP’s to give to the connecting clients
  • local ip = IP of VPN server. Value must be outside of “ip range”.
  • refuse pap = refure pap authentication
  • ppp debug = yes when testing, no when in production

Choose a good challenge-response authentication string. The secret should, ideally, be 16 characters long, and should probably be longer to ensure sufficient security. There is no minimum length requirement. In the file /etc/xl2tpd/l2tp-secrets:

* * exampleforchallengestring

In the file /etc/ppp/options.xl2tpd copy:

asyncmap 0
idle 1800
mtu 1200
mru 1200
name l2tpd
lcp-echo-interval 30
lcp-echo-failure 4

ms-dns option

Here you set the dns server for your lan, this dns server are pushed to the road warrior when he connects. If you wan to add several servers just add several lines. If you need to push wins settings to the clients there is an separate option for that.

mtu / mru

openswan suggest that it’s important to reduce the mru/mtu size because l2tp/ipsec are encapsulated several times it causes overhead. Reducing this makes it possible to transmit all packages over lines with reduced mtu size.


Adds an entry to this system’s ARP [Address Resolution Protocol] table with the IP address of the peer and the Ethernet address of this system. This will have the effect of making the peer appear to other systems to be on the local ethernet.

name l2tpd

Is used in the ppp authentication file.

Adding Users

In the file /etc/ppp/chap-secrets copy:

user1 l2tpd chooseagoodpassword *
user2 * chooseagoodpassword *
  • client = username for the user
  • server = the name we define in the ppp.options file for xl2tpd
  • secret = password for the user
  • IP Address = leave to * for any address or define addresses from were a user can login.

Note: you can add as many user you like.


in /etc/sysctl.conf


Load the new settings made in /etc/sysctl.conf

sysctl -p

Starting the VPN

sudo /etc/init.d/ipsec.vpn restart
sudo /etc/init.d/xl2tpd restart

Connecting the VPN to iOS device

  1. Go to Settings > General > Network > VPN > Add VPN Configuration > L2 TP
  2. VPN Description > the name you like
  3. Set VPN server > external ip address of the VPN server (x.x.x.x)
  4. Account > PPP username
  5. Set password > somegoodpassword
  6. Set L2T P Secret > was exampleforchallengestring
  7. Connect using the PPP username/password (user1 chooseagoodpassword)

Connecting the VPN to an Android device

  1. Go to Settings > Wireless & networks > VPN settings > Add VPN > Add L2TP/IPSec PSK VPN >
  2. VPN Name / Description > the name you like
  3. Set VPN server > external ip address of the VPN server (x.x.x.x)
  4. Set IPSec pre-shared key / password > somegoodpassword
  5. Enable L2TP secret > enable
  6. Set L2TP Secret > was exampleforchallengestring
  7. Press back, then connect using the PPP username/password (user1 chooseagoodpassword)


In case of problems this are a few commands that can help out the debugging.

sudo tcpdump -i ppp0
sudo tail -f /var/log/auth.log
sudo tail -f /var/log/syslog

You can also monitor the results on the Server with

sudo tcpdump -i eth0 host aaa.bbb.ccc.ddd and not port ssh

aaa.bbb.ccc.ddd are the public IP address of your Clients


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s