Jump to content

L2TPv3 over IPsec configuration example: Difference between revisions

From Teltonika Networks Wiki
No edit summary
No edit summary
Line 1: Line 1:
<span style="color: red;">The information on this page is updated in accordance with firmware version <span style="color: #0054A6;"><b>00.07.11.3</b></span>.</span>
==Introduction==
==Introduction==


<span style="color: red;">The information on this page is updated in accordance with firmware version <span style="color: #0054A6;"><b>00.07.10</b></span>.</span>
Due to the inherent lack of confidentiality in the '''Layer 2 Tunneling Protocol''' ('''L2TP'''), it is commonly secured by pairing it with '''Internet Protocol Security''' ('''IPsec'''). IPsec provides essential features such as confidentiality, authentication, and integrity for L2TP packets. This combination is widely referred to as '''L2TP over IPsec''' (or simply '''L2TP/IPsec''') and is a standard approach for secure VPN implementations.


Because of the lack of confidentiality inherent in the '''Layer 2 Networking Protocol''' ('''L2TP''') protocol, '''Internet Protocol Security''' ('''IPsec''') is often used to secure L2TP packets by providing confidentiality, authentication, and integrity. The combination of these two protocols is generally known as '''L2TP over IPsec''' (or simply '''L2TP/IPsec''').  
This article provides instructions on configuring L2TPv3 over IPsec on Teltonika routers and gateway devices. Please note that the guide is designed for advanced users and skips some of the more straightforward steps to maintain overall clarity. For instance, adding new instances is only briefly mentioned rather than described in detail. If this level of information feels insufficient for your setup, consider referring to our dedicated configuration guides '''[[IPsec RUTOS configuration example|IPsec]]''' and '''[[L2TP configuration examples RutOS|L2TP]]''' for reference.


This article provides a guide on how to configure L2TPv3/IPsec on RUTxxx routers. It should also be noted that this guide is aimed at more advanced users and, therefore, skips some of the more self-explanatory steps in order to preserve the overall coherence of the article. For example, instead of showing how to add new instances step by step, it is only mentioned in a short sentence. If you feel this lack of information impedes your ability to configure the setup, we suggest you check out our separate configuration guides on '''[[IPsec RUTOS configuration example|IPsec]]''' and '''[[L2TP configuration examples RutOS|L2TP]]''' for reference.
==Prerequisites==


==Configuration overview and prerequisites==
* '''Two routers''' with configured VLANs, will refer to these as '''RUT1''' and '''RUT2'''
* At least one router with a '''Public IP''' addresses (for L2TPv3/IPsec over mobile)
* '''Two PC''' devices for testing


Before we begin, let's overview the configuration that we are attempting to achieve and the prerequisites that make it possible.
==L2TPv3/IPsec Over Wired WAN network==


'''Prerequisites''':
* Two RUTxxx routers
* At least one router with a Public Static or Public Dynamic IP addresses
* At least one end device (PC, Laptop, Tablet, Smartphone) to configure the routers
* Two VLANs configurated on both devices


==Preparation==
As mentioned in Prerequisites, two VLANs must be configured on both RUT devices. Detailed instructions for this process can be found on this page: '''[[VLAN Set Up]]'''. The remaining configuration steps are provided in this configuration example.


As mentioned in Prerequisites, you will need to configure two VLANs on both RUT devices, detailed instructions on how to configure them can be found on this page: '''[[VLAN Set Up]]'''
===Topology===
Everything else we will configure along the way.


===Topology===
[[File:L2tpv3 ipsec over wired wan - topology.png|border|class=tlt-border|center]]


[[File:Networking rutxxx configuration examples l2tpv3 over ipsec topology v1.png|border|class=tlt-border|1100px]]
===IPsec configuration===


==IPSec configuration==
IPsec will be set up to ensure encrypted communication between two routers. The steps provided will guide through configuring the necessary parameters, such as authentication methods, encryption algorithms, and connection endpoints, starting with RUT1.
If you have familiarized yourself with the configuration schemes and have all of the devices in order, we can start configuring the routers using instructions provided in this section.
We will start our configuration with RUT1.


===IPsec RUT1 Config===
====IPsec RUT1 Config====
----
----
* Login to the router's WebUI and go to '''Services VPN -> IPsec'''
# Access the router's WebUI, go to '''Services > VPN > IPsec''', and input the desired name for the new instance.
* Add a new instance with your desired name, in my case, I will be using '''RUT1'''
# Click the [[File:Add_Button.png|40px]] button
[[File:L2tpv3 over ipsec - wired wan - r1 - add new instance.png|border|class=tlt-border]]


[[File:RutOS_IPsec_tunnel_with_certificates_7.8_add_ipsec.png|border|center|class=tlt-border|1102px]]


'''Note:''' ''Not specified fields can be left as is or changed according to your needs.''  
'''Instance configuration'''
====Instance configuration====
----
----
Make the following changes:
<table class="nd-othertables_2">
# '''''Enable''''' instance;
    <tr>
# Remote endpoint - '''''RUT2 public WAN IP;'''''
        <th width=750; style="border-bottom: 1px solid white;></th>
# Authentication method - '''''Pre-shared key;'''''
        <th width=950; style="border-bottom: 1px solid white;" rowspan=2>
        [[File:L2tpv3 over ipsec - wired wan - r1 - instance settings.png|border|class=tlt-border|center]]</th>
    </tr>
    <tr>
        <td style="border-bottom: 4px solid white>
# '''Enable''' instance;
# Remote endpoint - '''RUT2 wired WAN IP'''
# Authentication method - '''Pre-shared key'''
# Pre shared key - '''''Your chosen password (must match for both RUT1 & RUT2)'''''
# Pre shared key - '''''Your chosen password (must match for both RUT1 & RUT2)'''''
# Local identifier – '''''RUT1 LAN IP, which is 192.168.3.1 in this case;'''''
# Local identifier – '''RUT1 LAN IP, which is 192.168.1.1 in this case'''
# Remote identifier – '''''RUT2 LAN IP, which is 192.168.14.1 in this case;'''''
# Remote identifier – '''RUT2 LAN IP, which is 192.168.2.1 in this case'''
[[File:RutOS_IPsec_config_ex_7.8_rut1.png|border|class=tlt-border|center]]
        </td>
====Connection general section configuration====
    </tr>
</table>
 
'''Connection general section configuration'''
----
----
Make the following changes:
<table class="nd-othertables_2">
# Mode - '''''Start;'''''
    <tr>
# Type - '''''Tunnel;'''''
        <th width=700; style="border-bottom: 1px solid white;></th>
# Local subnet – '''''192.168.3.0/24;'''''
        <th width=1000; style="border-bottom: 1px solid white;" rowspan=2>
# Remote subnet – '''''192.168.14.0/24;'''''
        [[File:L2tpv3 over ipsec - wired wan - r1 - instance settings - general settings.png|border|class=tlt-border|center]]</th>
# Key exchange - '''''IKEv2;'''''
    </tr>
    <tr>
        <td style="border-bottom: 4px solid white>


[[File:RutOS_IPsec_tunnel_with_certificates_7.8_add_ipsec_config_connection.png|border|class=tlt-border|center]]
# Mode - '''Start;'''
# Type - '''Tunnel;'''
# Default route - '''off'''
# Route based IPsec - '''off'''
# Local subnet – '''192.168.1.0/24'''
# Remote subnet – '''192.168.2.0/24'''
# Key exchange - '''IKEv2;'''
        </td>
    </tr>
</table>


====Proposal configuration====
'''Proposal configuration'''
----
'''Important:''' Both the RUT1 and RUT2 Encryptions must match in order for this configuration to work.
'''Important:''' Both the RUT1 and RUT2 Encryptions must match in order for this configuration to work.
----
'''Note:''' ''This is only an example of a secure configuration. Other algorithms or even combinations of them could be used. However, we strongly recommend refraining from using older encryption and hashing algorithms unless support for certain legacy systems is required.''


Make the following changes:
 
'''Phase 1:'''
<table class="nd-othertables_2">
<table class="nd-othertables_2">
     <tr>
     <tr>
         <th width=330; style="border-bottom: 1px solid white;></th>
         <th width=500; style="border-bottom: 1px solid white;></th>
         <th width=800; style="border-bottom: 1px solid white;" rowspan=2>[[File:Networking_webui_manual_IPsec_configuration_proposal_phase1_settings_v1.png|border|class=tlt-border|671x336px|center]]</th>
         <th width=1100; style="border-bottom: 1px solid white;" rowspan=2>
[[File:L2tpv3 over ipsec - wired wan - r1 - instance settings - proposal settings - phase1.png|border|class=tlt-border|center]]</th>
     </tr>
     </tr>
     <tr>
     <tr>
         <td style="border-bottom: 4px solid white>
         <td style="border-bottom: 4px solid white>
# Encryption - '''''AES256;'''''
       
# Authentication - '''''SHA512;'''''
# Encryption - '''AES256'''
# DH group - '''''MODP4096;'''''
# Authentication - '''SHA512'''
# IKE lifetime - '''86400s'''.
# DH group - '''MODP4096'''
# IKE lifetime - '''86400s'''
         </td>
         </td>
     </tr>
     </tr>
Line 81: Line 100:


----
----
'''Phase 2:'''
<table class="nd-othertables_2">
<table class="nd-othertables_2">
     <tr>
     <tr>
         <th width=330; style="border-bottom: 1px solid white;></th>
         <th width=500; style="border-bottom: 1px solid white;></th>
         <th width=800; style="border-bottom: 1px solid white;" rowspan=2>[[File:Networking_webui_manual_IPsec_configuration_proposal_phase2_settings_v1.png|border|class=tlt-border|644x331px|center]]</th>
         <th width=1100; style="border-bottom: 1px solid white;" rowspan=2>
[[File:L2tpv3 over ipsec - wired wan - r1 - instance settings - proposal settings - phase2 rev1.png|border|class=tlt-border|center]]</th>
     </tr>
     </tr>
     <tr>
     <tr>
         <td style="border-bottom: 4px solid white>
         <td style="border-bottom: 4px solid white>
# Encryption - '''''AES256;'''''
# Encryption - '''AES256'''
# Authentication - '''''SHA512;'''''
# Authentication - '''SHA512;'''
# PFS group - '''''MODP4096;'''''
# PFS group - '''MODP4096;'''
# Lifetime – '''''86400s;'''''
# Lifetime – '''86400s'''
         </td>
         </td>
     </tr>
     </tr>
</table>
</table>


'''Note:''' ''This is only an example of a secure configuration. Other algorithms or even combinations of them could be used. However, we strongly recommend refraining from using older encryption and hashing algorithms unless support for certain legacy systems is required.''


====IPsec RUT2 Config====
----
# Access the router's WebUI, go to '''Services > VPN > IPsec''', and input the desired name for the new instance.
# Click the [[File:Add_Button.png|40px]] button
[[File:L2tpv3 over ipsec - wired wan - r2 - add new instance rev1.png|border|class=tlt-border]]


'''Instance configuration'''
----
<table class="nd-othertables_2">
    <tr>
        <th width=750; style="border-bottom: 1px solid white;></th>
        <th width=950; style="border-bottom: 1px solid white;" rowspan=2>
        [[File:L2tpv3 over ipsec - wired wan - r2 - instance settings rev2.png|border|class=tlt-border|center]]</th>
    </tr>
    <tr>
        <td style="border-bottom: 4px solid white>
# '''Enable''' instance;
# Remote endpoint - '''RUT1 wired WAN IP;'''
# Authentication method - '''Pre-shared key;'''
# Pre shared key - '''''Your chosen password (must match for both RUT1 & RUT2)'''''
# Local identifier – '''RUT1 LAN IP, which is 192.168.2.1 in this case;'''
# Remote identifier – '''RUT2 LAN IP, which is 192.168.1.1 in this case;'''
        </td>
    </tr>
</table>


===IPsec RUT2 Config===
'''Connection general section configuration'''
----
----
* Login to the router's WebUI and go to '''Services → VPN -> IPsec'''
<table class="nd-othertables_2">
* Add a new instance with your desired name, in my case I will be using '''RUT2'''
    <tr>
        <th width=700; style="border-bottom: 1px solid white;></th>
        <th width=1000; style="border-bottom: 1px solid white;" rowspan=2>
        [[File:L2tpv3 over ipsec - wired wan - r2 - instance settings - general settings.png|border|class=tlt-border|center]]</th>
    </tr>
    <tr>
        <td style="border-bottom: 4px solid white>


[[File:RutOS_IPsec_tunnel_with_certificates_7.8_add_ipsec.png|border|center|class=tlt-border|1102px]]
# Mode - '''Start;'''
# Type - '''Tunnel;'''
# Default route - '''off'''
# Route based IPsec - '''off'''
# Local subnet – '''192.168.2.0/24'''
# Remote subnet – '''192.168.1.0/24'''
# Key exchange - '''IKEv2;'''
        </td>
    </tr>
</table>


'''Note:''' ''Not specified fields can be left as is or changed according to your needs.''
'''Proposal configuration'''
====Instance configuration====
----
----
Make the following changes:
'''Important:''' Both the RUT1 and RUT2 Encryptions must match in order for this configuration to work.
# '''''Enable''''' instance;
 
# Authentication method - '''''Pre-shared key;'''''
# Pre shared key - '''''Your chosen password (must match for both RUT1 & RUT2)'''''
# Local identifier – '''''RUT2 LAN IP, which is 192.168.14.1 in this case;'''''
# Remote identifier – '''''RUT1 LAN IP, which is 192.168.3.1 in this case;'''''
[[File:RutOS_IPsec_config_ex_7.8_rut2222.png|border|class=tlt-border|center]]
====Connection general section configuration====
----
Make the following changes:
# Mode - '''''Start;'''''
# Type - '''''Tunnel;'''''
# Local subnet – '''''192.168.14.0/24;'''''
# Remote subnet – '''''192.168.3.0/24;'''''
# Key exchange - '''''IKEv2;'''''


[[File:RutOS_IPsec_tunnel_with_certificates_7.8_add_ipsec_config_connection_rut2_general.png|border|class=tlt-border|center]]
====Proposal configuration====
'''Important:''' Both the RUT1 and RUT2 Encryptions must match in order for this configuration to work.
----
'''Note:''' ''This is only an example of a secure configuration. Other algorithms or even combinations of them could be used. However, we strongly recommend refraining from using older encryption and hashing algorithms unless support for certain legacy systems is required.''


Make the following changes:
'''Phase 1:'''
<table class="nd-othertables_2">
<table class="nd-othertables_2">
     <tr>
     <tr>
         <th width=330; style="border-bottom: 1px solid white;></th>
         <th width=500; style="border-bottom: 1px solid white;></th>
         <th width=800; style="border-bottom: 1px solid white;" rowspan=2>[[File:Networking_webui_manual_IPsec_configuration_proposal_phase1_settings_v1.png|border|class=tlt-border|671x336px|center]]</th>
         <th width=1100; style="border-bottom: 1px solid white;" rowspan=2>
[[File:L2tpv3 over ipsec - wired wan - r1 - instance settings - proposal settings - phase1.png|border|class=tlt-border|center]]</th>
     </tr>
     </tr>
     <tr>
     <tr>
         <td style="border-bottom: 4px solid white>
         <td style="border-bottom: 4px solid white>
# Encryption - '''''AES256;'''''
       
# Authentication - '''''SHA512;'''''
# Encryption - '''AES256;'''
# DH group - '''''MODP4096;'''''
# Authentication - '''SHA512;'''
# IKE lifetime - '''86400s'''.
# DH group - '''MODP4096;'''
# IKE lifetime - '''24h'''
         </td>
         </td>
     </tr>
     </tr>
Line 148: Line 193:


----
----
'''Phase 2:'''
<table class="nd-othertables_2">
<table class="nd-othertables_2">
     <tr>
     <tr>
         <th width=330; style="border-bottom: 1px solid white;></th>
         <th width=500; style="border-bottom: 1px solid white;></th>
         <th width=800; style="border-bottom: 1px solid white;" rowspan=2>[[File:Networking_webui_manual_IPsec_configuration_proposal_phase2_settings_v1.png|border|class=tlt-border|644x331px|center]]</th>
         <th width=1100; style="border-bottom: 1px solid white;" rowspan=2>
[[File:L2tpv3 over ipsec - wired wan - r1 - instance settings - proposal settings - phase2 rev1.png|border|class=tlt-border|center]]</th>
     </tr>
     </tr>
     <tr>
     <tr>
         <td style="border-bottom: 4px solid white>
         <td style="border-bottom: 4px solid white>
# Encryption - '''''AES256;'''''
# Encryption - '''AES256;'''
# Authentication - '''''SHA512;'''''
# Authentication - '''SHA512;'''
# PFS group - '''''MODP4096;'''''
# PFS group - '''''MODP4096;'''
# Lifetime – '''''86400s;'''''
# Lifetime – '''24h;'''
         </td>
         </td>
     </tr>
     </tr>
</table>
</table>


===Testing IPsec connection===
'''Note:''' ''This is only an example of a secure configuration. Other algorithms or even combinations of them could be used. However, we strongly recommend refraining from using older encryption and hashing algorithms unless support for certain legacy systems is required.''
When you're done with the configuration, you should test whether it works before you move on. The simplest way to test an IPsec connection is using the '''ipsec status''' command. You can execute this command via a command line interface (CLI). A CLI is present in all RUTxxx routers' WebUIs. To access it, login to one of the routers' WebUI (doesn't matter which one) and navigate to '''Services → CLI'''. Log in to CLI with the user name '''root''' and the router's admin password. Then simply the ''ipsec status'' and press the "Enter" key:
----
 
====Testing IPsec connection====
 
After completing the configuration, it is essential to test its functionality before proceeding further. The simplest method to test an IPsec connection is by using the '''swanctl -l''' command. This command can be executed via the command line interface (CLI)and to access the CLI, log in to the WebUI of any router (either one can be used), navigate to '''Services → CLI''', log in to the CLI using the username '''root''' and the router's '''admin password'''. More details on accessing the CLI can be found [https://wiki.teltonika-networks.com/view/Command_Line_Interfaces here.]
 


[[File:Networking rutxxx configuration examples ipsec status v2.jpg|border|class=tlt-border|1100px]]
Enter the command '''swanctl -l''' and press the "'''Enter'''" key:


As you can see, executing ''ipsec status'' displays the number of active/inactive IPsec connections. If the connection you just configured is the only IPsec connection that you're using, you should a '''1 up''' indication next to Security Associations.
[[File:L2tpv3 over ipsec - wired wan - ipsec connectivity check.png|border|class=tlt-border]]


==L2TPv3==
If "'''established'''" appears in the output along with other connection details, it indicates that the IPsec connection was successful.


Next, you must configure a working L2TPv3 connection. This subsection contains instructions on how to do just that. The relevant parameters will be encapsulated <span style="color:red">'''in red rectangles'''</span>. Explanations about these parameters will be provided under each example. For more detailed informaton refer to '''[[VPN|VPN, L2TPv3]]'''.
----


New L2TPv3 instances can be created from the '''Services → VPN → L2TP → L2TPv3''' section of the router's WebUI. Enter a custom name and click the "Add" button to create a new instance. Then click the "Edit" button located next to the newly created instance to enter its configuration page.
===L2TPv3 configuration===


===RUT1===
L2TPv3 is an enhanced version of L2TP, providing support for Layer 3 (IP) and Layer 2 (Ethernet) tunneling. It is typically used in scenarios where the need for secure data transmission across an untrusted network exists, such as remote access or site-to-site VPNs.


[[File:Networking rutxxx configuration examples l2tpv3 rut1 v1.jpg|border|class=tlt-border|1100px]]
New L2TPv3 instances can be created from the '''Services > VPN > L2TPv3''' section of the router's WebUI. Enter a custom name and click the "Add" button to create a new instance. Then click the "Edit" button located next to the newly created instance to enter its configuration page.


* '''Enable''' - if checked, enables the L2TPv3 instance
====L2TPv3 RUT1 Config====
* '''Local address''' - IP address of the '''local''' instance. Provide '''RUT1''' device's '''LAN IP''' here.
* '''Tunnel ID''' - Uniquely identifies the tunnel. The value used must match the peer tunnel '''ID''' value being used at the peer. For this example '''3000'''.
* '''Session ID''' - The value used must match the tunnel ID value being used at the peer. For this example '''1000'''.
* '''Peer address''' - IP address of the '''remote''' instance. Provide '''RUT2''' device's '''LAN IP''' here.
* '''Peer Tunnel ID''' - '''RUT2''' Tunnel ID: '''4000'''
* '''Peer Session ID''' - '''RUT2''' Session ID: '''2000'''
* '''Bridge to''' -  you can select an instance that you want to bridge to. In this case select '''None'''.
*'''IPv4 address''' - Provide your '''RUT1''' first '''VLAN IP''' adress here. In this example '''10.10.10.1'''
*'''Netmask''' - netmask for provided IPv4 address above. In this example '''255.255.255.0'''
*'''MTU''' - '''1488'''
*'''Encapsulation''' - '''UDP'''
*'''UDP source port''' - '''RUT1''' UDP port. In this example '''5000'''
*'''UDP destination port''' - '''RUT2''' UDP port. In this example '''6000'''


----
----


# Access the router's WebUI, go to '''Services > VPN > L2TPv3''', and input the desired name for the new instance.
# Click the [[File:Add_Button.png|40px]] button
[[File:L2tpv3 over ipsec - wired wan - r1 - add instance.png|border|class=tlt-border]]


===RUT2===
'''Instance Settings'''
----
<table class="nd-othertables_2">
    <tr>
        <th width=600; style="border-bottom: 1px solid white;></th>
        <th width=800; style="border-bottom: 1px solid white;" rowspan=2>
[[File:L2tpv3 over ipsec - wired wan - r1 - l2tpv3 instance settings.png|border|class=tlt-border|center]]</th>
    </tr>
    <tr>
        <td style="border-bottom: 4px solid white>
# '''Enable''' - if checked, enables the L2TPv3 instance
# '''Local address''' - IP address of the local instance. Provide RUT1 device's LAN IP here.
# '''Tunnel ID''' - Uniquely identifies the tunnel. The value used must match the peer tunnel ID value being used at the peer. For this example 3000.
# '''Session ID''' - The value used must match the tunnel ID value being used at the peer. For this example 1000
# '''Cookie''' - The value used must match the RUT2 peer cookie value in L2TPv3 instance peer settings.
# '''Peer address''' - IP address of the remote instance. Provide RUT2 device's LAN IP here.
# '''Peer Tunnel ID''' - RUT2 Tunnel ID: 4000
# '''Peer Session ID''' - RUT2 Session ID: 2000
# '''Peer Cookie''' - The value used must match the RUT2 cookie value in L2TPv3 instance settings.
# '''Bridge to''' -  you can select an instance that you want to bridge to. In this case select lan1, which is bridged lan interface for VLAN3.
# '''MTU''' - 1488
# '''Encapsulation''' - UDP
# '''UDP source port''' - RUT1 UDP port. In this example 5000
# '''UDP destination port''' - RUT2 UDP port. In this example 6000
# '''Layer 2 specific header type''' - Linux default
        </td>
    </tr>
</table>


[[File:Networking rutxxx configuration examples l2tpv3 rut2 v1.jpg|border|class=tlt-border|1100px]]
----


* '''Enable''' - if checked, enables the L2TPv3 instance
====L2TPv3 RUT2 Config====
* '''Local address''' - IP address of the '''local''' instance. Provide '''RUT2''' device's '''LAN IP''' here.
* '''Tunnel ID''' - Uniquely identifies the tunnel. The value used must match the peer tunnel '''ID''' value being used at the peer. For this example '''4000'''.
* '''Session ID''' - The value used must match the tunnel ID value being used at the peer. For this example '''2000'''.
* '''Peer address''' - IP address of the '''remote''' instance. Provide '''RUT1''' device's '''LAN IP''' here.
* '''Peer Tunnel ID''' - '''RUT1''' Tunnel ID: '''3000'''
* '''Peer Session ID''' - '''RUT1''' Session ID: '''1000'''
* '''Bridge to''' -  you can select an instance that you want to bridge to. In this case select '''None'''.
*'''IPv4 address''' - Provide your '''RUT2''' first '''VLAN IP''' adress here. In this example '''10.10.10.2'''
*'''Netmask''' - netmask for provided IPv4 address above. In this example '''255.255.255.0'''
*'''MTU''' - '''1488'''
*'''Encapsulation''' - '''UDP'''
*'''UDP source port''' - '''RUT2''' UDP port. In this example '''6000'''
*'''UDP destination port''' - '''RUT1''' UDP port. In this example '''5000'''


# Access the router's WebUI, go to '''Services > VPN > L2TPv3''', and input the desired name for the new instance.
# Click the [[File:Add_Button.png|40px]] button
[[File:L2tpv3 over ipsec - wired wan - r2 - add instance.png|border|class=tlt-border]]
'''Instance Settings'''
----
----
<table class="nd-othertables_2">
    <tr>
        <th width=600; style="border-bottom: 1px solid white;></th>
        <th width=800; style="border-bottom: 1px solid white;" rowspan=2>
[[File:L2tpv3 over ipsec - wired wan - r2 - l2tpv3 instance settings.png|border|class=tlt-border|center]]</th>
    </tr>
    <tr>
        <td style="border-bottom: 4px solid white>
       
# '''Enable''' - if checked, enables the L2TPv3 instance
# '''Local address''' - IP address of the '''local''' instance. Provide '''RUT2''' device's '''LAN IP''' here.
# '''Tunnel ID''' - Uniquely identifies the tunnel. The value used must match the peer tunnel '''ID''' value being used at the peer. For this example '''4000'''.
# '''Session ID''' - The value used must match the tunnel ID value being used at the peer. For this example '''2000'''
# '''Cookie''' - The value used must match the RUT1 peer cookie value in L2TPv3 instance peer settings.
# '''Peer address''' - IP address of the '''remote''' instance. Provide '''RUT1''' device's '''LAN IP''' here.
# '''Peer Tunnel ID''' - '''RUT1''' Tunnel ID: '''4000'''
# '''Peer Session ID''' - '''RUT1''' Session ID: '''2000'''
# '''Peer Cookie''' - The value used must match the RUT2 cookie value in L2TPv3 instance settings.
# '''Bridge to''' -  you can select an instance that you want to bridge to. In this case select '''lan1''', which is bridged lan interface for VLAN3.
# '''MTU''' - '''1488'''
# '''Encapsulation''' - '''UDP'''
# '''UDP source port''' - '''RUT2''' UDP port. In this example '''5000'''
# '''UDP destination port''' - '''RUT1''' UDP port. In this example '''6000'''
# '''Layer 2 specific header type''' - Linux default
        </td>
    </tr>
</table>


===Firewall rules===
----


Before testing L2TPv3 over IPsec configuration we will need to change '''L2TPv3''' Firewall rules on both '''RUT1''' and '''RUT2'''.
====Testing L2TPv3 configuration====
To do that Open your device's '''Firewall''' by navigating to '''Network → Firewall → Traffic Rules'''. Now on both '''RUT1''' and '''RUT2''', you will need to find two rules called '''Allow-your_instance_name-L2TPv3-traffic'''


[[File:Networking rutxxx configuration examples l2tpv3 firewall v1.jpg|border|class=tlt-border|1100px]]
The simplest way to test an L2TPv3 connection is using the '''ip l2tp show tunnel''' command. You can execute this command via a command line interface (CLI). A CLI is present in all RUTxxx routers' WebUIs. To access it, login to one of the routers' WebUI (doesn't matter which one) and navigate to '''Services → CLI'''. Log in to CLI with the user name '''root''' and the router's '''admin password'''. Then simply the ''ip l2tp show tunnel'' and press the "Enter" key. If everything was configurated correctly you should see L2TPv3 tunnel information:


Now '''Edit''' both of these rules and search for '''Destination address''' field. In this field, there should be written '''0.0.0.0''' you need to '''delete''' this address and '''Save''' the configuration. Repeat this process on both rules and on both '''RUT1''' and '''RUT2'''.
'''RUT1:'''
[[File:L2tpv3 over ipsec - wired wan - r1 - ip l2tp show tunnel.png|border|class=tlt-border]]


[[File:Networking rutxxx configuration examples l2tpv3 firewall edit v1.jpg|border|class=tlt-border|1100px]]
'''RUT2:'''
[[File:L2tpv3 over ipsec - wired wan - r2 - ip l2tp show tunnel.png|border|class=tlt-border]]


----
==L2TPv3/IPsec Over Mobile Network==


===Testing L2TPv3 configuration===
The configuration will be nearly identical to the [[#L2TPv3/IPsec Over Wired WAN network|L2TPv3/IPsec over Wired WAN]] setup, with only a few slight adjustments to the IPsec settings.


The simplest way to test an L2TPv3 connection is using the '''ip l2tp show tunnel''' command. You can execute this command via a command line interface (CLI). A CLI is present in all RUTxxx routers' WebUIs. To access it, login to one of the routers' WebUI (doesn't matter which one) and navigate to '''Services → CLI'''. Log in to CLI with the user name '''root''' and the router's admin password. Then simply the ''ip l2tp show tunnel'' and press the "Enter" key. IF everything was configurated correctly you should see two L2TPv3 tunnels (example was taken from '''RUT1'''):
The steps for the '''L2TPv3 configuration''' will be identical to those outlined in the [[#L2TPv3 configuration|wired WAN configuration]].


[[File:Networking rutxxx configuration examples l2tpv3 tunnel status v1.jpg.jpg|border|class=tlt-border|1100px]]
===Topology===


==Testing full configuration==
[[File:L2tpv3 ipsec over mobile wan.png|border|class=tlt-border|center]]
===IPsec configuration===


===TCP Dump===
Set up IPsec following the same steps as in the [[#IPsec configuration|wired WAN configuration]], but in the '''RUT1''' settings, leave the '''Remote endpoint''' field '''empty''', and in the '''RUT2''' settings, specify the '''RUT1 Public IP''' address in the '''Remote endpoint''' field.


The first way of testing our setup would be to check if the traffic between '''RUT1''' and '''RUT2''' devices is encrypted. To do this we will require to utilize '''TCP Dump''', '''TCP Dump''' will let us capture traffic that goes through '''RUT2'''. In this example, we will install '''TCP Dump''' on '''RUT2''' and we will proceed on capturing the data that is going through the device.
'''RUT1:'''[[File:L2tpv3 over ipsec - mobile wan - r1 - ipsec instance settings.png|border|class=tlt-border]]
----


====Installing TCP Dump on RUT2====
'''RUT2:'''[[File:L2tpv3 over ipsec - mobile wan - r2 - ipsec instance settings.png|border|class=tlt-border]]


Firstly, you will need to connect to the '''RUT2''' device's '''CLI/SSH'''. You can connect the '''RUT2''' device CLI via WebUI by navigating to '''Services → CLI'''. Log in to '''CLI''' with the user name '''root''' and the router's admin password.
==Testing full configuration==


Now execute these commands one at a time:
To begin testing the setup, the first step is to verify if the traffic between '''RUT1''' and '''RUT2''' devices is encrypted. This can be achieved by using '''tcpdump''', a tool that allows capturing traffic. In this example, tcpdump will be installed on RUT2, and then data passing through the device will be captured for analysis.


===Installing TCP Dump===
----
Firstly, you will need to connect to the '''RUT2''' device's '''CLI/SSH'''. You can connect the '''RUT2''' device CLI via WebUI by navigating to '''Services → CLI'''. Log in to '''CLI''' with the user name '''root''' and the router's '''admin password'''.


Now execute these commands one at a time:


''opkg update''
''opkg update''


''opkg install tcpdump''
''opkg install tcpdump''


To test if TCP Dump has been installed on your device execute the command ''tcpdump''
To test if TCP Dump has been installed on your device execute the command ''tcpdump''


===Installing Wireshark===
----
----
To analyze the captured data from tcpdump, '''Wireshark''' will be used. While the data can be viewed directly through CLI/SSH, Wireshark provides a more detailed view and makes it easier to interpret the tcpdump output. You can download Wireshark: [https://www.wireshark.org/#download here].


====Installing Wireshark====
===Capturing TCP Dump===
 
To see captured data via TCP Dumb we will be using Wireshark, although the data can be seen directly from CLI/SSH, Wireshark will let you see more information about captured data and it is simpler to understand TCP Dump output. The Wireshark can be downloaded [https://www.wireshark.org/#download here].
 
----
----
Log in to the RUT2 CLI/SSH and execute the following command:


====Capturing TCP Dump====


''tcpdump -i eth0.2 -vv -w test.pcap''


Now you will need to login on to both '''RUT1''' and '''RUT2''' devices CLI/SSH.
Once you have logged on both devices CLI/SSH, on '''RUT1''' execute command '''ping 10.2.0.0'''


Leave this command running, the output should be similar:
This command captures all traffic on the wired '''wan''' interface and saves it to the '''test.pcap''' file. Leave this command running throughout the test.


[[File:Networking rutxxx configuration examples l2tpv3 ping rut2 lan v1.jpg|border|class=tlt-border|1100px]]
Initiate a ping from '''PC1''', connected to the '''RUT1 VLAN1''' network, to '''PC2''', connected to the '''RUT2 VLAN1''' network.
[[File:L2tpv3 over ipsec - wired wan - testing -pc1 ping command.png|border|class=tlt-border]]


----
Stop '''tcpdump''' command by pressing '''Ctrl + C'''.  
Now on RUT2 execute the command '''tcpdump -i wwan0 -n -w test.pcap''' this command will capture all '''wwan0 interface (mobile)''' traffic and write it into '''test.pcap''' file. Leave this command running for a minute and after that press '''Ctrl + C''' to stop this command.


[[File:Networking rutxxx configuration examples l2tpv3 tcpdump rut2 v1.jpg|border|class=tlt-border|1100px]]
[[File:Networking rutxxx configuration examples l2tpv3 tcpdump rut2 v1.jpg|border|class=tlt-border]]


Now in your device (at the directory in that you have executed the TCP Dump command(in this example /root/) you will be able to find '''test.pcap''' file, extract it to your computer(you can find instructions on how to do that here:[[Upload & Download Files from RutOS|'''Upload & Download Files from RutOS''']] and open this file with Wireshark. You should see similar output:
On the RUT2 device (in the directory where the tcpdump command was executed, such as '''/root/''' in this example), locate the '''test.pcap''' file. Extract the file to your computer. For instructions, refer to [[Upload & Download Files from RutOS|'''Upload & Download Files from RutOS''']] and open this file with Wireshark. You should see similar output:


[[File:Networking rutxxx configuration examples l2tpv3 wireshark rut2 v1.jpg|border|class=tlt-border|1100px]]
[[File:L2tpv3 over ipsec - wired wan - testing - r2 tcpdump capture.png|border|class=tlt-border]]


Here you will need to look if your devices communicate with '''ESP(Encapsulating Security Payload)''' protocol, if so then your configuration is working.  
If '''ESP (Encapsulating Security Payload)''' packets are present, the configuration is functioning correctly.


----
If traffic is captured directly on PC2 using Wireshark, the same data will be visible, but in a decrypted format:
[[File:L2tpv3 over ipsec - wired wan - testing - pc2 wireshark capture.png|border|class=tlt-border]]


===Ping VLANs===
To summarize:
Another simple method to check if the configuration is working is to test if '''RUT1 VLAN''' can reach '''RUT2 VLAN''' and vice versa. In this example we will execute ping command of '''VLAN1''' interface of '''RUT1''' to '''VLAN1''' of '''RUT2'''.


Once again login to RUT1 CLI/SSH and execute the command '''ping -I 10.10.10.1 10.10.10.2''' this will execute a ping from '''VLAN1 of RUT1 to VLAN1 of RUT2'''. If the configuration is working you should see a similar output of this command:
*Traffic between the IPSec routers (RUT1 and RUT2) will be encrypted while it is passing through the IPSec tunnel.
*Once the traffic reaches RUT2 (the destination router), it will be decrypted before being sent to the VLAN1 network, which includes PC2.


[[File:Networking rutxxx configuration examples l2tpv3 ping VLANS v1.jpg|border|class=tlt-border|1100px]]
----


==See also==
==See also==

Revision as of 13:41, 17 January 2025

Main Page > General Information > Configuration Examples > Use cases > L2TPv3 over IPsec configuration example

The information on this page is updated in accordance with firmware version 00.07.11.3.

Introduction

Due to the inherent lack of confidentiality in the Layer 2 Tunneling Protocol (L2TP), it is commonly secured by pairing it with Internet Protocol Security (IPsec). IPsec provides essential features such as confidentiality, authentication, and integrity for L2TP packets. This combination is widely referred to as L2TP over IPsec (or simply L2TP/IPsec) and is a standard approach for secure VPN implementations.

This article provides instructions on configuring L2TPv3 over IPsec on Teltonika routers and gateway devices. Please note that the guide is designed for advanced users and skips some of the more straightforward steps to maintain overall clarity. For instance, adding new instances is only briefly mentioned rather than described in detail. If this level of information feels insufficient for your setup, consider referring to our dedicated configuration guides IPsec and L2TP for reference.

Prerequisites

  • Two routers with configured VLANs, will refer to these as RUT1 and RUT2
  • At least one router with a Public IP addresses (for L2TPv3/IPsec over mobile)
  • Two PC devices for testing

L2TPv3/IPsec Over Wired WAN network

As mentioned in Prerequisites, two VLANs must be configured on both RUT devices. Detailed instructions for this process can be found on this page: VLAN Set Up. The remaining configuration steps are provided in this configuration example.

Topology

IPsec configuration

IPsec will be set up to ensure encrypted communication between two routers. The steps provided will guide through configuring the necessary parameters, such as authentication methods, encryption algorithms, and connection endpoints, starting with RUT1.

IPsec RUT1 Config


  1. Access the router's WebUI, go to Services > VPN > IPsec, and input the desired name for the new instance.
  2. Click the button


Instance configuration


  1. Enable instance;
  2. Remote endpoint - RUT2 wired WAN IP
  3. Authentication method - Pre-shared key
  4. Pre shared key - Your chosen password (must match for both RUT1 & RUT2)
  5. Local identifier – RUT1 LAN IP, which is 192.168.1.1 in this case
  6. Remote identifier – RUT2 LAN IP, which is 192.168.2.1 in this case

Connection general section configuration


  1. Mode - Start;
  2. Type - Tunnel;
  3. Default route - off
  4. Route based IPsec - off
  5. Local subnet – 192.168.1.0/24
  6. Remote subnet – 192.168.2.0/24
  7. Key exchange - IKEv2;

Proposal configuration


Important: Both the RUT1 and RUT2 Encryptions must match in order for this configuration to work.


Phase 1:

  1. Encryption - AES256
  2. Authentication - SHA512
  3. DH group - MODP4096
  4. IKE lifetime - 86400s

Phase 2:

  1. Encryption - AES256
  2. Authentication - SHA512;
  3. PFS group - MODP4096;
  4. Lifetime – 86400s

Note: This is only an example of a secure configuration. Other algorithms or even combinations of them could be used. However, we strongly recommend refraining from using older encryption and hashing algorithms unless support for certain legacy systems is required.

IPsec RUT2 Config


  1. Access the router's WebUI, go to Services > VPN > IPsec, and input the desired name for the new instance.
  2. Click the button

Instance configuration


  1. Enable instance;
  2. Remote endpoint - RUT1 wired WAN IP;
  3. Authentication method - Pre-shared key;
  4. Pre shared key - Your chosen password (must match for both RUT1 & RUT2)
  5. Local identifier – RUT1 LAN IP, which is 192.168.2.1 in this case;
  6. Remote identifier – RUT2 LAN IP, which is 192.168.1.1 in this case;

Connection general section configuration


  1. Mode - Start;
  2. Type - Tunnel;
  3. Default route - off
  4. Route based IPsec - off
  5. Local subnet – 192.168.2.0/24
  6. Remote subnet – 192.168.1.0/24
  7. Key exchange - IKEv2;

Proposal configuration


Important: Both the RUT1 and RUT2 Encryptions must match in order for this configuration to work.


Phase 1:

  1. Encryption - AES256;
  2. Authentication - SHA512;
  3. DH group - MODP4096;
  4. IKE lifetime - 24h

Phase 2:

  1. Encryption - AES256;
  2. Authentication - SHA512;
  3. PFS group - MODP4096;
  4. Lifetime – 24h;

Note: This is only an example of a secure configuration. Other algorithms or even combinations of them could be used. However, we strongly recommend refraining from using older encryption and hashing algorithms unless support for certain legacy systems is required.


Testing IPsec connection

After completing the configuration, it is essential to test its functionality before proceeding further. The simplest method to test an IPsec connection is by using the swanctl -l command. This command can be executed via the command line interface (CLI)and to access the CLI, log in to the WebUI of any router (either one can be used), navigate to Services → CLI, log in to the CLI using the username root and the router's admin password. More details on accessing the CLI can be found here.


Enter the command swanctl -l and press the "Enter" key:

If "established" appears in the output along with other connection details, it indicates that the IPsec connection was successful.


L2TPv3 configuration

L2TPv3 is an enhanced version of L2TP, providing support for Layer 3 (IP) and Layer 2 (Ethernet) tunneling. It is typically used in scenarios where the need for secure data transmission across an untrusted network exists, such as remote access or site-to-site VPNs.

New L2TPv3 instances can be created from the Services > VPN > L2TPv3 section of the router's WebUI. Enter a custom name and click the "Add" button to create a new instance. Then click the "Edit" button located next to the newly created instance to enter its configuration page.

L2TPv3 RUT1 Config


  1. Access the router's WebUI, go to Services > VPN > L2TPv3, and input the desired name for the new instance.
  2. Click the button

Instance Settings


  1. Enable - if checked, enables the L2TPv3 instance
  2. Local address - IP address of the local instance. Provide RUT1 device's LAN IP here.
  3. Tunnel ID - Uniquely identifies the tunnel. The value used must match the peer tunnel ID value being used at the peer. For this example 3000.
  4. Session ID - The value used must match the tunnel ID value being used at the peer. For this example 1000
  5. Cookie - The value used must match the RUT2 peer cookie value in L2TPv3 instance peer settings.
  6. Peer address - IP address of the remote instance. Provide RUT2 device's LAN IP here.
  7. Peer Tunnel ID - RUT2 Tunnel ID: 4000
  8. Peer Session ID - RUT2 Session ID: 2000
  9. Peer Cookie - The value used must match the RUT2 cookie value in L2TPv3 instance settings.
  10. Bridge to - you can select an instance that you want to bridge to. In this case select lan1, which is bridged lan interface for VLAN3.
  11. MTU - 1488
  12. Encapsulation - UDP
  13. UDP source port - RUT1 UDP port. In this example 5000
  14. UDP destination port - RUT2 UDP port. In this example 6000
  15. Layer 2 specific header type - Linux default

L2TPv3 RUT2 Config

  1. Access the router's WebUI, go to Services > VPN > L2TPv3, and input the desired name for the new instance.
  2. Click the button

Instance Settings


  1. Enable - if checked, enables the L2TPv3 instance
  2. Local address - IP address of the local instance. Provide RUT2 device's LAN IP here.
  3. Tunnel ID - Uniquely identifies the tunnel. The value used must match the peer tunnel ID value being used at the peer. For this example 4000.
  4. Session ID - The value used must match the tunnel ID value being used at the peer. For this example 2000
  5. Cookie - The value used must match the RUT1 peer cookie value in L2TPv3 instance peer settings.
  6. Peer address - IP address of the remote instance. Provide RUT1 device's LAN IP here.
  7. Peer Tunnel ID - RUT1 Tunnel ID: 4000
  8. Peer Session ID - RUT1 Session ID: 2000
  9. Peer Cookie - The value used must match the RUT2 cookie value in L2TPv3 instance settings.
  10. Bridge to - you can select an instance that you want to bridge to. In this case select lan1, which is bridged lan interface for VLAN3.
  11. MTU - 1488
  12. Encapsulation - UDP
  13. UDP source port - RUT2 UDP port. In this example 5000
  14. UDP destination port - RUT1 UDP port. In this example 6000
  15. Layer 2 specific header type - Linux default

Testing L2TPv3 configuration

The simplest way to test an L2TPv3 connection is using the ip l2tp show tunnel command. You can execute this command via a command line interface (CLI). A CLI is present in all RUTxxx routers' WebUIs. To access it, login to one of the routers' WebUI (doesn't matter which one) and navigate to Services → CLI. Log in to CLI with the user name root and the router's admin password. Then simply the ip l2tp show tunnel and press the "Enter" key. If everything was configurated correctly you should see L2TPv3 tunnel information:

RUT1:

RUT2:

L2TPv3/IPsec Over Mobile Network

The configuration will be nearly identical to the L2TPv3/IPsec over Wired WAN setup, with only a few slight adjustments to the IPsec settings.

The steps for the L2TPv3 configuration will be identical to those outlined in the wired WAN configuration.

Topology

IPsec configuration

Set up IPsec following the same steps as in the wired WAN configuration, but in the RUT1 settings, leave the Remote endpoint field empty, and in the RUT2 settings, specify the RUT1 Public IP address in the Remote endpoint field.

RUT1:

RUT2:

Testing full configuration

To begin testing the setup, the first step is to verify if the traffic between RUT1 and RUT2 devices is encrypted. This can be achieved by using tcpdump, a tool that allows capturing traffic. In this example, tcpdump will be installed on RUT2, and then data passing through the device will be captured for analysis.

Installing TCP Dump


Firstly, you will need to connect to the RUT2 device's CLI/SSH. You can connect the RUT2 device CLI via WebUI by navigating to Services → CLI. Log in to CLI with the user name root and the router's admin password.

Now execute these commands one at a time:

opkg update

opkg install tcpdump

To test if TCP Dump has been installed on your device execute the command tcpdump

Installing Wireshark


To analyze the captured data from tcpdump, Wireshark will be used. While the data can be viewed directly through CLI/SSH, Wireshark provides a more detailed view and makes it easier to interpret the tcpdump output. You can download Wireshark: here.

Capturing TCP Dump


Log in to the RUT2 CLI/SSH and execute the following command:


tcpdump -i eth0.2 -vv -w test.pcap


This command captures all traffic on the wired wan interface and saves it to the test.pcap file. Leave this command running throughout the test.

Initiate a ping from PC1, connected to the RUT1 VLAN1 network, to PC2, connected to the RUT2 VLAN1 network.

Stop tcpdump command by pressing Ctrl + C.

On the RUT2 device (in the directory where the tcpdump command was executed, such as /root/ in this example), locate the test.pcap file. Extract the file to your computer. For instructions, refer to Upload & Download Files from RutOS and open this file with Wireshark. You should see similar output:

If ESP (Encapsulating Security Payload) packets are present, the configuration is functioning correctly.

If traffic is captured directly on PC2 using Wireshark, the same data will be visible, but in a decrypted format:

To summarize:

  • Traffic between the IPSec routers (RUT1 and RUT2) will be encrypted while it is passing through the IPSec tunnel.
  • Once the traffic reaches RUT2 (the destination router), it will be decrypted before being sent to the VLAN1 network, which includes PC2.

See also

Other types of VPNs supported by RUTxxx devices: