Jump to content

Overlapping subnets with IPsec solution: Difference between revisions

From Teltonika Networks Wiki
No edit summary
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<p style="color:red">The information on this page is updated in accordance with the [https://wiki.teltonika-networks.com/view/FW_%26_SDK_Downloads'''00.07.17.4'''] firmware version.</p>
==Introduction==
==Introduction==
This article provides an extensive configuration example with details on how to configure Ipsec with overlapping subnets.
This article provides an extensive configuration example with details on how to solve overlapping subnets when using IPsec.


==Configuration overview and prerequisites==
==Configuration overview and prerequisites==
'''Prerequisites:'''
'''Prerequisites:'''
*Two RUTxxx routers of any type.
*Two RUTxxx routers of any type (excluding RUT850)
*A SIM card with a Public Static or Public Dynamic IP address for the IPsec server.
*A SIM card with a Public Static or Public Dynamic IP address for the IPsec server
*An end device (PC, Laptop, Tablet, Smartphone) to configure the  
*An end device (PC, Laptop, Tablet, Smartphone) to configure the routers
*Installing package via '''[https://wiki.teltonika-networks.com/view/RUT241_Package_Manager package manager]''' on both devices: '''IPtables NAT extra'''
 
 
----
----
'''Configuration scheme''':
'''Configuration scheme''':
Line 22: Line 17:
===Basic tunnel===
===Basic tunnel===
----
----
First of all, let’s configure a simple connection between two IPsec instances, i.e., RUT1 and RUT2.
First of, lets configure a simple connection between two IPsec instances, i.e., RUT1 and RUT2.


====RUT1 configuration====
====RUT1 configuration====
----
----
[[File:Ipsec_Over_1.png|border|class=tlt-border]]
[[File:IPsec1 config.png|border|class=tlt-border|700x700px]]
[[File:Ipsec_Over_2.png|border|class=tlt-border]]
[[File:Ipsec2_config.png|border|class=tlt-border|700x700px]]
#'''Enable''' instance.
#'''Enable''' instance.
#'''Remote endpoint''' (Only one side of IPsec needs to have it configured)
#'''Remote endpoint''' (Only one side of IPsec needs to have it configured)
#Enter the '''Pre shared key'''(a shared password used for authentication between the peers. The value of this field must match on both instances).
#Write '''Pre shared key'''(a shared password used for authentication between the peers. The value of this field must match on both instances).
#Select tunnel '''Type'''
#Select '''Type''' to tunnel
#Enter '''Local subnet '''(an IP address/Subnet mask of the router on which the IPsec instance is configured).
#Write '''Local subnet '''(an IP address/Subnet mask of the router on which the IPsec instance is configured).
#Enter '''Remote subnet '''
#Write '''Remote subnet '''


====RUT2 configuration====
====RUT2 configuration====
----
----
[[File:Ipsec_Over_3.png|border|class=tlt-border]]
[[File:Ipsec3 config Overlapping subnets solution example .png|border|class=tlt-border|700x700px]]
[[File:Ipsec_Over_4.png|border|class=tlt-border]]
[[File:Ipsec4 config Overlapping subnets solution example .png|border|class=tlt-border|700x700px]]
#'''Enable''' instance.
#'''Enable''' instance.
#Enter '''Remote endpoint'''
#Add '''Remote endpoint'''
#Enter '''Pre shared key''' (a shared password used for authentication between the peers. The value of this field must match on both instances).
#Write '''Pre shared key''' (a shared password used for authentication between the peers. The value of this field must match on both instances).
#Select tunnel '''Type'''  
#Select '''Type''' to tunnel
#Enter '''Local subnet '''(an IP address/Subnet mask of the router on which the IPsec instance is configured).
#Write '''Local subnet '''(an IP address/Subnet mask of the router on which the IPsec instance is configured).
#Enter '''Remote subnet '''
#Write '''Remote subnet '''


====Check IPsec tunnel status====
====Check IPsec tunnel status====
----
----
If you’ve followed all the steps above, your configuration should be complete. However, as with any configuration, it is wise to test the setup to ensure it works properly. This can be verified by running '''swanctl --list-sas''' command in RUT CLI, you should see tunnel between virtual networks:
If you've followed all the steps presented above, your configuration should be finished. But as with any other configuration, it is always wise to test the setup in order to make sure that it works properly. This can be verified by running '''ipsec status''' command in RUT CLI, you should see tunnel being installed between virtual networks:


<pre>root@RUT1:~# swanctl --list-sas
<pre>root@Teltonika-RUTX12:~# ipsec status
Server: #7, ESTABLISHED, IKEv1, da0c8d300529bd5a_i 812482f852fb55b7_r*                                                                               
Security Associations (1 up, 0 connecting):
  local  '192.168.2.124' @ 192.168.2.124[500]                                                                                                      
ipsec-ipsec_c[1]: ESTABLISHED 32 MINUTES AGO, 192.168.2.124[192.168.2.124]...192.168.2.145[192.168.2.145]
  remote '192.168.2.145' @ 192.168.2.145[500]                                                                                                        
ipsec-ipsec_c{1}:  INSTALLED, TUNNEL, reqid 1, ESP SPIs: ca6d4767_i c3f5534b_o
  AES_CBC-128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_1536                                                                                                   
ipsec-ipsec_c{1}:  192.168.3.0/24 === 192.168.4.0/24</pre>
  established 2409s ago, rekeying in 11816s                                                                                                         
  Server_c: #2, reqid 1, INSTALLED, TUNNEL, ESP:AES_CBC-128/HMAC_SHA1_96/MODP_1536                                                                   
    installed 2408s ago, rekeying in 1017s, expires in 1555s                                                                                         
    in  c0795e33,      0 bytes,    0 packets                                                                                                       
    out c7a0bca0,      0 bytes,    0 packets                                                                                                       
    local  192.168.3.0/24                                                                                                                            
    remote 192.168.4.0/24   </pre>


===Firewall configuration===
===Firewall configuration===
After establishing IPsec tunnel it's necessary to map LAN network IP addresses to virtual IPsec network addresses,  for this we'll use iptables NETMAP target. Insert these IPtables rules into '''WebUI -> Network -> Firewall -> Custom rules'''.
After establishing IPsec tunnel it's necessary to map LAN network IP addresses to virtual IPsec network addresses,  for this we'll use iptables NETMAP target. Insert these '''IPtables rules into WebUI -> Network -> Firewall -> Custom rules'''.


[[File:Custom rules for overlapping subnets.png|border|class=tlt-border|1100x1100px]]
====RUT1 Firewall configuration====
====RUT1 Firewall configuration====
----
----
<pre>iptables -t nat -I POSTROUTING -s 192.168.1.0/24 -d 192.168.4.0/24 -j NETMAP --to 192.168.3.0/24
<pre>iptables -t nat -I POSTROUTING -s 192.168.1.0/24 -d 192.168.4.0/24 -j NETMAP --to 192.168.3.0/24
iptables -t nat -I PREROUTING -s 192.168.4.0/24 -j NETMAP --to 192.168.1.0/24</pre>
iptables -t nat -I PREROUTING -s 192.168.4.0/24 -j NETMAP --to 192.168.1.0/24</pre>
[[File:Ipsec_Over_5.png|border|class=tlt-border]]


====RUT2 Firewall configuration====
====RUT2 Firewall configuration====
Line 78: Line 65:
iptables -t nat -I PREROUTING -s 192.168.3.0/24 -j NETMAP --to 192.168.1.0/24</pre>
iptables -t nat -I PREROUTING -s 192.168.3.0/24 -j NETMAP --to 192.168.1.0/24</pre>


[[File:Ipsec_Over_6.png|border|class=tlt-border]]
'''POSTROUTING''' rule checks if outgoing packet destination IP belongs to remote IPsec virtual IP range, if yes, it will change packet source IP from LAN IP to virtual IPsec IP.
 
'''PREROUTING''' rule checks if incoming packet source IP belongs to remote IPsec virtual IP range, if yes, it will change incoming packet destination IP from virtual IPsec IP to LAN IP.
===Routing configuration===
----
To reach virtual addresses routes should be configured under '''WebUI -> Network -> Routing -> Policy Based Routing'''.


Aplly configuration to the devices that virutal addresses would be reachable form LAN:
Now LAN to LAN communication should be possible between end devices but to enable RUT to RUT communication additionally it'll be needed to install route on each device.


=====RUT1 Routing Configuration=====
===Routing update===
----
----
Add new instance:
To have permanent static route navigate to '''WebUI -> Network -> Routing -> Advanced static routes'''.
 
Add new routing table and insert static route where:
# Enter ID: '''123'''
* '''Interface''' is LAN
# Enter New configuration name: '''Ipsec'''
* '''Target''' is remote IPsec virtual network
[[File:Ipsec_Over_7.png|border|class=tlt-border|center]]
* '''Gateway''' is LAN IP
[[File:Table route overlapping subnets solution example.png|border|class=tlt-border|1100x1100px]]
Then create IP rule and specify lookup table.


click [[File:Add Button.png|40x70px]] in the new window make following changes:
[[File:Routing rule overlapping subnets solution example.png|border|class=tlt-border|700x700px]]
 
=====Static IPv4 Routes=====
----
click [[File:Add Button.png|40x70px]] and apply this to the route:
#Select Interface: '''lan''' | Enter Target: '''192.168.4.0''' | Enter IPv4-Netmask: '''255.255.255.0''' | Enter IPv4-Gateway: '''192.168.1.1'''
[[File:Ipsec_Over_8.png|border|class=tlt-border|center|1000x300px]]
 
====Routing Rules for IPv4====
----
By clicking [[File:Add Button.png|40x70px]] create rule under '''Routing Rules for IPv4''' tab apply these changes to the rules:
=====RUT1 Policy Rule=====
----
# Enter Priority: '''1'''
# Lookup Table: '''Ipsec (123)'''
 
[[File:Ipsec_Over_9.png|border|class=tlt-border|center|1000x800px]]
 
=====RUT2 Routing Configuration=====
----
Add new instance:
 
# Enter ID: '''123'''
# Enter New configuration name: '''Ipsec'''
[[File:Ipsec_Over_7.png|border|class=tlt-border|center]]
 
click [[File:Add Button.png|40x70px]] in the new window make following changes:
 
=====Static IPv4 Routes=====
----
click [[File:Add Button.png|40x70px]] and apply this to the route:
#Select Interface: '''lan''' | Enter Target: '''192.168.3.0''' | Enter IPv4-Netmask: '''255.255.255.0''' | Enter IPv4-Gateway: '''192.168.1.1'''
[[File:Ipsec_Over_10.png|border|class=tlt-border|center|1000x300px]]
 
====Routing Rules for IPv4====
----
By clicking [[File:Add Button.png|40x70px]] create rule under '''Routing Rules for IPv4''' tab apply these changes to the rules:
=====RUT2 Policy Rule=====
----
# Enter Priority: '''1'''
# Lookup Table: '''Ipsec (123)'''
 
[[File:Ipsec_Over_9.png|border|class=tlt-border|center|1000x800px]]
 
===Connectivity testing===
----
Sending ping requests from the LAN to the virtual addresses
 
====RUT1====
----
[[File:Ipsec_Over_11.png|border|class=tlt-border|center]]
 
====RUT2====
----
[[File:Ipsec_Over_12.png|border|class=tlt-border|center]]
[[Category:VPN]]

Revision as of 14:06, 12 January 2022

Main Page > General Information > Configuration Examples > VPN > Overlapping subnets with IPsec solution

Introduction

This article provides an extensive configuration example with details on how to solve overlapping subnets when using IPsec.

Configuration overview and prerequisites

Prerequisites:

  • Two RUTxxx routers of any type (excluding RUT850)
  • A SIM card with a Public Static or Public Dynamic IP address for the IPsec server
  • An end device (PC, Laptop, Tablet, Smartphone) to configure the routers

Configuration scheme:

Router configuration

If you have familiarized yourself with the configuration scheme and have all of the devices in order, we can start configuring the routers using instructions provided in this section.

Basic tunnel


First of, lets configure a simple connection between two IPsec instances, i.e., RUT1 and RUT2.

RUT1 configuration


  1. Enable instance.
  2. Remote endpoint (Only one side of IPsec needs to have it configured)
  3. Write Pre shared key(a shared password used for authentication between the peers. The value of this field must match on both instances).
  4. Select Type to tunnel
  5. Write Local subnet (an IP address/Subnet mask of the router on which the IPsec instance is configured).
  6. Write Remote subnet

RUT2 configuration


  1. Enable instance.
  2. Add Remote endpoint
  3. Write Pre shared key (a shared password used for authentication between the peers. The value of this field must match on both instances).
  4. Select Type to tunnel
  5. Write Local subnet (an IP address/Subnet mask of the router on which the IPsec instance is configured).
  6. Write Remote subnet

Check IPsec tunnel status


If you've followed all the steps presented above, your configuration should be finished. But as with any other configuration, it is always wise to test the setup in order to make sure that it works properly. This can be verified by running ipsec status command in RUT CLI, you should see tunnel being installed between virtual networks:

root@Teltonika-RUTX12:~# ipsec status
Security Associations (1 up, 0 connecting):
ipsec-ipsec_c[1]: ESTABLISHED 32 MINUTES AGO, 192.168.2.124[192.168.2.124]...192.168.2.145[192.168.2.145]
ipsec-ipsec_c{1}:  INSTALLED, TUNNEL, reqid 1, ESP SPIs: ca6d4767_i c3f5534b_o
ipsec-ipsec_c{1}:   192.168.3.0/24 === 192.168.4.0/24

Firewall configuration

After establishing IPsec tunnel it's necessary to map LAN network IP addresses to virtual IPsec network addresses, for this we'll use iptables NETMAP target. Insert these IPtables rules into WebUI -> Network -> Firewall -> Custom rules.

RUT1 Firewall configuration


iptables -t nat -I POSTROUTING -s 192.168.1.0/24 -d 192.168.4.0/24 -j NETMAP --to 192.168.3.0/24
iptables -t nat -I PREROUTING -s 192.168.4.0/24 -j NETMAP --to 192.168.1.0/24

RUT2 Firewall configuration


iptables -t nat -I POSTROUTING -s 192.168.1.0/24 -d 192.168.3.0/24 -j NETMAP --to 192.168.4.0/24
iptables -t nat -I PREROUTING -s 192.168.3.0/24 -j NETMAP --to 192.168.1.0/24

POSTROUTING rule checks if outgoing packet destination IP belongs to remote IPsec virtual IP range, if yes, it will change packet source IP from LAN IP to virtual IPsec IP. PREROUTING rule checks if incoming packet source IP belongs to remote IPsec virtual IP range, if yes, it will change incoming packet destination IP from virtual IPsec IP to LAN IP.

Now LAN to LAN communication should be possible between end devices but to enable RUT to RUT communication additionally it'll be needed to install route on each device.

Routing update


To have permanent static route navigate to WebUI -> Network -> Routing -> Advanced static routes. Add new routing table and insert static route where:

  • Interface is LAN
  • Target is remote IPsec virtual network
  • Gateway is LAN IP

Then create IP rule and specify lookup table.