Skip to content
Nosce Te Ipsum
  • Home
  • About me
  • My COETAIL Blogs
    • Course 1
    • Course 2
    • Course 3
    • Course 4
  • Testimonials
    • Professional
    • Personal
Site Search

Setting up L2TP/IPSEC server using PSK on Raspberry Pi…

  • November 7, 2018November 7, 2018
  • by Muhammad
Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin
Pin on Pinterest
Pinterest
Share on Reddit
Reddit
Email this to someone
email
Share on StumbleUpon
StumbleUpon
Digg this
Digg

While reading and searching for which IPSEC app to use for this server on Raspi (that is how I am going to call my Raspberry Pi now) I realised that Openswan may have some issues and as I had successfully installed Strongswan on my VPS, I stick to Strongswan.

We will do it in small steps. First Strongswan, then L2TP and then firewall rules.

Strongswan

sudo apt-get install strongswan iptables-persistent

go to /etc directory

cd /etc

copy both ‘ipsec.conf’ and ‘ipsec.secrets’ to keep default originals

sudo cp ipsec.conf ipsec.conf.original
sudo cp ipsec.secrets ipsec.secrets.original

cleanup the ‘ipsec.conf’ to put your own config

sudo echo ''| sudo tee ipsec.conf
and now edit with your favourite editor
sudo vim ipsec.conf

# ipsec.conf - strongSwan IPsec configuration file
# basic configuration

config setup

# strictcrlpolicy=yes
# uniqueids = no
# Add connections here.

conn vpnserver
type=transport
authby=secret
pfs=no
rekey=no
keyingtries=1
left=%any
leftprotoport=udp/l2tp
leftid=@wildfire
right=%any
rightprotoport=udp/%any
auto=add

include /var/lib/strongswan/ipsec.conf.inc

As we are using PSK instead of certificates, we will be editing the ipsec.secrets file next. You need to insert the line below in the file replacing x.x.x.x with IP of the interface on server which will listen for connections and ‘password’ with a pass phrase.

x.x.x.x &any : PSK "password"

L2TP (Xl2tpd)

Now it is the turn for L2TP installation.

sudo apt-get install xl2tpd

Make a copy of the config file to keep

sudo cp xl2tpd.conf xl2tpd.conf.original

Edit the config file and add these lines at the end of file


[global]
port = 1701
auth file = /etc/xl2tpd/l2tp-secrets
access control = no

[lns default]
exclusive = no
; enter the IP range you wish to give out to your clients here
ip range = x.x.x.x - x.x.x.x
; address of the L2TP end of the tunnel (i.e. this machine)
local ip = x.x.x.x
require authentication = yes
pppoptfile = /etc/ppp/options

PPP

We will use PPP for authentication hence install

sudo apt-get install ppp

Again, make copies of files we will be changing

sudo cp /etc/ppp/option option.original
sudo cp /etc/ppp/chap-secrets chap-secrets.original

Now at the end of ‘options’ file enter this code replacing the x.x.x.x with your desired DNS server’s IP address which you want to pass to the VPN clients


noccp
auth
mtu 1410
mru 1410
nodefaultroute
proxyarp
silent
debug
ms-dns x.x.x.x

You will also need to ‘remark’ the following lines in the ‘options’ file


#modem
#lock
#crtscts

At the end of ‘chap-secrets’ file, add this code replacing ‘username’ and ‘password’ with what you desire for each client and you can also restrict from a certain IP. We leave it with ‘*’ to allow the connection from anywhere.


user   *    password   *

Firewall rules

First of all make a copy of ‘/etc/sysctl.conf’ to save and then edit this file. Find the first three lines and ‘unremark’ them. Last line may or may not be in your config file. If it is, unremark it and if it isn’t add this.


net.ipv4.ip_forward=1
..
net.ipv4.conf.all.accept_redirects = 0
..
net.ipv4.conf.all.send_redirects = 0
..
net.ipv4.ip_no_pmtu_disc = 1

Now make a copy of ‘/etc/iptables/rules.v4’ and start editing this file. You need to enter the block of code below, replacing x.x.x.x/x with the subnet you have selected to use for allocating IP addresses to your VPN clients.


-A INPUT -p esp -j ACCEPT
-A INPUT -p ah -j ACCEPT
-A INPUT -p udp -m multiport --dports 500,4500 -j ACCEPT
-A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -m conntrack --ctstate NEW -s x.x.x.x/x -m policy --pol ipsec --dir in -j ACCEPT

and now you need to run a command to allow the server to serve as a NAT device for all VPN clients. Replace x.x.x.x/x with the subnet allocated for VPN clients to get IP address from.


sudo iptables -t nat -A POSTROUTING -s x.x.x.x/x -j MASQUERADE
Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin
Pin on Pinterest
Pinterest
Share on Reddit
Reddit
Email this to someone
email
Share on StumbleUpon
StumbleUpon
Digg this
Digg
Starting with Raspberry Pi
Attaching an external storage with over 2TB in size
Muhammad
firewall IPsec L2TP raspberry pi Strongswan VPN

Related articles

Raspberry PI as temperature and…
Dynamic DNS client setup for…
Install Nginx, MySQL and PHP…
Autostart a terminal app on…
Attaching an external storage with…
(c) Raspberry Pi
Starting with Raspberry Pi
Using GeoIP database to identify…
Designing Technology Infrastructure for Transformational…
The sad state of human…
Installing RD9700 chipset based USB…

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Me!

Follow Me On TwitterFollow Me On LinkedInFollow Me On PinterestFollow Me On About.meFollow Me On Wordpress
May 2025
M T W T F S S
« Oct    
 1234
567891011
12131415161718
19202122232425
262728293031  

2009 2010 2011 Amelie apache beijing birthday clearos crèpes debian december 2009 dubai email february firewall guide holidays ill install internet kuala lumpur linux list mac maheen mobile october 2009 outlook Pakistan raspberry raspberry pi router search Sharepoint smtp snow spring ubuntu unix VLAN VPN windows 7 winter xian Zimbra

WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

Categories

Licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Theme by Colorlib Powered by WordPress
  • Home
  • About me
  • My COETAIL Blogs
  • Testimonials