How to Setup an L2TP/IPsec VPN Client on Linux

L2TP (which stands for Layer 2 Tunneling Protocol) is a tunneling protocol designed to support virtual private networks (VPN connections) over the internet. It is implemented in most if not all modern operating systems including Linux and VPN-capable devices.

The L2TP does not provide any authentication or encryption mechanisms directly to traffic that passes through it, it is usually implemented with the IPsec authentication suite (L2TP/IPsec) to provide encryption within the L2TP tunnel.

In this article, we will show how to set up an L2TP/IPSec VPN connection in Ubuntu and its derivatives and Fedora Linux.

This guide assumes that the L2TP/IPsec VPN server has been set up and that you have received the following VPN connection details from your organization’s or company’s system administrator.

Gateway IP address or hostname
Username and Password
Pre-shared Key (Secret)

How to Setup L2TP VPN Connection in Linux

To add an L2TP/IPsec option to the NetworkManager, you need to install the NetworkManager-l2tp VPN plugin which supports NetworkManager 1.8 and later. It provides support for L2TP and L2TP/IPsec.

To install the L2TP module on Ubuntu and Ubuntu-based Linux distributions, use the following PPA.

$ sudo add-apt-repository ppa:nm-l2tp/network-manager-l2tp
$ sudo apt-get update
$ sudo apt-get install network-manager-l2tp  network-manager-l2tp-gnome

On RHEL/CentOS and Fedora Linux, use the following dnf command to install L2TP module.

# dnf install xl2tpd
# dnf install NetworkManager-l2tp
# dnf install NetworkManager-l2tp-gnome
OR
# yum install xl2tpd
# yum install NetworkManager-l2tp
# yum install NetworkManager-l2tp-gnome

Once the package installation is complete, click on your Network Manager icon, then go to Network Settings.

Access Network Settings
Access Network Settings

Next, add a new VPN connection by clicking on the (+) sign.

Add New VPN Connection
Add New VPN Connection

Then select Layer 2 Tunneling Protocol (L2TP) option from the pop-up window.

Select Layer 2 Tunneling Protocol
Select Layer 2 Tunneling Protocol

Next, enter the VPN connection details (gateway IP address or hostname, username and password) you received from the system administrator, in the following window.

Add VPN Details
Add VPN Details

Next, click IPsec Settings to enter the pre-shared key for the connection. Then enable IPsec tunnel to L2TP host, enter (or copy and paste the) the Pre-shared key and click Ok.

Add Pre-shared Key
Add Pre-shared Key

After that, click Add. Now your new VPN connection should be added.

VPN Connection Created
VPN Connection Created

Next, turn on the VPN connection to start using it. If the connection details are correct, the connection should be established successfully.

Enable VPN Connection
Enable VPN Connection
Enabled VPN Connection
Enabled VPN Connection

Last but not least, test if the VPN is working fine. You can check your computer’s public IP address to confirm this from a web browser: it should now point to the IP of the gateway.

Confirm Your VPN Connection
Confirm Your VPN Connection

That’s the end of this article. If you have any queries or thoughts to share, reach us via the feedback form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

21 Comments

Leave a Reply
  1. When configuring IPSEC, I have to set Phase1 algorithms to 3des-sha1-modp1024 and Phase1 algorithms to 3des-sha1 y Phase1 algorithms
    Linux Mint Mate 19.3.

    Reply
  2. It doesn’t work for me, I’m trying to do it from Debian since Windows the VPN works.

    Could You please help me? I’m new to Debian.

    Reply
  3. I followed your steps but I have this error.

    The L2TP connection attempt failed because the security layer encountered a processing error during initial negotiations with the remote computer.

    Reply
  4. Hello, I set up the client from Ubuntu 20.04, and when I want to connect to Cisco Meraki, it never connects it, I made many setups trying this one work but it doesn’t work, what information do you need to solve this problem?

    Reply
  5. Hello,

    I have a problem with l2tp in Ubuntu 20.04. I connect to the VPN successfully. but within it, there are two networks and I can only access one of them.

    From Windows 10 everything works correctly.

    would you know what the problem is?

    Reply
  6. No, not in LINUX but in Ubuntu and Fedora-related distros only. Ubuntu and Fedora are not the alpha and omega of Linux. There are hundreds of other Linux distros that these instructions CANNOT be used for.

    I am not asking for you to provide setup instructions for all other distros. All I am asking for is ‘truth in advertising’. If the article is specific to Ubuntu and Fedora, say so in the title. Otherwise, you are wasting the time of the millions of people who use distros other than those in Ubuntu/Fedora families.

    I know that Tecmint would not intentionally give its articles click-bait titles.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.