<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>VyOS - Blog</title>
    <link>https://blog.vyos.io</link>
    <description>VyOS Platform Project news and updates 
All about development and project life in  our blog</description>
    <language>en</language>
    <pubDate>Wed, 04 May 2022 09:45:50 GMT</pubDate>
    <dc:date>2022-05-04T09:45:50Z</dc:date>
    <dc:language>en</dc:language>
    <item>
      <title>Which VPN protocol to use</title>
      <link>https://blog.vyos.io/which-vpn-software-to-use</link>
      <description>&lt;div class="hs-featured-image-wrapper"&gt; 
 &lt;a href="https://blog.vyos.io/which-vpn-software-to-use" title="" class="hs-featured-image-link"&gt; &lt;img src="https://blog.vyos.io/hubfs/vpn.png" alt="vpn picture" class="hs-featured-image" style="width:auto !important; max-width:50%; float:left; margin:0 15px 15px 0;"&gt; &lt;/a&gt; 
&lt;/div&gt; 
&lt;p&gt;&lt;span&gt;Hello Community!&lt;/span&gt;&lt;/p&gt; 
&lt;p&gt;&lt;span&gt;A question that often comes up in networking software discussions is "which VPN protocol should I use?" followed by "why should I use that one when there are so many others?" I'm going to try to tackle these questions in lay terms here.&lt;/span&gt;&lt;/p&gt;</description>
      <content:encoded>&lt;div class="hs-featured-image-wrapper"&gt; 
 &lt;a href="https://blog.vyos.io/which-vpn-software-to-use" title="" class="hs-featured-image-link"&gt; &lt;img src="https://blog.vyos.io/hubfs/vpn.png" alt="vpn picture" class="hs-featured-image" style="width:auto !important; max-width:50%; float:left; margin:0 15px 15px 0;"&gt; &lt;/a&gt; 
&lt;/div&gt; 
&lt;p&gt;&lt;span&gt;Hello Community!&lt;/span&gt;&lt;/p&gt; 
&lt;p&gt;&lt;span&gt;A question that often comes up in networking software discussions is "which VPN protocol should I use?" followed by "why should I use that one when there are so many others?" I'm going to try to tackle these questions in lay terms here.&lt;/span&gt;&lt;/p&gt;  
&lt;img src="https://track.hubspot.com/__ptq.gif?a=4129050&amp;amp;k=14&amp;amp;r=https%3A%2F%2Fblog.vyos.io%2Fwhich-vpn-software-to-use&amp;amp;bu=https%253A%252F%252Fblog.vyos.io&amp;amp;bvt=rss" alt="" width="1" height="1" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important; "&gt;</content:encoded>
      <category>vpn</category>
      <category>vyos</category>
      <pubDate>Wed, 04 May 2022 09:45:50 GMT</pubDate>
      <author>e.altunbas@vyos.io (Erkin Batu Altunbas)</author>
      <guid>https://blog.vyos.io/which-vpn-software-to-use</guid>
      <dc:date>2022-05-04T09:45:50Z</dc:date>
    </item>
    <item>
      <title>Using DMVPN and BGP to interconnect your sites</title>
      <link>https://blog.vyos.io/using-dmvpn-and-bgp-to-interconnect-multiple-sites</link>
      <description>&lt;div class="hs-featured-image-wrapper"&gt; 
 &lt;a href="https://blog.vyos.io/using-dmvpn-and-bgp-to-interconnect-multiple-sites" title="" class="hs-featured-image-link"&gt; &lt;img src="https://blog.vyos.io/hubfs/image-png-Oct-30-2021-10-31-15-23-AM.png" alt="dmvpn topology pic" class="hs-featured-image" style="width:auto !important; max-width:50%; float:left; margin:0 15px 15px 0;"&gt; &lt;/a&gt; 
&lt;/div&gt; 
&lt;p&gt;Hello, Community!&lt;/p&gt; 
&lt;p&gt;Some weeks ago a very close friend of mine approached me and asked about an issue in his VyOS installation. He is using several WireGuard tunnels in a star topology connecting his private sites with a central hub. All of his traffic is forced to traverse the hub - which adds additional latency to the connections.&lt;/p&gt; 
&lt;p&gt;He wanted to change the design so that individual spokes are able to talk to one another, directly. This requires a topology change to a full-mesh when sticking with WireGuard. A fully meshed WireGuard installation with 4 sites will require you to configure 3 WireGuard tunnels per individual site, leading to a total of 12 tunnels—too complex!&lt;/p&gt; 
&lt;p&gt;I then explained how to use &lt;a href="https://docs.vyos.io/en/equuleus/configuration/vpn/dmvpn.html?highlight=dmvpn"&gt;DMVPN&lt;/a&gt; (Dynamic Multipoint Virtual Private Network) with VyOS—and as there is a new LTS release on the way, it is time for some in-depth testing of a very old feature! As DMVPN was the initial reason I choose VyOS (1.1.7, more than 5 years ago), it is fun for me to write about the same topic in 2021.&lt;/p&gt;</description>
      <content:encoded>&lt;div class="hs-featured-image-wrapper"&gt; 
 &lt;a href="https://blog.vyos.io/using-dmvpn-and-bgp-to-interconnect-multiple-sites" title="" class="hs-featured-image-link"&gt; &lt;img src="https://blog.vyos.io/hubfs/image-png-Oct-30-2021-10-31-15-23-AM.png" alt="dmvpn topology pic" class="hs-featured-image" style="width:auto !important; max-width:50%; float:left; margin:0 15px 15px 0;"&gt; &lt;/a&gt; 
&lt;/div&gt; 
&lt;p&gt;Hello, Community!&lt;/p&gt; 
&lt;p&gt;Some weeks ago a very close friend of mine approached me and asked about an issue in his VyOS installation. He is using several WireGuard tunnels in a star topology connecting his private sites with a central hub. All of his traffic is forced to traverse the hub - which adds additional latency to the connections.&lt;/p&gt; 
&lt;p&gt;He wanted to change the design so that individual spokes are able to talk to one another, directly. This requires a topology change to a full-mesh when sticking with WireGuard. A fully meshed WireGuard installation with 4 sites will require you to configure 3 WireGuard tunnels per individual site, leading to a total of 12 tunnels—too complex!&lt;/p&gt; 
&lt;p&gt;I then explained how to use &lt;a href="https://docs.vyos.io/en/equuleus/configuration/vpn/dmvpn.html?highlight=dmvpn"&gt;DMVPN&lt;/a&gt; (Dynamic Multipoint Virtual Private Network) with VyOS—and as there is a new LTS release on the way, it is time for some in-depth testing of a very old feature! As DMVPN was the initial reason I choose VyOS (1.1.7, more than 5 years ago), it is fun for me to write about the same topic in 2021.&lt;/p&gt;  
&lt;img src="https://track.hubspot.com/__ptq.gif?a=4129050&amp;amp;k=14&amp;amp;r=https%3A%2F%2Fblog.vyos.io%2Fusing-dmvpn-and-bgp-to-interconnect-multiple-sites&amp;amp;bu=https%253A%252F%252Fblog.vyos.io&amp;amp;bvt=rss" alt="" width="1" height="1" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important; "&gt;</content:encoded>
      <category>bgp</category>
      <category>ipsec</category>
      <category>vpn</category>
      <category>dmvpn</category>
      <category>pppoe</category>
      <pubDate>Sun, 31 Oct 2021 13:04:02 GMT</pubDate>
      <author>christian@poessinger.com (Christian Pössinger)</author>
      <guid>https://blog.vyos.io/using-dmvpn-and-bgp-to-interconnect-multiple-sites</guid>
      <dc:date>2021-10-31T13:04:02Z</dc:date>
    </item>
    <item>
      <title>PKI and IPSec IKEv2 remote-access VPN</title>
      <link>https://blog.vyos.io/pki-and-ipsec-ikev2-remote-access-vpn</link>
      <description>&lt;div class="hs-featured-image-wrapper"&gt; 
 &lt;a href="https://blog.vyos.io/pki-and-ipsec-ikev2-remote-access-vpn" title="" class="hs-featured-image-link"&gt; &lt;img src="https://blog.vyos.io/hubfs/IPSec%20IKEv2%20remote-access%20VPN.png" alt="remote access vpn ipsec ikev2" class="hs-featured-image" style="width:auto !important; max-width:50%; float:left; margin:0 15px 15px 0;"&gt; &lt;/a&gt; 
&lt;/div&gt; 
&lt;p&gt;Hello!&lt;/p&gt; 
&lt;p&gt;VyOS was always strong in supporting a multitude of different VPN techniques ranging from old school IPsec site-to-site/DMVPN setups to new kids on the block like SSTP, OpenVPN, and WireGuard. Today I want to present a new feature that was added to VyOS in the current 1.4 (Sagitta) development cycle — IKEv2 remote-access VPN.&lt;/p&gt; 
&lt;p&gt;Given the fact this is actually not a "new" technology, it is still a very interesting one as it is natively supported on all major operating systems!&lt;/p&gt;</description>
      <content:encoded>&lt;div class="hs-featured-image-wrapper"&gt; 
 &lt;a href="https://blog.vyos.io/pki-and-ipsec-ikev2-remote-access-vpn" title="" class="hs-featured-image-link"&gt; &lt;img src="https://blog.vyos.io/hubfs/IPSec%20IKEv2%20remote-access%20VPN.png" alt="remote access vpn ipsec ikev2" class="hs-featured-image" style="width:auto !important; max-width:50%; float:left; margin:0 15px 15px 0;"&gt; &lt;/a&gt; 
&lt;/div&gt; 
&lt;p&gt;Hello!&lt;/p&gt; 
&lt;p&gt;VyOS was always strong in supporting a multitude of different VPN techniques ranging from old school IPsec site-to-site/DMVPN setups to new kids on the block like SSTP, OpenVPN, and WireGuard. Today I want to present a new feature that was added to VyOS in the current 1.4 (Sagitta) development cycle — IKEv2 remote-access VPN.&lt;/p&gt; 
&lt;p&gt;Given the fact this is actually not a "new" technology, it is still a very interesting one as it is natively supported on all major operating systems!&lt;/p&gt;  
&lt;img src="https://track.hubspot.com/__ptq.gif?a=4129050&amp;amp;k=14&amp;amp;r=https%3A%2F%2Fblog.vyos.io%2Fpki-and-ipsec-ikev2-remote-access-vpn&amp;amp;bu=https%253A%252F%252Fblog.vyos.io&amp;amp;bvt=rss" alt="" width="1" height="1" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important; "&gt;</content:encoded>
      <category>ipsec</category>
      <category>vpn</category>
      <category>1.4</category>
      <category>remote access</category>
      <pubDate>Sun, 01 Aug 2021 20:30:39 GMT</pubDate>
      <author>christian@poessinger.com (Christian Pössinger)</author>
      <guid>https://blog.vyos.io/pki-and-ipsec-ikev2-remote-access-vpn</guid>
      <dc:date>2021-08-01T20:30:39Z</dc:date>
    </item>
    <item>
      <title>Take a third option: site to site OpenVPN</title>
      <link>https://blog.vyos.io/take-a-third-option-site-to-site-openvpn</link>
      <description>&lt;div class="posthaven-post-body"&gt; 
 &lt;p&gt;I've written a long series of post about setting up IPsec VPNs between NATed machines. As you've already seen, with some creative configuration it's possible, but is it always worth the sacrifice? Sometimes performance requirements, or lack of support for anything else on the other side make it necessary, but if the other side is also a VyOS, or another open source system, there's an alternative.&lt;/p&gt; 
 &lt;p&gt;While OpenVPN is usually associated with road warrior VPN setups, it is not limited to it. It does have a site to site option and it's very quick and easy to setup. For some strange reason, that option is neglected by just about everyone who otherwise supports OpenVPN: in OpenWRT it's possible to setup through custom config options, while in Mikrotik RouterOS it's not possible to setup at all. In VyOS we have an explicit option for it. OPNsense also supports site to site OpenVPN out of the box (I thought it doesn't, but the authors corrected me).&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;The advantages are that it takes very few commands to get a tunnel to work, and that it will work in any network where you can forward a single port, even is both sides are behind double NAT. The downside is performance: squeezing even 100mbit/s of encrypted traffic out of it can be impossible, typical iperf figures are 10-20 mbit/s. For many use cases that performance is more than enough, though if you plan to use the tunnel for storage replication or another high-traffic job, that option is definitely not for you and you'll have to resort to IPsec.&lt;/p&gt; 
 &lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;br&gt; &lt;/p&gt; 
 &lt;h2&gt;Setting up site to site OpenVPN&lt;/h2&gt; 
 &lt;h3&gt;Generating a key&lt;/h3&gt; 
 &lt;p&gt;OpenVPN in site to site mode supports either static pre-shared keys or x.509. For a quick tunnel setup between your own routers, the format option is a lot easier and arguably not less secure. Unlike most IPsec implementations, OpenVPN stores pre-shared keys in files, and uses keys of considerable length (default is 2038. It takes just one command to generate a suitable key:&lt;/p&gt; 
 &lt;pre&gt;run generate openvpn key /config/auth/mysite.key
&lt;/pre&gt; 
 &lt;p&gt;Then you can copy the file to the remote side via SCP or something else. That command is a wrapper for "openvpn --genkey --secret" in case you want to generate a key outside VyOS. It's a good idea to store the keys in /config/auth directory that was specifically meant for authentication data, since /config will be migrated to the new image when you upgrade your system — if you put them in /etc, they will be inaccessible from the upgraded image.&lt;/p&gt; 
 &lt;h3&gt;Setting up the tunnel&lt;/h3&gt; 
 &lt;p&gt;It's quite straightforward. &lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;Local (listening) side:&lt;/p&gt; 
 &lt;pre&gt;set interfaces openvpn vtun10 mode site-to-site&lt;br&gt;
set interfaces openvpn vtun10 description 'My remote site'&lt;br&gt;
set interfaces openvpn vtun10 local-host 203.0.113.50 # Listen address&lt;br&gt;
set interfaces openvpn vtun10 local-address 192.168.34.1 # Tunnel address&lt;br&gt;
set interfaces openvpn vtun10 local-port 8000 # Port to listen on&lt;br&gt;
set interfaces openvpn vtun10 protocol udp # Can be TCP but TCP is slower&lt;br&gt;
set interfaces openvpn vtun10 remote-address 192.168.34.2 # Tunnel peer address&lt;br&gt;
set interfaces openvpn vtun10 shared-secret-key-file /config/auth/mysite.key # The file you generated
&lt;/pre&gt; 
 &lt;p&gt;Remote (connecting) side:&lt;/p&gt; 
 &lt;pre&gt;set interfaces openvpn vtun10 mode site-to-site&lt;br&gt;
set interfaces openvpn vtun10 remote-host 203.0.113.50 # Remote router external address&lt;br&gt;
set interfaces openvpn vtun10 local-address 192.168.34.2 # Tunnel address, don't forget to local/remote addresses for the remote side!&lt;br&gt;
set interfaces openvpn vtun10 remote-port 8000 # Port to connect on&lt;br&gt;
set interfaces openvpn vtun10 protocol udp # Can be TCP but TCP is slower&lt;br&gt;
set interfaces openvpn vtun10 remote-address 192.168.34.1&lt;br&gt;
set interfaces openvpn vtun10 shared-secret-key-file /config/auth/mysite.key
&lt;/pre&gt; 
 &lt;p&gt;As you can see, with less than 10 commands on each side, you can get a tunnel working.&lt;/p&gt; 
 &lt;h3&gt;What about x.509?&lt;/h3&gt; 
 &lt;p&gt;It is doable, though I'm not sure if it's really worth the trouble for site to site tunnels.&lt;/p&gt; 
 &lt;p&gt;This is how it's done. Local (listening) side:&lt;/p&gt; 
 &lt;pre&gt;set interfaces openvpn vtun10 tls role passive&lt;br&gt;
set interfaces openvpn vtun10 tls dh-file /config/auth/dh2048.pem&lt;br&gt;
set interfaces openvpn vtun10 tls ca-cert-file /config/auth/ca.crt&lt;br&gt;
set interfaces openvpn vtun10 tls cert-file /config/auth/local.crt&lt;br&gt;
set interfaces openvpn vtun10 tls key-file /config/auth/local.key
&lt;/pre&gt; 
 &lt;p&gt;Remote (connecting) side:&lt;/p&gt; 
 &lt;pre&gt;set interfaces openvpn vtun10 tls role active&lt;br&gt;
set interfaces openvpn vtun10 tls ca-cert-file /config/auth/ca.crt&lt;br&gt;
set interfaces openvpn vtun10 tls cert-file /config/auth/remote.crt&lt;br&gt;
set interfaces openvpn vtun10 tls key-file /config/auth/remote.key
&lt;/pre&gt; 
 &lt;h3&gt;Routing&lt;/h3&gt; 
 &lt;p&gt;Since OpenVPN tunnels look like normal network interfaces, you can setup routing right away as if they were physical links. You can also use push-route commands through custom options (as in, openvpn-option "push ..."). Note that OpenVPN in site to site mode doesn't install any routes by default so you need to take care of it yourself.&lt;br&gt;&lt;/p&gt; 
&lt;/div&gt;</description>
      <content:encoded>&lt;div class="posthaven-post-body"&gt; 
 &lt;p&gt;I've written a long series of post about setting up IPsec VPNs between NATed machines. As you've already seen, with some creative configuration it's possible, but is it always worth the sacrifice? Sometimes performance requirements, or lack of support for anything else on the other side make it necessary, but if the other side is also a VyOS, or another open source system, there's an alternative.&lt;/p&gt; 
 &lt;p&gt;While OpenVPN is usually associated with road warrior VPN setups, it is not limited to it. It does have a site to site option and it's very quick and easy to setup. For some strange reason, that option is neglected by just about everyone who otherwise supports OpenVPN: in OpenWRT it's possible to setup through custom config options, while in Mikrotik RouterOS it's not possible to setup at all. In VyOS we have an explicit option for it. OPNsense also supports site to site OpenVPN out of the box (I thought it doesn't, but the authors corrected me).&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;The advantages are that it takes very few commands to get a tunnel to work, and that it will work in any network where you can forward a single port, even is both sides are behind double NAT. The downside is performance: squeezing even 100mbit/s of encrypted traffic out of it can be impossible, typical iperf figures are 10-20 mbit/s. For many use cases that performance is more than enough, though if you plan to use the tunnel for storage replication or another high-traffic job, that option is definitely not for you and you'll have to resort to IPsec.&lt;/p&gt; 
 &lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;br&gt; &lt;/p&gt; 
 &lt;h2&gt;Setting up site to site OpenVPN&lt;/h2&gt; 
 &lt;h3&gt;Generating a key&lt;/h3&gt; 
 &lt;p&gt;OpenVPN in site to site mode supports either static pre-shared keys or x.509. For a quick tunnel setup between your own routers, the format option is a lot easier and arguably not less secure. Unlike most IPsec implementations, OpenVPN stores pre-shared keys in files, and uses keys of considerable length (default is 2038. It takes just one command to generate a suitable key:&lt;/p&gt; 
 &lt;pre&gt;run generate openvpn key /config/auth/mysite.key
&lt;/pre&gt; 
 &lt;p&gt;Then you can copy the file to the remote side via SCP or something else. That command is a wrapper for "openvpn --genkey --secret" in case you want to generate a key outside VyOS. It's a good idea to store the keys in /config/auth directory that was specifically meant for authentication data, since /config will be migrated to the new image when you upgrade your system — if you put them in /etc, they will be inaccessible from the upgraded image.&lt;/p&gt; 
 &lt;h3&gt;Setting up the tunnel&lt;/h3&gt; 
 &lt;p&gt;It's quite straightforward. &lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;Local (listening) side:&lt;/p&gt; 
 &lt;pre&gt;set interfaces openvpn vtun10 mode site-to-site&lt;br&gt;
set interfaces openvpn vtun10 description 'My remote site'&lt;br&gt;
set interfaces openvpn vtun10 local-host 203.0.113.50 # Listen address&lt;br&gt;
set interfaces openvpn vtun10 local-address 192.168.34.1 # Tunnel address&lt;br&gt;
set interfaces openvpn vtun10 local-port 8000 # Port to listen on&lt;br&gt;
set interfaces openvpn vtun10 protocol udp # Can be TCP but TCP is slower&lt;br&gt;
set interfaces openvpn vtun10 remote-address 192.168.34.2 # Tunnel peer address&lt;br&gt;
set interfaces openvpn vtun10 shared-secret-key-file /config/auth/mysite.key # The file you generated
&lt;/pre&gt; 
 &lt;p&gt;Remote (connecting) side:&lt;/p&gt; 
 &lt;pre&gt;set interfaces openvpn vtun10 mode site-to-site&lt;br&gt;
set interfaces openvpn vtun10 remote-host 203.0.113.50 # Remote router external address&lt;br&gt;
set interfaces openvpn vtun10 local-address 192.168.34.2 # Tunnel address, don't forget to local/remote addresses for the remote side!&lt;br&gt;
set interfaces openvpn vtun10 remote-port 8000 # Port to connect on&lt;br&gt;
set interfaces openvpn vtun10 protocol udp # Can be TCP but TCP is slower&lt;br&gt;
set interfaces openvpn vtun10 remote-address 192.168.34.1&lt;br&gt;
set interfaces openvpn vtun10 shared-secret-key-file /config/auth/mysite.key
&lt;/pre&gt; 
 &lt;p&gt;As you can see, with less than 10 commands on each side, you can get a tunnel working.&lt;/p&gt; 
 &lt;h3&gt;What about x.509?&lt;/h3&gt; 
 &lt;p&gt;It is doable, though I'm not sure if it's really worth the trouble for site to site tunnels.&lt;/p&gt; 
 &lt;p&gt;This is how it's done. Local (listening) side:&lt;/p&gt; 
 &lt;pre&gt;set interfaces openvpn vtun10 tls role passive&lt;br&gt;
set interfaces openvpn vtun10 tls dh-file /config/auth/dh2048.pem&lt;br&gt;
set interfaces openvpn vtun10 tls ca-cert-file /config/auth/ca.crt&lt;br&gt;
set interfaces openvpn vtun10 tls cert-file /config/auth/local.crt&lt;br&gt;
set interfaces openvpn vtun10 tls key-file /config/auth/local.key
&lt;/pre&gt; 
 &lt;p&gt;Remote (connecting) side:&lt;/p&gt; 
 &lt;pre&gt;set interfaces openvpn vtun10 tls role active&lt;br&gt;
set interfaces openvpn vtun10 tls ca-cert-file /config/auth/ca.crt&lt;br&gt;
set interfaces openvpn vtun10 tls cert-file /config/auth/remote.crt&lt;br&gt;
set interfaces openvpn vtun10 tls key-file /config/auth/remote.key
&lt;/pre&gt; 
 &lt;h3&gt;Routing&lt;/h3&gt; 
 &lt;p&gt;Since OpenVPN tunnels look like normal network interfaces, you can setup routing right away as if they were physical links. You can also use push-route commands through custom options (as in, openvpn-option "push ..."). Note that OpenVPN in site to site mode doesn't install any routes by default so you need to take care of it yourself.&lt;br&gt;&lt;/p&gt; 
&lt;/div&gt;  
&lt;img src="https://track.hubspot.com/__ptq.gif?a=4129050&amp;amp;k=14&amp;amp;r=https%3A%2F%2Fblog.vyos.io%2Ftake-a-third-option-site-to-site-openvpn&amp;amp;bu=https%253A%252F%252Fblog.vyos.io&amp;amp;bvt=rss" alt="" width="1" height="1" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important; "&gt;</content:encoded>
      <category>openvpn</category>
      <category>tutorial</category>
      <category>Uncategorized</category>
      <category>vpn</category>
      <pubDate>Fri, 30 Mar 2018 10:38:22 GMT</pubDate>
      <author>daniil@sentrium.io (Daniil Baturin)</author>
      <guid>https://blog.vyos.io/take-a-third-option-site-to-site-openvpn</guid>
      <dc:date>2018-03-30T10:38:22Z</dc:date>
    </item>
    <item>
      <title>Interaction between IPsec and NAT (on the same router)</title>
      <link>https://blog.vyos.io/interaction-between-ipsec-and-nat-on-the-same-router</link>
      <description>&lt;div class="posthaven-post-body"&gt; 
 &lt;p&gt;I've just completed a certain unusual setup that involved NATing packets before they are sent to an IPsec tunnel, so I thought I'll write about this topic. Even in perfectly ordinary setups, the interaction between the two often catches people off guard, me included.&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;No, this is &lt;b&gt;not &lt;/b&gt;a premature Friday post. The Friday post will be a continuation of the little known featured of the VyOS CLI.&lt;/p&gt; 
 &lt;p&gt;Most routers these days have some NAT configured, so if you setup an IPsec tunnel, you need to understand the interaction between the two. Luckily, it's pretty simple.&lt;/p&gt; 
 &lt;p&gt;Every network OS has a fixed packet processing order, and for a good reason. For example, source NAT has to be performed after routing because otherwise the OS will not know which outgoing interface must be used for the packet, and will not be able to determine which SNAT rule must be applied to that packet. Likewise, destination NAT must happen before routing if we want to be able to send incoming packets to the intended host — the routing decision depends on the new destination address.&lt;/p&gt; 
 &lt;p&gt;Sometimes the order is less critical but reversing it would create inconvenience for network admins. For example, in Linux (and thus in VyOS), inbound firewall rules are processed after DNAT, so the destination address the firewall will see is the internal address, and you can easily setup a firewall that mentions private addresses on your WAN interface. If it was the other way around, then if you wanted to setup firewall rules for your private addresses, you would have to assign the firewall to the out direction of the LAN interface — not quite as logical or convenient, even if the end result is the same.&lt;/p&gt; 
 &lt;p&gt;Where's IPsec in that processing flow and what are the implications of its position in it?&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;Let's revisit the complete diagram (image by &lt;a href="http://inai.de/" title="Link: http://inai.de/"&gt;Jan Engelhardt&lt;/a&gt;, CC-BY-SA):&lt;/p&gt; 
 &lt;div class="posthaven-gallery"&gt; 
  &lt;p class="posthaven-file posthaven-file-image posthaven-file-state-processed"&gt; &lt;img class="posthaven-gallery-image" src="https://blog.vyos.io/hubfs/Imported_Blog_Media/Netfilter-packet-flow_svg-1.png"&gt; &lt;/p&gt; 
 &lt;/div&gt; 
 &lt;p&gt;If posthaven can't handle images properly, here's a direct link to the larger version: &lt;/p&gt; 
 &lt;div class="posthaven-gallery"&gt; 
  &lt;p class="posthaven-file posthaven-file-image posthaven-file-state-processed"&gt; &lt;img class="posthaven-gallery-image" src="https://blog.vyos.io/hubfs/Imported_Blog_Media/nf-packet-flow-2.png"&gt; &lt;/p&gt; 
 &lt;/div&gt; 
 &lt;p&gt; &lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;The box you are looking for is "XFRM". In Linux, IPsec is not a special component, but a part of the XFRM framework that can do encryption amond other things (it also does compression and header modification).&lt;/p&gt; 
 &lt;p&gt;From the diagram we can see that XFRM decode step (thus IPsec encryption) is &lt;b&gt;before &lt;/b&gt;DNAT (NAT prerouting), and IPsec decryption is &lt;b&gt;after &lt;/b&gt;SNAT (NAT postrouting). The implications of it are twofold: first you need to be careful when setting up SNAT and IPsec on the same machine, second, you &lt;i&gt;can &lt;/i&gt;apply NAT rules to traffic that will go to the tunnel if you really have to.&lt;/p&gt; 
 &lt;h2&gt;Avoiding adverse interaction&lt;/h2&gt; 
 &lt;p&gt;Suppose you have this config:&lt;/p&gt; 
 &lt;pre&gt;vyos@vyos# show vpn ipsec site-to-site&lt;br&gt;
 peer 192.0.2.150 {&lt;br&gt;
     [SNIP]&lt;br&gt;
     tunnel 1 {&lt;br&gt;
         local {&lt;br&gt;
             prefix 192.168.10.0/24&lt;br&gt;
         }&lt;br&gt;
         remote {&lt;br&gt;
             prefix 10.10.10.0/24&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 }
&lt;p&gt;vyos@vyos# show nat source&lt;br&gt;
 rule 10 {&lt;br&gt;
     outbound-interface eth0&lt;br&gt;
     source {&lt;br&gt;
         address 192.168.10.0/24&lt;br&gt;
     }&lt;br&gt;
     translation {&lt;br&gt;
         address 203.0.113.134&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/p&gt;&lt;/pre&gt; 
 &lt;p&gt;What will happen to a packet sent by host 192.168.10.100 to host 10.10.10.200? Since SNAT is performed before IPsec, and the 192.168.10.100 source address matches the rule 10, the rule will be applied and the packet will go down the packet processing pipeline with source address 203.0.113.134, which does not match the IPsec policy from tunnel 1. The packet will be sent out of the eth0 interface, unencrypted, and destined to be dropped by the ISP due to its private destination address (or it will be sent to a wrong host, which is not any better).&lt;/p&gt; 
 &lt;p&gt;In this case this order of packet processing seems to be a real hassle. There's a very easy workaround though: exclude packets with destination address 10.10.10.0/24 from SNAT, like this:&lt;/p&gt; 
 &lt;pre&gt;vyos@VyOS-AMI# show nat source&lt;br&gt;
rule 5 {&lt;br&gt;
    outbound-interface eth0&lt;br&gt;
    destination {&lt;br&gt;
        address 10.10.10.0/24&lt;br&gt;
    }&lt;br&gt;
    exclude&lt;br&gt;
}&lt;br&gt;
 rule 10 {&lt;br&gt;
     outbound-interface eth0&lt;br&gt;
     source {&lt;br&gt;
         address 192.168.10.0/24&lt;br&gt;
     }&lt;br&gt;
     translation {&lt;br&gt;
         address 203.0.113.134&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/pre&gt; 
 &lt;p&gt;If you've setup IPsec, the SA is up, but for some reason packets don't get through, make sure that you didn't forget to exclude traffic to the remote network from NAT. It's easy to see with tcpdump whether packets are sent the wrong way or not.&lt;/p&gt; 
 &lt;h2&gt;Exploiting the interaction&lt;/h2&gt; 
 &lt;p&gt;So far we've only seen how this particular processing order can be bad for our setup. Can it be good for anything then? Sometimes it seems like the Linux network stack was optimized to allow doing crazy things. Just a few days ago I've run into a case when this turned beneficial.&lt;/p&gt; 
 &lt;p&gt;Suppose you setup an IPsec tunnel to your partner, and it turns out you both are using 192.168.10.0/24 subnet internally. None of you is willing to renumber your own network to solve the problem cleanly, but some compromise must be made. The solution is to NAT packets before they are encrypted, which works as expected precisely because IPsec happens after SNAT.&lt;/p&gt; 
 &lt;p&gt;For simplicity let's assume only a single host from our network (internal address 192.168.10.45) needs to interact with a single host from the remote network (10.10.10.55). We will make up an intermediate 172.16.17.45 address and NAT the tunnel traffic to and from 10.10.10.55 host to actually be sent to the 192.168.10.45 host.&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;The config looks like this:&lt;/p&gt; 
 &lt;pre&gt;vyos@vyos# show vpn ipsec site-to-site&lt;br&gt;
 peer 192.0.2.150 {&lt;br&gt;
     [SNIP]&lt;br&gt;
     tunnel 1 {&lt;br&gt;
         local {&lt;br&gt;
             prefix 172.16.17.45/32&lt;br&gt;
         }&lt;br&gt;
         remote {&lt;br&gt;
             prefix 10.10.10.55/32&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 }
&lt;p&gt;vyos@vyos# show nat source&lt;br&gt;
 rule 10 {&lt;br&gt;
     outbound-interface any&lt;br&gt;     destination {&lt;br&gt;         address 10.10.10.55&lt;br&gt;     }&lt;br&gt;    &amp;nbsp;source {&lt;br&gt;
         address 192.168.10.45&lt;br&gt;
     }&lt;br&gt;    &amp;nbsp;translation {&lt;br&gt;
         address 172.16.17.45&lt;br&gt;
     }&lt;br&gt;
 }&lt;/p&gt;
&lt;p&gt;vyos@vyos# show nat destination&lt;br&gt;
 rule 10 {&lt;br&gt;
     destination {&lt;br&gt;
         address 172.16.17.45&lt;br&gt;
     }&lt;br&gt;
     inbound-interface any&lt;br&gt;
     translation {&lt;br&gt;
         address 192.168.10.45&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/p&gt;&lt;/pre&gt; 
 &lt;p&gt;If IPsec was performed before source NAT, this kind of setup would be impossible.&lt;br&gt;&lt;/p&gt; 
&lt;/div&gt;</description>
      <content:encoded>&lt;div class="posthaven-post-body"&gt; 
 &lt;p&gt;I've just completed a certain unusual setup that involved NATing packets before they are sent to an IPsec tunnel, so I thought I'll write about this topic. Even in perfectly ordinary setups, the interaction between the two often catches people off guard, me included.&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;No, this is &lt;b&gt;not &lt;/b&gt;a premature Friday post. The Friday post will be a continuation of the little known featured of the VyOS CLI.&lt;/p&gt; 
 &lt;p&gt;Most routers these days have some NAT configured, so if you setup an IPsec tunnel, you need to understand the interaction between the two. Luckily, it's pretty simple.&lt;/p&gt; 
 &lt;p&gt;Every network OS has a fixed packet processing order, and for a good reason. For example, source NAT has to be performed after routing because otherwise the OS will not know which outgoing interface must be used for the packet, and will not be able to determine which SNAT rule must be applied to that packet. Likewise, destination NAT must happen before routing if we want to be able to send incoming packets to the intended host — the routing decision depends on the new destination address.&lt;/p&gt; 
 &lt;p&gt;Sometimes the order is less critical but reversing it would create inconvenience for network admins. For example, in Linux (and thus in VyOS), inbound firewall rules are processed after DNAT, so the destination address the firewall will see is the internal address, and you can easily setup a firewall that mentions private addresses on your WAN interface. If it was the other way around, then if you wanted to setup firewall rules for your private addresses, you would have to assign the firewall to the out direction of the LAN interface — not quite as logical or convenient, even if the end result is the same.&lt;/p&gt; 
 &lt;p&gt;Where's IPsec in that processing flow and what are the implications of its position in it?&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;Let's revisit the complete diagram (image by &lt;a href="http://inai.de/" title="Link: http://inai.de/"&gt;Jan Engelhardt&lt;/a&gt;, CC-BY-SA):&lt;/p&gt; 
 &lt;div class="posthaven-gallery"&gt; 
  &lt;p class="posthaven-file posthaven-file-image posthaven-file-state-processed"&gt; &lt;img class="posthaven-gallery-image" src="https://blog.vyos.io/hubfs/Imported_Blog_Media/Netfilter-packet-flow_svg-1.png"&gt; &lt;/p&gt; 
 &lt;/div&gt; 
 &lt;p&gt;If posthaven can't handle images properly, here's a direct link to the larger version: &lt;/p&gt; 
 &lt;div class="posthaven-gallery"&gt; 
  &lt;p class="posthaven-file posthaven-file-image posthaven-file-state-processed"&gt; &lt;img class="posthaven-gallery-image" src="https://blog.vyos.io/hubfs/Imported_Blog_Media/nf-packet-flow-2.png"&gt; &lt;/p&gt; 
 &lt;/div&gt; 
 &lt;p&gt; &lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;The box you are looking for is "XFRM". In Linux, IPsec is not a special component, but a part of the XFRM framework that can do encryption amond other things (it also does compression and header modification).&lt;/p&gt; 
 &lt;p&gt;From the diagram we can see that XFRM decode step (thus IPsec encryption) is &lt;b&gt;before &lt;/b&gt;DNAT (NAT prerouting), and IPsec decryption is &lt;b&gt;after &lt;/b&gt;SNAT (NAT postrouting). The implications of it are twofold: first you need to be careful when setting up SNAT and IPsec on the same machine, second, you &lt;i&gt;can &lt;/i&gt;apply NAT rules to traffic that will go to the tunnel if you really have to.&lt;/p&gt; 
 &lt;h2&gt;Avoiding adverse interaction&lt;/h2&gt; 
 &lt;p&gt;Suppose you have this config:&lt;/p&gt; 
 &lt;pre&gt;vyos@vyos# show vpn ipsec site-to-site&lt;br&gt;
 peer 192.0.2.150 {&lt;br&gt;
     [SNIP]&lt;br&gt;
     tunnel 1 {&lt;br&gt;
         local {&lt;br&gt;
             prefix 192.168.10.0/24&lt;br&gt;
         }&lt;br&gt;
         remote {&lt;br&gt;
             prefix 10.10.10.0/24&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 }
&lt;p&gt;vyos@vyos# show nat source&lt;br&gt;
 rule 10 {&lt;br&gt;
     outbound-interface eth0&lt;br&gt;
     source {&lt;br&gt;
         address 192.168.10.0/24&lt;br&gt;
     }&lt;br&gt;
     translation {&lt;br&gt;
         address 203.0.113.134&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/p&gt;&lt;/pre&gt; 
 &lt;p&gt;What will happen to a packet sent by host 192.168.10.100 to host 10.10.10.200? Since SNAT is performed before IPsec, and the 192.168.10.100 source address matches the rule 10, the rule will be applied and the packet will go down the packet processing pipeline with source address 203.0.113.134, which does not match the IPsec policy from tunnel 1. The packet will be sent out of the eth0 interface, unencrypted, and destined to be dropped by the ISP due to its private destination address (or it will be sent to a wrong host, which is not any better).&lt;/p&gt; 
 &lt;p&gt;In this case this order of packet processing seems to be a real hassle. There's a very easy workaround though: exclude packets with destination address 10.10.10.0/24 from SNAT, like this:&lt;/p&gt; 
 &lt;pre&gt;vyos@VyOS-AMI# show nat source&lt;br&gt;
rule 5 {&lt;br&gt;
    outbound-interface eth0&lt;br&gt;
    destination {&lt;br&gt;
        address 10.10.10.0/24&lt;br&gt;
    }&lt;br&gt;
    exclude&lt;br&gt;
}&lt;br&gt;
 rule 10 {&lt;br&gt;
     outbound-interface eth0&lt;br&gt;
     source {&lt;br&gt;
         address 192.168.10.0/24&lt;br&gt;
     }&lt;br&gt;
     translation {&lt;br&gt;
         address 203.0.113.134&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/pre&gt; 
 &lt;p&gt;If you've setup IPsec, the SA is up, but for some reason packets don't get through, make sure that you didn't forget to exclude traffic to the remote network from NAT. It's easy to see with tcpdump whether packets are sent the wrong way or not.&lt;/p&gt; 
 &lt;h2&gt;Exploiting the interaction&lt;/h2&gt; 
 &lt;p&gt;So far we've only seen how this particular processing order can be bad for our setup. Can it be good for anything then? Sometimes it seems like the Linux network stack was optimized to allow doing crazy things. Just a few days ago I've run into a case when this turned beneficial.&lt;/p&gt; 
 &lt;p&gt;Suppose you setup an IPsec tunnel to your partner, and it turns out you both are using 192.168.10.0/24 subnet internally. None of you is willing to renumber your own network to solve the problem cleanly, but some compromise must be made. The solution is to NAT packets before they are encrypted, which works as expected precisely because IPsec happens after SNAT.&lt;/p&gt; 
 &lt;p&gt;For simplicity let's assume only a single host from our network (internal address 192.168.10.45) needs to interact with a single host from the remote network (10.10.10.55). We will make up an intermediate 172.16.17.45 address and NAT the tunnel traffic to and from 10.10.10.55 host to actually be sent to the 192.168.10.45 host.&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;The config looks like this:&lt;/p&gt; 
 &lt;pre&gt;vyos@vyos# show vpn ipsec site-to-site&lt;br&gt;
 peer 192.0.2.150 {&lt;br&gt;
     [SNIP]&lt;br&gt;
     tunnel 1 {&lt;br&gt;
         local {&lt;br&gt;
             prefix 172.16.17.45/32&lt;br&gt;
         }&lt;br&gt;
         remote {&lt;br&gt;
             prefix 10.10.10.55/32&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 }
&lt;p&gt;vyos@vyos# show nat source&lt;br&gt;
 rule 10 {&lt;br&gt;
     outbound-interface any&lt;br&gt;     destination {&lt;br&gt;         address 10.10.10.55&lt;br&gt;     }&lt;br&gt;    &amp;nbsp;source {&lt;br&gt;
         address 192.168.10.45&lt;br&gt;
     }&lt;br&gt;    &amp;nbsp;translation {&lt;br&gt;
         address 172.16.17.45&lt;br&gt;
     }&lt;br&gt;
 }&lt;/p&gt;
&lt;p&gt;vyos@vyos# show nat destination&lt;br&gt;
 rule 10 {&lt;br&gt;
     destination {&lt;br&gt;
         address 172.16.17.45&lt;br&gt;
     }&lt;br&gt;
     inbound-interface any&lt;br&gt;
     translation {&lt;br&gt;
         address 192.168.10.45&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/p&gt;&lt;/pre&gt; 
 &lt;p&gt;If IPsec was performed before source NAT, this kind of setup would be impossible.&lt;br&gt;&lt;/p&gt; 
&lt;/div&gt;  
&lt;img src="https://track.hubspot.com/__ptq.gif?a=4129050&amp;amp;k=14&amp;amp;r=https%3A%2F%2Fblog.vyos.io%2Finteraction-between-ipsec-and-nat-on-the-same-router&amp;amp;bu=https%253A%252F%252Fblog.vyos.io&amp;amp;bvt=rss" alt="" width="1" height="1" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important; "&gt;</content:encoded>
      <category>ipsec</category>
      <category>nat</category>
      <category>tutorial</category>
      <category>Uncategorized</category>
      <category>vpn</category>
      <pubDate>Thu, 01 Feb 2018 06:01:49 GMT</pubDate>
      <author>daniil@sentrium.io (Daniil Baturin)</author>
      <guid>https://blog.vyos.io/interaction-between-ipsec-and-nat-on-the-same-router</guid>
      <dc:date>2018-02-01T06:01:49Z</dc:date>
    </item>
    <item>
      <title>Setting up GRE/IPsec behind NAT</title>
      <link>https://blog.vyos.io/setting-up-gre-slash-ipsec-behind-nat</link>
      <description>&lt;div class="posthaven-post-body"&gt; 
 &lt;p&gt;In the previous posts of this series we've discussed setting up "plain" IPsec tunnels from behind NAT. &lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;The transparency of the plain IPsec, however, is more often a curse than a blessing. Truly transparent IPsec is only possible between publicly routed networks, and the tunnel mode creates a strange mix of the two approaches: you do not have a network interface associated with the tunnel, but the setup is not free of routing issues either, and it's often hard to test whether the tunnel actually works or not from the router itself.&lt;/p&gt; 
 &lt;p&gt;GRE/IPsec (or IPIP/IPsec, or anything else) offers a convenient solution: for all intents and purposes it's a normal network interface and makes it look like the networks are connected with a wire. You can easily ping the other side, use the interface for firewall and QoS rulesets, and setup dynamic routing protocols in a straightforward way. However, NAT creates a unique challenge for this setup.&lt;/p&gt; 
 &lt;p&gt;The canonical and the simplest GRE/IPsec setup looks like this:&lt;/p&gt; 
 &lt;pre&gt;interfaces {&lt;br&gt;
  tunnel tun0 {&lt;br&gt;
    address 10.0.0.2/29&lt;br&gt;
    local-ip 192.0.2.10&lt;br&gt;
    remote-ip 203.0.113.20&lt;br&gt;
    encapsulation gre&lt;br&gt;
  }&lt;br&gt;
}&lt;br&gt;
vpn {&lt;br&gt;
  ipsec {&lt;br&gt;
    site-to-site {&lt;br&gt;
      peer 203.0.113.20 {&lt;br&gt;
        tunnel 1 {&lt;br&gt;
          protocol gre&lt;br&gt;
        }&lt;br&gt;
        local-address 192.0.2.10
&lt;/pre&gt; 
 &lt;p&gt;It creates a policy that encrypts any GRE packets sent to 203.0.113.20. Of course it's not going to work with NAT because the remote side is not directly routable. &lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;Let's see how we can get around it. Suppose you are setting up a tunnel between routers called East and West. The way to get around it is pretty simple even if not exactly intuitive and boils down to this:&lt;/p&gt; 
 &lt;ol&gt; 
  &lt;li&gt;Setup an additional address on a loopback or dummy interface on each router, e.g. 10.10.0.1/32 on the East and 10.10.0.2/32 on the West.&lt;/li&gt; 
  &lt;li&gt;Setup GRE tunnels that are using 10.10.0.1 and .2 as local-ip and remote-ip respectively.&lt;/li&gt; 
  &lt;li&gt;Setup an IPsec tunnels that uses 10.10.0.1 and .2 as local-prefix and remote-prefix respectively.&lt;/li&gt; 
 &lt;/ol&gt; 
 &lt;p&gt;This way when traffic is sent through the GRE tunnel on the East, the GRE packets will use 10.10.0.1 as a source address, which will match the IPsec policy. Since 10.10.0.2/32 is specified as the remote-prefix of the tunnel, the IPsec process will setup a kernel route to it, and the GRE packets will reach the other side.&lt;/p&gt; 
 &lt;p&gt;Let's look at the config:&lt;/p&gt; 
 &lt;pre&gt;interfaces {&lt;br&gt;
  dummy dum0 {&lt;br&gt;
    address 10.10.0.1/32&lt;br&gt;
  }&lt;br&gt;
  tunnel tun0 {&lt;br&gt;
    address 10.0.0.1/29&lt;br&gt;
    local-ip 10.10.0.1&lt;br&gt;
    remote-ip 10.10.0.2&lt;br&gt;
    encapsulation gre&lt;br&gt;
  }&lt;br&gt;
}&lt;br&gt;
vpn {&lt;br&gt;
  ipsec {&lt;br&gt;
    site-to-site {&lt;br&gt;
      peer @west {&lt;br&gt;
        connection-type respond&lt;br&gt;
        tunnel 1 {&lt;br&gt;
          local {&lt;br&gt;
            prefix 10.10.0.1/32&lt;br&gt;
          }&lt;br&gt;
          remote {&lt;br&gt;
            prefix 10.10.0.2/32&lt;br&gt;
          }
&lt;/pre&gt; 
 &lt;p&gt;This approach also has a property that may make it useful even in publicly routed networks if you are going to use the GRE tunnel for sensitive but unencrypted traffic (I've seen that in legacy applications): unlike the canonical setup, GRE tunnel stops working when the IPsec SA goes down because the remote end becomes unreachable. The canonical setup will continue to work even without IPsec and may expose the GRE traffic to eavesdropping and MitM attacks.&lt;/p&gt; 
 &lt;p&gt;This concludes the series of posts about IPsec and NAT. Next Friday I'll find something else to write about. ;)&lt;br&gt;&lt;/p&gt; 
&lt;/div&gt;</description>
      <content:encoded>&lt;div class="posthaven-post-body"&gt; 
 &lt;p&gt;In the previous posts of this series we've discussed setting up "plain" IPsec tunnels from behind NAT. &lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;The transparency of the plain IPsec, however, is more often a curse than a blessing. Truly transparent IPsec is only possible between publicly routed networks, and the tunnel mode creates a strange mix of the two approaches: you do not have a network interface associated with the tunnel, but the setup is not free of routing issues either, and it's often hard to test whether the tunnel actually works or not from the router itself.&lt;/p&gt; 
 &lt;p&gt;GRE/IPsec (or IPIP/IPsec, or anything else) offers a convenient solution: for all intents and purposes it's a normal network interface and makes it look like the networks are connected with a wire. You can easily ping the other side, use the interface for firewall and QoS rulesets, and setup dynamic routing protocols in a straightforward way. However, NAT creates a unique challenge for this setup.&lt;/p&gt; 
 &lt;p&gt;The canonical and the simplest GRE/IPsec setup looks like this:&lt;/p&gt; 
 &lt;pre&gt;interfaces {&lt;br&gt;
  tunnel tun0 {&lt;br&gt;
    address 10.0.0.2/29&lt;br&gt;
    local-ip 192.0.2.10&lt;br&gt;
    remote-ip 203.0.113.20&lt;br&gt;
    encapsulation gre&lt;br&gt;
  }&lt;br&gt;
}&lt;br&gt;
vpn {&lt;br&gt;
  ipsec {&lt;br&gt;
    site-to-site {&lt;br&gt;
      peer 203.0.113.20 {&lt;br&gt;
        tunnel 1 {&lt;br&gt;
          protocol gre&lt;br&gt;
        }&lt;br&gt;
        local-address 192.0.2.10
&lt;/pre&gt; 
 &lt;p&gt;It creates a policy that encrypts any GRE packets sent to 203.0.113.20. Of course it's not going to work with NAT because the remote side is not directly routable. &lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;Let's see how we can get around it. Suppose you are setting up a tunnel between routers called East and West. The way to get around it is pretty simple even if not exactly intuitive and boils down to this:&lt;/p&gt; 
 &lt;ol&gt; 
  &lt;li&gt;Setup an additional address on a loopback or dummy interface on each router, e.g. 10.10.0.1/32 on the East and 10.10.0.2/32 on the West.&lt;/li&gt; 
  &lt;li&gt;Setup GRE tunnels that are using 10.10.0.1 and .2 as local-ip and remote-ip respectively.&lt;/li&gt; 
  &lt;li&gt;Setup an IPsec tunnels that uses 10.10.0.1 and .2 as local-prefix and remote-prefix respectively.&lt;/li&gt; 
 &lt;/ol&gt; 
 &lt;p&gt;This way when traffic is sent through the GRE tunnel on the East, the GRE packets will use 10.10.0.1 as a source address, which will match the IPsec policy. Since 10.10.0.2/32 is specified as the remote-prefix of the tunnel, the IPsec process will setup a kernel route to it, and the GRE packets will reach the other side.&lt;/p&gt; 
 &lt;p&gt;Let's look at the config:&lt;/p&gt; 
 &lt;pre&gt;interfaces {&lt;br&gt;
  dummy dum0 {&lt;br&gt;
    address 10.10.0.1/32&lt;br&gt;
  }&lt;br&gt;
  tunnel tun0 {&lt;br&gt;
    address 10.0.0.1/29&lt;br&gt;
    local-ip 10.10.0.1&lt;br&gt;
    remote-ip 10.10.0.2&lt;br&gt;
    encapsulation gre&lt;br&gt;
  }&lt;br&gt;
}&lt;br&gt;
vpn {&lt;br&gt;
  ipsec {&lt;br&gt;
    site-to-site {&lt;br&gt;
      peer @west {&lt;br&gt;
        connection-type respond&lt;br&gt;
        tunnel 1 {&lt;br&gt;
          local {&lt;br&gt;
            prefix 10.10.0.1/32&lt;br&gt;
          }&lt;br&gt;
          remote {&lt;br&gt;
            prefix 10.10.0.2/32&lt;br&gt;
          }
&lt;/pre&gt; 
 &lt;p&gt;This approach also has a property that may make it useful even in publicly routed networks if you are going to use the GRE tunnel for sensitive but unencrypted traffic (I've seen that in legacy applications): unlike the canonical setup, GRE tunnel stops working when the IPsec SA goes down because the remote end becomes unreachable. The canonical setup will continue to work even without IPsec and may expose the GRE traffic to eavesdropping and MitM attacks.&lt;/p&gt; 
 &lt;p&gt;This concludes the series of posts about IPsec and NAT. Next Friday I'll find something else to write about. ;)&lt;br&gt;&lt;/p&gt; 
&lt;/div&gt;  
&lt;img src="https://track.hubspot.com/__ptq.gif?a=4129050&amp;amp;k=14&amp;amp;r=https%3A%2F%2Fblog.vyos.io%2Fsetting-up-gre-slash-ipsec-behind-nat&amp;amp;bu=https%253A%252F%252Fblog.vyos.io&amp;amp;bvt=rss" alt="" width="1" height="1" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important; "&gt;</content:encoded>
      <category>gre</category>
      <category>ipsec</category>
      <category>nat</category>
      <category>tutorial</category>
      <category>Uncategorized</category>
      <category>vpn</category>
      <pubDate>Fri, 19 Jan 2018 15:00:55 GMT</pubDate>
      <author>daniil@sentrium.io (Daniil Baturin)</author>
      <guid>https://blog.vyos.io/setting-up-gre-slash-ipsec-behind-nat</guid>
      <dc:date>2018-01-19T15:00:55Z</dc:date>
    </item>
    <item>
      <title>How to setup an IPsec connection between two NATed peers: using id's and RSA keys</title>
      <link>https://blog.vyos.io/how-to-setup-an-ipsec-connection-between-two-nated-peers-using-ids-and-rsa-keys</link>
      <description>&lt;div class="posthaven-post-body"&gt; 
 &lt;p&gt;In the previous post from this series, we've discussed setting up an IPsec tunnel from a NATed router to a non-NATed one. The key point is that in the presence of NAT, the non-NATed side cannot identify the NATed peer by its public address, so a manually configured id is required.&lt;/p&gt; 
 &lt;p&gt;What if both peers are NATed though? Suppose you are setting up a tunnel between two EC2 instances. They are both NATed, and this creates its own unique challenges: neither of them know their public addresses or can identify their peers by their public address. So, we need to solve two problems.&lt;/p&gt; 
 &lt;p&gt;In this post, we'll setup a tunnel between two routers, let's call them "east" and "west". The "east" router will be the initiator, and "west" will be the responder.&lt;/p&gt; 
 &lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;br&gt; &lt;/p&gt; 
 &lt;h3&gt;A note on pre-shared keys&lt;/h3&gt; 
 &lt;p&gt;While there are many issues with PSKs that public key cryptography solves in an elegant way, such as the problem of exchanging them securely, there's also a specific pitfall associated with them in VyOS: if the local-address of the peer is set to 'any' and the peer is identified by an id rather than public address, it won't allow you to use a pre-shared key for that peer. I have to admit I don't remember if this is a fundamental issue or an implementation detail, and perhaps we can lift this limitation at some point, but as of 1.1.8 and the current builds of 1.2.0, you have to use RSA keys or x.509 for authentication in this kind of setup.&lt;/p&gt; 
 &lt;h3&gt;Setting up RSA keys&lt;/h3&gt; 
 &lt;p&gt;We will not touch x.509 just yet and will focus on "certless" RSA keys in this post. They are very fast and easy to setup. The only real disadvantage is that some IPsec implementation do not support them and require either pre-shared keys or x.509 certificates, but in our example both sides are running VyOS and this is not an issue.&lt;/p&gt; 
 &lt;p&gt;To generate an RSA key, use this command: "run generate vpn rsa-key bits 2048 random /dev/urandom".&lt;/p&gt; 
 &lt;p&gt;Adjust the key length to match the size and style of your tinfoil hat. Mine looks fine with 2048, though setting it to 4096 won't harm. There is also an option to use /dev/random, but on virtual machines it can be impractical due to long blocking time, and contrary to the popular misconception, neither is /dev/random a source of "true" (information theoretically secure) random numbers, nor is &lt;a href="https://www.2uo.de/myths-about-urandom/"&gt;/dev/urandom always inherently insecure&lt;/a&gt;. Let's generate a key on the West router.&lt;br&gt;&lt;/p&gt; 
 &lt;pre&gt;vyos@west# run generate vpn rsa-key bits 2048 random /dev/urandom&lt;br&gt;
Generating rsa-key to /config/ipsec.d/rsa-keys/localhost.key
&lt;p&gt;Your new local RSA key has been generated&lt;br&gt;
The public portion of the key is:&lt;/p&gt;
&lt;p&gt;0sAQO8DJuyosdeE1VQnRUdsPGYFJ5gBsj4qYurjUv+/Jn5qSJJSvLYONNCDYfRDj/me5WGAtGwqmikD00oiLdCqR0FOZJTEQoEWeEh7YnOd4MEIWdeOLFRnGeETcoxGX63S7mxfol4/CVw/9n/kXRRHCnNsgYROsygZLlQIRK7hWAq3L6O1WT7Y3s7dHekXN+Ev6UbtZWQq8lejgmO0TR2ZAF3y6iBETW4Q93ARlhUva/ubBjg2oqtuX9u5UpxWTowuNycY44jm3+vjWczPtcYvvlXNt6nSGoORoHPdBeVyzU7yGIf+TcPKXTiro1JO20gwFv1dPTOLucmgEhjhuO86fFf&lt;/p&gt;
&lt;/pre&gt; 
 &lt;p&gt;Save the public key somewhere. If you clear the screen before copying it, don't worry, you can always find the public key in /config/ipsec.d/rsa-keys/localhost.key file, in its "pubkey=..." section.&lt;/p&gt; 
 &lt;p&gt;Now add the West key to the East router so that we can reference it in the IPsec settings:&lt;/p&gt; 
 &lt;p&gt;&lt;br&gt;&lt;/p&gt; 
 &lt;pre&gt;vyos@east# set vpn rsa-keys rsa-key-name east rsa-key 0sAQO8DJuyosdeE1V...
&lt;/pre&gt; 
 &lt;p&gt;Repeat the procedure on the second router.&lt;/p&gt; 
 &lt;h3&gt;IPsec setup&lt;/h3&gt; 
 &lt;p&gt;Now that both routers have each other's keys, we can setup the actual tunnel. The key points:&lt;/p&gt; 
 &lt;ol&gt; 
  &lt;li&gt;Since both routers do not know their effective public addresses, we set the local-address of the peer to "any".&lt;/li&gt; 
  &lt;li&gt;On the initiator, we set the peer address to its public address, but on the responder we only set the id.&lt;/li&gt; 
  &lt;li&gt;On the initiator, we need to set the remote-id option so that it can identify IKE traffic from the responder correctly.&lt;/li&gt; 
  &lt;li&gt;On the responder, we need to set the local id so that initiator can know who's talking to it for the point #3 to work.&lt;/li&gt; 
  &lt;li&gt;Don't forget to enable NAT traversal on both sides, "set vpn ipsec nat-traversal enable".&lt;br&gt; &lt;/li&gt; 
 &lt;/ol&gt; 
 &lt;p&gt;Let's look at the configs:&lt;/p&gt; 
 &lt;p&gt;The East side:&lt;/p&gt; 
 &lt;pre&gt;vyos@east# show vpn&lt;br&gt;
 ipsec {&lt;br&gt;
     [SNIP, IKE/ESP groups are irrelevant]&lt;br&gt;
     ipsec-interfaces {&lt;br&gt;
         interface eth0&lt;br&gt;
     }&lt;br&gt;
     nat-traversal enable&lt;br&gt;
     site-to-site {&lt;br&gt;
         peer 192.0.2.60 {&lt;br&gt;
             authentication {&lt;br&gt;
                 id @east&lt;br&gt;
                 mode rsa&lt;br&gt;
                 remote-id west&lt;br&gt;
                 rsa-key-name west&lt;br&gt;
             }&lt;br&gt;
             connection-type initiate&lt;br&gt;
             default-esp-group Foo&lt;br&gt;
             ike-group Foo&lt;br&gt;
             local-address any&lt;br&gt;
             tunnel 1 {&lt;br&gt;
                 local {&lt;br&gt;
                     prefix 10.36.63.0/24&lt;br&gt;
                 }&lt;br&gt;
                 remote {&lt;br&gt;
                     prefix 10.45.54.0/24&lt;br&gt;
                 }&lt;br&gt;
             }&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 }&lt;br&gt;
 rsa-keys {&lt;br&gt;
     rsa-key-name west {&lt;br&gt;
         rsa-key 0sAQO8DJuyosdeE1VQnRUdsPGYFJ5gBsj4qYurjUv+/Jn5qSJJSvLYONNCDYfRDj/me5WGAtGwqmikD00oiLdCqR0FOZJTEQoEWeEh7YnOd4MEIWdeOLFRnGeETcoxGX63S7mxfol4/CVw/9n/kXRRHCnNsgYROsygZLlQIRK7hWAq3L6O1WT7Y3s7dHekXN+Ev6UbtZWQq8lejgmO0TR2ZAF3y6iBETW4Q93ARlhUva/ubBjg2oqtuX9u5UpxWTowuNycY44jm3+vjWczPtcYvvlXNt6nSGoORoHPdBeVyzU7yGIf+TcPKXTiro1JO20gwFv1dPTOLucmgEhjhuO86fFf&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/pre&gt; 
 &lt;p&gt;The West side:&lt;/p&gt; 
 &lt;pre&gt;vyos@west# show vpn&lt;br&gt;
 ipsec {&lt;br&gt;
     [SNIP]&lt;br&gt;
     ipsec-interfaces {&lt;br&gt;
         interface eth0&lt;br&gt;
     }&lt;br&gt;
     nat-traversal enable&lt;br&gt;
     site-to-site {&lt;br&gt;
         peer @east {&lt;br&gt;
             authentication {&lt;br&gt;
                 id west&lt;br&gt;
                 mode rsa&lt;br&gt;
                 rsa-key-name east&lt;br&gt;
             }&lt;br&gt;
             connection-type respond&lt;br&gt;
             default-esp-group Foo&lt;br&gt;
             ike-group Foo&lt;br&gt;
             local-address any&lt;br&gt;
             tunnel 1 {&lt;br&gt;
                 local {&lt;br&gt;
                     prefix 10.45.54.0/24&lt;br&gt;
                 }&lt;br&gt;
                 remote {&lt;br&gt;
                     prefix 10.36.63.0/24&lt;br&gt;
                 }&lt;br&gt;
             }&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 }&lt;br&gt;
 rsa-keys {&lt;br&gt;
     rsa-key-name east {&lt;br&gt;
         rsa-key 0sAQO7OF/FKgx33E5I29HSy2cqLnL9hNZ6CMbR8kVRIKhqAowIAskh13+gJN2QKOvLfbjN29uy94W02tty5G7+S+xOPeMsCJyz+ofD/v5tJpqIUughngCAGEoB6uveRRfqF15sOetEgjUGPmcVU+neOJ822E2T1sYbnEVfd+vilNPFopzlY61gtWgq7m7ANe2logwSB5XWyQkgCDNi+8IqVyFhNTVbmxDyfJQ1T4/3sRgcEh5XdZhSqRIwxI7/m2jH1FfIGg0FX5+5ok0bBmRU3tMkUKMB1A4QqgXPXR5P0SMDEkfo6zkbsueAX1NEOKXO443r5aKzA1qAGKV0Zp0sriuR&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/pre&gt; 
 &lt;p&gt;Now if we look in the logs, we will see the following picture:&lt;/p&gt; 
 &lt;pre&gt;Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #1: enabling possible NAT-traversal with method 3&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #1: NAT-Traversal: Result using RFC 3947: both are NATed&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #1: we don't have a cert&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #1: Peer ID is ID_FQDN: 'west'&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #1: ISAKMP SA established&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #2: initiating Quick Mode PUBKEY+ENCRYPT+TUNNEL+PFS+UP {using isakmp#1}&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #2: sent QI2, IPsec SA established {ESP=&amp;gt;0xc9bf71e1 &amp;lt;0xc32e1a3a NATOA=0.0.0.0}
&lt;/pre&gt; 
 &lt;p&gt;This concludes the all-NATed IPsec setup.&lt;/p&gt; 
&lt;/div&gt;</description>
      <content:encoded>&lt;div class="posthaven-post-body"&gt; 
 &lt;p&gt;In the previous post from this series, we've discussed setting up an IPsec tunnel from a NATed router to a non-NATed one. The key point is that in the presence of NAT, the non-NATed side cannot identify the NATed peer by its public address, so a manually configured id is required.&lt;/p&gt; 
 &lt;p&gt;What if both peers are NATed though? Suppose you are setting up a tunnel between two EC2 instances. They are both NATed, and this creates its own unique challenges: neither of them know their public addresses or can identify their peers by their public address. So, we need to solve two problems.&lt;/p&gt; 
 &lt;p&gt;In this post, we'll setup a tunnel between two routers, let's call them "east" and "west". The "east" router will be the initiator, and "west" will be the responder.&lt;/p&gt; 
 &lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;br&gt; &lt;/p&gt; 
 &lt;h3&gt;A note on pre-shared keys&lt;/h3&gt; 
 &lt;p&gt;While there are many issues with PSKs that public key cryptography solves in an elegant way, such as the problem of exchanging them securely, there's also a specific pitfall associated with them in VyOS: if the local-address of the peer is set to 'any' and the peer is identified by an id rather than public address, it won't allow you to use a pre-shared key for that peer. I have to admit I don't remember if this is a fundamental issue or an implementation detail, and perhaps we can lift this limitation at some point, but as of 1.1.8 and the current builds of 1.2.0, you have to use RSA keys or x.509 for authentication in this kind of setup.&lt;/p&gt; 
 &lt;h3&gt;Setting up RSA keys&lt;/h3&gt; 
 &lt;p&gt;We will not touch x.509 just yet and will focus on "certless" RSA keys in this post. They are very fast and easy to setup. The only real disadvantage is that some IPsec implementation do not support them and require either pre-shared keys or x.509 certificates, but in our example both sides are running VyOS and this is not an issue.&lt;/p&gt; 
 &lt;p&gt;To generate an RSA key, use this command: "run generate vpn rsa-key bits 2048 random /dev/urandom".&lt;/p&gt; 
 &lt;p&gt;Adjust the key length to match the size and style of your tinfoil hat. Mine looks fine with 2048, though setting it to 4096 won't harm. There is also an option to use /dev/random, but on virtual machines it can be impractical due to long blocking time, and contrary to the popular misconception, neither is /dev/random a source of "true" (information theoretically secure) random numbers, nor is &lt;a href="https://www.2uo.de/myths-about-urandom/"&gt;/dev/urandom always inherently insecure&lt;/a&gt;. Let's generate a key on the West router.&lt;br&gt;&lt;/p&gt; 
 &lt;pre&gt;vyos@west# run generate vpn rsa-key bits 2048 random /dev/urandom&lt;br&gt;
Generating rsa-key to /config/ipsec.d/rsa-keys/localhost.key
&lt;p&gt;Your new local RSA key has been generated&lt;br&gt;
The public portion of the key is:&lt;/p&gt;
&lt;p&gt;0sAQO8DJuyosdeE1VQnRUdsPGYFJ5gBsj4qYurjUv+/Jn5qSJJSvLYONNCDYfRDj/me5WGAtGwqmikD00oiLdCqR0FOZJTEQoEWeEh7YnOd4MEIWdeOLFRnGeETcoxGX63S7mxfol4/CVw/9n/kXRRHCnNsgYROsygZLlQIRK7hWAq3L6O1WT7Y3s7dHekXN+Ev6UbtZWQq8lejgmO0TR2ZAF3y6iBETW4Q93ARlhUva/ubBjg2oqtuX9u5UpxWTowuNycY44jm3+vjWczPtcYvvlXNt6nSGoORoHPdBeVyzU7yGIf+TcPKXTiro1JO20gwFv1dPTOLucmgEhjhuO86fFf&lt;/p&gt;
&lt;/pre&gt; 
 &lt;p&gt;Save the public key somewhere. If you clear the screen before copying it, don't worry, you can always find the public key in /config/ipsec.d/rsa-keys/localhost.key file, in its "pubkey=..." section.&lt;/p&gt; 
 &lt;p&gt;Now add the West key to the East router so that we can reference it in the IPsec settings:&lt;/p&gt; 
 &lt;p&gt;&lt;br&gt;&lt;/p&gt; 
 &lt;pre&gt;vyos@east# set vpn rsa-keys rsa-key-name east rsa-key 0sAQO8DJuyosdeE1V...
&lt;/pre&gt; 
 &lt;p&gt;Repeat the procedure on the second router.&lt;/p&gt; 
 &lt;h3&gt;IPsec setup&lt;/h3&gt; 
 &lt;p&gt;Now that both routers have each other's keys, we can setup the actual tunnel. The key points:&lt;/p&gt; 
 &lt;ol&gt; 
  &lt;li&gt;Since both routers do not know their effective public addresses, we set the local-address of the peer to "any".&lt;/li&gt; 
  &lt;li&gt;On the initiator, we set the peer address to its public address, but on the responder we only set the id.&lt;/li&gt; 
  &lt;li&gt;On the initiator, we need to set the remote-id option so that it can identify IKE traffic from the responder correctly.&lt;/li&gt; 
  &lt;li&gt;On the responder, we need to set the local id so that initiator can know who's talking to it for the point #3 to work.&lt;/li&gt; 
  &lt;li&gt;Don't forget to enable NAT traversal on both sides, "set vpn ipsec nat-traversal enable".&lt;br&gt; &lt;/li&gt; 
 &lt;/ol&gt; 
 &lt;p&gt;Let's look at the configs:&lt;/p&gt; 
 &lt;p&gt;The East side:&lt;/p&gt; 
 &lt;pre&gt;vyos@east# show vpn&lt;br&gt;
 ipsec {&lt;br&gt;
     [SNIP, IKE/ESP groups are irrelevant]&lt;br&gt;
     ipsec-interfaces {&lt;br&gt;
         interface eth0&lt;br&gt;
     }&lt;br&gt;
     nat-traversal enable&lt;br&gt;
     site-to-site {&lt;br&gt;
         peer 192.0.2.60 {&lt;br&gt;
             authentication {&lt;br&gt;
                 id @east&lt;br&gt;
                 mode rsa&lt;br&gt;
                 remote-id west&lt;br&gt;
                 rsa-key-name west&lt;br&gt;
             }&lt;br&gt;
             connection-type initiate&lt;br&gt;
             default-esp-group Foo&lt;br&gt;
             ike-group Foo&lt;br&gt;
             local-address any&lt;br&gt;
             tunnel 1 {&lt;br&gt;
                 local {&lt;br&gt;
                     prefix 10.36.63.0/24&lt;br&gt;
                 }&lt;br&gt;
                 remote {&lt;br&gt;
                     prefix 10.45.54.0/24&lt;br&gt;
                 }&lt;br&gt;
             }&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 }&lt;br&gt;
 rsa-keys {&lt;br&gt;
     rsa-key-name west {&lt;br&gt;
         rsa-key 0sAQO8DJuyosdeE1VQnRUdsPGYFJ5gBsj4qYurjUv+/Jn5qSJJSvLYONNCDYfRDj/me5WGAtGwqmikD00oiLdCqR0FOZJTEQoEWeEh7YnOd4MEIWdeOLFRnGeETcoxGX63S7mxfol4/CVw/9n/kXRRHCnNsgYROsygZLlQIRK7hWAq3L6O1WT7Y3s7dHekXN+Ev6UbtZWQq8lejgmO0TR2ZAF3y6iBETW4Q93ARlhUva/ubBjg2oqtuX9u5UpxWTowuNycY44jm3+vjWczPtcYvvlXNt6nSGoORoHPdBeVyzU7yGIf+TcPKXTiro1JO20gwFv1dPTOLucmgEhjhuO86fFf&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/pre&gt; 
 &lt;p&gt;The West side:&lt;/p&gt; 
 &lt;pre&gt;vyos@west# show vpn&lt;br&gt;
 ipsec {&lt;br&gt;
     [SNIP]&lt;br&gt;
     ipsec-interfaces {&lt;br&gt;
         interface eth0&lt;br&gt;
     }&lt;br&gt;
     nat-traversal enable&lt;br&gt;
     site-to-site {&lt;br&gt;
         peer @east {&lt;br&gt;
             authentication {&lt;br&gt;
                 id west&lt;br&gt;
                 mode rsa&lt;br&gt;
                 rsa-key-name east&lt;br&gt;
             }&lt;br&gt;
             connection-type respond&lt;br&gt;
             default-esp-group Foo&lt;br&gt;
             ike-group Foo&lt;br&gt;
             local-address any&lt;br&gt;
             tunnel 1 {&lt;br&gt;
                 local {&lt;br&gt;
                     prefix 10.45.54.0/24&lt;br&gt;
                 }&lt;br&gt;
                 remote {&lt;br&gt;
                     prefix 10.36.63.0/24&lt;br&gt;
                 }&lt;br&gt;
             }&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 }&lt;br&gt;
 rsa-keys {&lt;br&gt;
     rsa-key-name east {&lt;br&gt;
         rsa-key 0sAQO7OF/FKgx33E5I29HSy2cqLnL9hNZ6CMbR8kVRIKhqAowIAskh13+gJN2QKOvLfbjN29uy94W02tty5G7+S+xOPeMsCJyz+ofD/v5tJpqIUughngCAGEoB6uveRRfqF15sOetEgjUGPmcVU+neOJ822E2T1sYbnEVfd+vilNPFopzlY61gtWgq7m7ANe2logwSB5XWyQkgCDNi+8IqVyFhNTVbmxDyfJQ1T4/3sRgcEh5XdZhSqRIwxI7/m2jH1FfIGg0FX5+5ok0bBmRU3tMkUKMB1A4QqgXPXR5P0SMDEkfo6zkbsueAX1NEOKXO443r5aKzA1qAGKV0Zp0sriuR&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/pre&gt; 
 &lt;p&gt;Now if we look in the logs, we will see the following picture:&lt;/p&gt; 
 &lt;pre&gt;Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #1: enabling possible NAT-traversal with method 3&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #1: NAT-Traversal: Result using RFC 3947: both are NATed&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #1: we don't have a cert&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #1: Peer ID is ID_FQDN: 'west'&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #1: ISAKMP SA established&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #2: initiating Quick Mode PUBKEY+ENCRYPT+TUNNEL+PFS+UP {using isakmp#1}&lt;br&gt;
Jan 12 06:24:23 east pluto[28278]: "peer-192.0.2.60-tunnel-1" #2: sent QI2, IPsec SA established {ESP=&amp;gt;0xc9bf71e1 &amp;lt;0xc32e1a3a NATOA=0.0.0.0}
&lt;/pre&gt; 
 &lt;p&gt;This concludes the all-NATed IPsec setup.&lt;/p&gt; 
&lt;/div&gt;  
&lt;img src="https://track.hubspot.com/__ptq.gif?a=4129050&amp;amp;k=14&amp;amp;r=https%3A%2F%2Fblog.vyos.io%2Fhow-to-setup-an-ipsec-connection-between-two-nated-peers-using-ids-and-rsa-keys&amp;amp;bu=https%253A%252F%252Fblog.vyos.io&amp;amp;bvt=rss" alt="" width="1" height="1" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important; "&gt;</content:encoded>
      <category>ipsec</category>
      <category>tutorial</category>
      <category>Uncategorized</category>
      <category>vpn</category>
      <pubDate>Fri, 12 Jan 2018 09:05:06 GMT</pubDate>
      <author>daniil@sentrium.io (Daniil Baturin)</author>
      <guid>https://blog.vyos.io/how-to-setup-an-ipsec-connection-between-two-nated-peers-using-ids-and-rsa-keys</guid>
      <dc:date>2018-01-12T09:05:06Z</dc:date>
    </item>
    <item>
      <title>Why IPsec behind 1:1 NAT is so problematic and what you can do about it</title>
      <link>https://blog.vyos.io/why-ipsec-behind-11-nat-is-so-problematic-and-what-you-can-do-about-it</link>
      <description>&lt;div class="posthaven-post-body"&gt; 
 &lt;p&gt;Not so long ago the only scenario when the issues with IPsec and NAT could arise was a remote access setup, while routers invariably had real public addresses and router to router IPsec operators were incredibly unlikely to run into those issues. A router behind NAT was seen as a pathological case.&lt;/p&gt; 
 &lt;p&gt;I believe it's still a pathological case, but as platforms such as Amazon EC2 that use one to one NAT to simplify IP address management rose in popularity and people started setting up their routers there, it became the new normal. This new reality became a constant source of confusion for beginner network admins and people who simply are not VPN specialists. Attempts to setup a VPN as if there's no NAT, with peer external IP addresses and pre-shared keys as it's commonly done, just fail to work.&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;Sometimes I'm asked why is that so, if the NAT in question is 1:1, and no other protocol just refuses to work behind it without reconfiguration. The reasons are inside the IPsec protocols themselves, and 1:1 NAT is not much better in this regard than any other kind (even though it's somewhat better than the situation when there are multiple clients behind NAT).&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;IPsec pre-dates NAT by over a decade, and was explicitly designed with end to end connectivity in mind. It was also designed as a way to add built-in security to the IP protocol stack rather than a new protocol within the stack, so it made heavy use of those underlying assumptions. That's why workarounds had to be added when the assumption of end to end connectivity became incorrect.&lt;/p&gt; 
 &lt;p&gt;Let's look into the details and then see how IPsec can be configured to work around those issues. Incidentally, the solutions are equally applicable to machines with dynamic addresses as well as those behind a 1:1 NAT, since the root cause of the issues is not knowing beforehand what your outgoing address will be next time.&lt;br&gt;&lt;/p&gt; 
 &lt;h2&gt;AH and ESP&lt;br&gt;&lt;br&gt; &lt;/h2&gt; 
 &lt;p&gt;We all (hopefully) remember that there are three criteria of information security: availability, confidentiality, and integrity. Availability (when required) in the IP is provided by reliable transmission protocols such as TCP and SCTP. IPsec was supposed to provide the other two.&lt;/p&gt; 
 &lt;p&gt;AH (Authentication Header) was designed to ensure packet integrity. For that, it calculates a hash function from the entire packet with all its headers, including source and destination addresses. Since NAT changes the addresses, it invalidates the checksum and NATed packets would be considered corrupted. So, AH is unconditionally incompatible with NAT.&lt;/p&gt; 
 &lt;p&gt;ESP only protects the payload of the packet (whether it's some protocol data, or an entire tunnelled packet), so it, luckily, can work behind NAT. The UDP encapsulation of ESP packets was introduced to allow the traffic to pass through incorrect NAT implementations that may discard non-TCP or UDP protocols, and for correct implementations this should be irrelevant (I've seen a number of SOHO routers that couldn't handle typical L2TP/IPsec connections despite that UDP encapsulation — but that's another story).&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;Before we can start sending ESP packets, we need to establish a "connection" (security association) though. In practice, most IPsec connections are negotiated via the IKE protocol rather than statically configured, and that's where IKE issues come into play.&lt;/p&gt; 
 &lt;h2&gt;IKE and pre-shared keys&lt;br&gt;&lt;br&gt; &lt;/h2&gt; 
 &lt;p&gt;To begin with, original IKE was specified to use UDP/500 for both source and destination port. Since NAT may change the source port, the specification had to be adjusted to allow other source ports. Even more issues arise when there are multiple clients behind NAT and traffic has to be multiplexed, but we'll limit the discussion to 1:1 NAT where canonical IKE might work. Let's assume the IKE exchange has gone that far.&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;The vast majority of IPsec setups in the wild use pre-shared keys. I've configured connections to vendors and partners on behalf of my employers and customers countless times, and I believe I've seen an x.509-based setup once or twice. In a setup with pre-shared keys, routers need to know which keys to use for which peers. How do they know? Suppose you've configured a tunnel with peer 192.0.2.10 and key "qwerty". The other side has 172.16.0.1 address NATed to 192.0.2.10. Will it be the source address of the peer that will be used for the key lookup? Not quite.&lt;/p&gt; 
 &lt;p&gt; In the IKE/ISAKMP exchange, there are identifiers. It's the pairs of identifiers and pre-shared keys that must be unique to reliably tell one peer from another and use correct keys for every peer. There are several types of identifiers specified by the ISAKMP protocol: IP (v4 or v6) address, subnet, FQDN, user and FQDN pair (user@example.com), and raw byte string. &lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;By default, most implementations (including StrongSWAN in VyOS) will use the IP address of the outgoing interface for the identifier, and it will be embedded in the IKE packet. If the host is behind NAT, that address is a private address, 172.16.0.1. When the packet passes through the NAT, the payload will obviously remain unchanged, and when it arrives, the responder will try to find the pair of 172.16.0.1:qwerty in its configuration rather than 192.0.2.1:qwerty that is has configured, and will send NO_PROPOSAL_CHOSEN to the NATed peer.&lt;br&gt;&lt;/p&gt; 
 &lt;h2&gt;The solutions&lt;/h2&gt; 
 &lt;p&gt;So, how do you get around those issues? Whether IKE is configured to use NAT detection or not, you'll get to use peer identification methods that do not rely on known and fixed IP addresses.&lt;/p&gt; 
 &lt;p&gt;The simplest approach is to use a manually configured peer identifier. This approach will work when one side is NATed and the other is not. The only thing you need to remember is that VyOS (right now at least) requires that FQDN identifiers are prepended with the "@" character. They also do not need to match any real domain name of your machine. You also need to set the local-address on the NATed side to "any".&lt;/p&gt; 
 &lt;p&gt;Here's an example:&lt;/p&gt; 
 &lt;h3&gt;Non-NATed side&lt;/h3&gt; 
 &lt;pre&gt;vpn {&lt;br&gt;
  ipsec {&lt;br&gt;
    site-to-site {&lt;br&gt;
       peer @foo {&lt;br&gt;
         authentication {&lt;br&gt;
             mode pre-shared-secret&lt;br&gt;
             pre-shared-secret qwerty&lt;br&gt;
         }&lt;br&gt;
         default-esp-group Foo&lt;br&gt;
         ike-group Foo&lt;br&gt;
         local-address 203.0.113.1&lt;br&gt;
         tunnel 1 {&lt;br&gt;
             local {&lt;br&gt;
                 prefix 10.103.0.0/24&lt;br&gt;
             }&lt;br&gt;
             remote {&lt;br&gt;
                 prefix 10.104.0.0/24&lt;br&gt;
             }&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 } &lt;br&gt;&lt;/pre&gt; 
 &lt;h3&gt;NATed side&lt;/h3&gt; 
 &lt;pre&gt;  ipsec {&lt;br&gt;
    site-to-site {&lt;br&gt;
         peer 203.0.113.1 {&lt;br&gt;
             authentication {&lt;br&gt;
                 id @foo&lt;br&gt;
                 mode pre-shared-secret&lt;br&gt;
                 pre-shared-secret qwerty&lt;br&gt;
             }&lt;br&gt;
             default-esp-group Foo&lt;br&gt;
             ike-group Foo&lt;br&gt;
             local-address any&lt;br&gt;
             tunnel 1 {&lt;br&gt;
                 local {&lt;br&gt;
                     prefix 10.104.0.0/24&lt;br&gt;
                 }&lt;br&gt;
                 remote {&lt;br&gt;
                     prefix 10.103.0.0/24&lt;br&gt;
                 }&lt;br&gt;
             }&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/pre&gt; 
&lt;/div&gt;</description>
      <content:encoded>&lt;div class="posthaven-post-body"&gt; 
 &lt;p&gt;Not so long ago the only scenario when the issues with IPsec and NAT could arise was a remote access setup, while routers invariably had real public addresses and router to router IPsec operators were incredibly unlikely to run into those issues. A router behind NAT was seen as a pathological case.&lt;/p&gt; 
 &lt;p&gt;I believe it's still a pathological case, but as platforms such as Amazon EC2 that use one to one NAT to simplify IP address management rose in popularity and people started setting up their routers there, it became the new normal. This new reality became a constant source of confusion for beginner network admins and people who simply are not VPN specialists. Attempts to setup a VPN as if there's no NAT, with peer external IP addresses and pre-shared keys as it's commonly done, just fail to work.&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;Sometimes I'm asked why is that so, if the NAT in question is 1:1, and no other protocol just refuses to work behind it without reconfiguration. The reasons are inside the IPsec protocols themselves, and 1:1 NAT is not much better in this regard than any other kind (even though it's somewhat better than the situation when there are multiple clients behind NAT).&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;IPsec pre-dates NAT by over a decade, and was explicitly designed with end to end connectivity in mind. It was also designed as a way to add built-in security to the IP protocol stack rather than a new protocol within the stack, so it made heavy use of those underlying assumptions. That's why workarounds had to be added when the assumption of end to end connectivity became incorrect.&lt;/p&gt; 
 &lt;p&gt;Let's look into the details and then see how IPsec can be configured to work around those issues. Incidentally, the solutions are equally applicable to machines with dynamic addresses as well as those behind a 1:1 NAT, since the root cause of the issues is not knowing beforehand what your outgoing address will be next time.&lt;br&gt;&lt;/p&gt; 
 &lt;h2&gt;AH and ESP&lt;br&gt;&lt;br&gt; &lt;/h2&gt; 
 &lt;p&gt;We all (hopefully) remember that there are three criteria of information security: availability, confidentiality, and integrity. Availability (when required) in the IP is provided by reliable transmission protocols such as TCP and SCTP. IPsec was supposed to provide the other two.&lt;/p&gt; 
 &lt;p&gt;AH (Authentication Header) was designed to ensure packet integrity. For that, it calculates a hash function from the entire packet with all its headers, including source and destination addresses. Since NAT changes the addresses, it invalidates the checksum and NATed packets would be considered corrupted. So, AH is unconditionally incompatible with NAT.&lt;/p&gt; 
 &lt;p&gt;ESP only protects the payload of the packet (whether it's some protocol data, or an entire tunnelled packet), so it, luckily, can work behind NAT. The UDP encapsulation of ESP packets was introduced to allow the traffic to pass through incorrect NAT implementations that may discard non-TCP or UDP protocols, and for correct implementations this should be irrelevant (I've seen a number of SOHO routers that couldn't handle typical L2TP/IPsec connections despite that UDP encapsulation — but that's another story).&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;Before we can start sending ESP packets, we need to establish a "connection" (security association) though. In practice, most IPsec connections are negotiated via the IKE protocol rather than statically configured, and that's where IKE issues come into play.&lt;/p&gt; 
 &lt;h2&gt;IKE and pre-shared keys&lt;br&gt;&lt;br&gt; &lt;/h2&gt; 
 &lt;p&gt;To begin with, original IKE was specified to use UDP/500 for both source and destination port. Since NAT may change the source port, the specification had to be adjusted to allow other source ports. Even more issues arise when there are multiple clients behind NAT and traffic has to be multiplexed, but we'll limit the discussion to 1:1 NAT where canonical IKE might work. Let's assume the IKE exchange has gone that far.&lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;The vast majority of IPsec setups in the wild use pre-shared keys. I've configured connections to vendors and partners on behalf of my employers and customers countless times, and I believe I've seen an x.509-based setup once or twice. In a setup with pre-shared keys, routers need to know which keys to use for which peers. How do they know? Suppose you've configured a tunnel with peer 192.0.2.10 and key "qwerty". The other side has 172.16.0.1 address NATed to 192.0.2.10. Will it be the source address of the peer that will be used for the key lookup? Not quite.&lt;/p&gt; 
 &lt;p&gt; In the IKE/ISAKMP exchange, there are identifiers. It's the pairs of identifiers and pre-shared keys that must be unique to reliably tell one peer from another and use correct keys for every peer. There are several types of identifiers specified by the ISAKMP protocol: IP (v4 or v6) address, subnet, FQDN, user and FQDN pair (user@example.com), and raw byte string. &lt;br&gt;&lt;/p&gt; 
 &lt;p&gt;By default, most implementations (including StrongSWAN in VyOS) will use the IP address of the outgoing interface for the identifier, and it will be embedded in the IKE packet. If the host is behind NAT, that address is a private address, 172.16.0.1. When the packet passes through the NAT, the payload will obviously remain unchanged, and when it arrives, the responder will try to find the pair of 172.16.0.1:qwerty in its configuration rather than 192.0.2.1:qwerty that is has configured, and will send NO_PROPOSAL_CHOSEN to the NATed peer.&lt;br&gt;&lt;/p&gt; 
 &lt;h2&gt;The solutions&lt;/h2&gt; 
 &lt;p&gt;So, how do you get around those issues? Whether IKE is configured to use NAT detection or not, you'll get to use peer identification methods that do not rely on known and fixed IP addresses.&lt;/p&gt; 
 &lt;p&gt;The simplest approach is to use a manually configured peer identifier. This approach will work when one side is NATed and the other is not. The only thing you need to remember is that VyOS (right now at least) requires that FQDN identifiers are prepended with the "@" character. They also do not need to match any real domain name of your machine. You also need to set the local-address on the NATed side to "any".&lt;/p&gt; 
 &lt;p&gt;Here's an example:&lt;/p&gt; 
 &lt;h3&gt;Non-NATed side&lt;/h3&gt; 
 &lt;pre&gt;vpn {&lt;br&gt;
  ipsec {&lt;br&gt;
    site-to-site {&lt;br&gt;
       peer @foo {&lt;br&gt;
         authentication {&lt;br&gt;
             mode pre-shared-secret&lt;br&gt;
             pre-shared-secret qwerty&lt;br&gt;
         }&lt;br&gt;
         default-esp-group Foo&lt;br&gt;
         ike-group Foo&lt;br&gt;
         local-address 203.0.113.1&lt;br&gt;
         tunnel 1 {&lt;br&gt;
             local {&lt;br&gt;
                 prefix 10.103.0.0/24&lt;br&gt;
             }&lt;br&gt;
             remote {&lt;br&gt;
                 prefix 10.104.0.0/24&lt;br&gt;
             }&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 } &lt;br&gt;&lt;/pre&gt; 
 &lt;h3&gt;NATed side&lt;/h3&gt; 
 &lt;pre&gt;  ipsec {&lt;br&gt;
    site-to-site {&lt;br&gt;
         peer 203.0.113.1 {&lt;br&gt;
             authentication {&lt;br&gt;
                 id @foo&lt;br&gt;
                 mode pre-shared-secret&lt;br&gt;
                 pre-shared-secret qwerty&lt;br&gt;
             }&lt;br&gt;
             default-esp-group Foo&lt;br&gt;
             ike-group Foo&lt;br&gt;
             local-address any&lt;br&gt;
             tunnel 1 {&lt;br&gt;
                 local {&lt;br&gt;
                     prefix 10.104.0.0/24&lt;br&gt;
                 }&lt;br&gt;
                 remote {&lt;br&gt;
                     prefix 10.103.0.0/24&lt;br&gt;
                 }&lt;br&gt;
             }&lt;br&gt;
         }&lt;br&gt;
     }&lt;br&gt;
 }
&lt;/pre&gt; 
&lt;/div&gt;  
&lt;img src="https://track.hubspot.com/__ptq.gif?a=4129050&amp;amp;k=14&amp;amp;r=https%3A%2F%2Fblog.vyos.io%2Fwhy-ipsec-behind-11-nat-is-so-problematic-and-what-you-can-do-about-it&amp;amp;bu=https%253A%252F%252Fblog.vyos.io&amp;amp;bvt=rss" alt="" width="1" height="1" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important; "&gt;</content:encoded>
      <category>ipsec</category>
      <category>tutorial</category>
      <category>Uncategorized</category>
      <category>vpn</category>
      <pubDate>Fri, 05 Jan 2018 23:14:16 GMT</pubDate>
      <author>daniil@sentrium.io (Daniil Baturin)</author>
      <guid>https://blog.vyos.io/why-ipsec-behind-11-nat-is-so-problematic-and-what-you-can-do-about-it</guid>
      <dc:date>2018-01-05T23:14:16Z</dc:date>
    </item>
  </channel>
</rss>
