8

I have google arround for the answer of my thread. Most of the result suggesting to use Network Manager, which i believe is not the solution for me as i'm running Ubuntu Server without UI.

Is there anyone who experienced on connecting VPN Tunnel on L2TP with command line ? Any link or leads very much appreciated.

Thank you

2 Answers 2

6

I was looking for that and then I found a started solution here: https://gist.github.com/pastleo/aa3a9524664864c505d637b771d079c9 but still needs GUI, then I decide to test and I got the complete solution, here it is:

Note: I use Centos 7 but I think it works with Ubuntu

  1. Install NetworkManager-l2tp
    Centos 7:
yum -y install NetworkManager-l2tp

Ubuntu:
(Will need to add repository before install)

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

  1. Run this command as root (make your own changes before running, see below):
nmcli connection add connection.id [vpnName] con-name [vpnName] type VPN vpn-type l2tp ifname -- connection.autoconnect no ipv4.method auto vpn.data "gateway = [ipv4], ipsec-enabled = yes, ipsec-psk = 0s"$(base64

You have to change:

  • [vpnName] = The name of your connection
  • [ipv4] = ip of the l2tp/ipsec server
  • [PSK] = pre shared key from the l2tp/ipsec server
  • [user] = user name to connect to
  • [user-password] = password of the user to connect

I don't know if generated PSK will work for you, it works for me. If don't just connect with another PC with GUI, then copy PSK from file /etc/NetworkManager/system-connections/{vpn_name} and paste on

Thats it!

To show generated file: nmcli c show id [vpnName]
To start the VPN from cli: nmcli c up [vpnName]
To stop the VPN from cli: nmcli c down [vpnName]

Hope it can help because there is no other information how to do that on all Internet!

Enjoy your l2tp/ipsec VPN!

4
  • I'm trying to implement the VPN but I get an error when runing the command: Error: Argument 'type' was expected, but 'connection.id' provided. Any idea? Regards.
    – Fran Rod
    May 27, 2020 at 17:45
  • 1
    should we include brackets in password and vpn name?
    – zshanabek
    Oct 24, 2020 at 14:27
  • 2
    getting error "Error: Connection activation failed: Could not find source connection." Mar 9, 2022 at 14:06
  • 1
    Also getting the "Error: Connection activation failed: Could not find source connection." on Ubuntu 20.04LTS
    – Gregology
    Mar 12, 2022 at 16:33
5

I know it's an old post, but it helped me today, so here's my solution.

It didn't worked like this (ubuntu server 20.04), I tried as sugested on the other answer, made the connection on a VM with GUI, but instead of copying, I compared the files. The ipsec key was not in vpn.data, but in vpn.secrets, in plain text, so I changed the command, and it worked.

What I did was install the networkmanager

sudo add-apt-repository ppa:nm-l2tp/network-manager-l2tp
sudo apt install network-manager-l2tp

And ran this command

sudo nmcli connection add connection.id [vpnName] con-name [vpnName] type VPN vpn-type l2tp ifname -- connection.autoconnect no ipv4.method auto vpn.data "gateway = [ipv4], ipsec-enabled = yes, mru = 1400, mtu = 1400, password-flags = 0, refuse-chap = yes, refuse-mschap = yes, refuse-pap = yes, require-mppe = yes, user = [user]" vpn.secrets "password=[user-password], ipsec-psk = [PSK]"

Changing:

  • [vpnName] = The name of your connection
  • [ipv4] = ip of the l2tp/ipsec server
  • [PSK] = pre shared key from the l2tp/ipsec server
  • [user] = user name to connect to
  • [user-password] = password of the user to connect

(Remove the brackets)

To connect and disconnect:

nmcli c up [vpnName]
nmcli c down [vpnName]

PS It's my first time answering, so sorry for any mistake

1
  • 1
    thanks for sharing the update. NOT following your instructions had cost me a day full of headache: the PPA is essential! Given network-manager is already available with 20.04, I tried getting it to work following several pathes for resolving issues that occurred. With the repository added, it worked right away. Thanks a lot and keep sharing!
    – ThinkOli
    Mar 31, 2022 at 12:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .