{"id":1655,"date":"2014-07-02T16:02:04","date_gmt":"2014-07-02T20:02:04","guid":{"rendered":"https:\/\/infotechguy.net\/?p=1655"},"modified":"2022-08-26T09:48:22","modified_gmt":"2022-08-26T13:48:22","slug":"nat-traversal-ipsec","status":"publish","type":"post","link":"https:\/\/infotechguy.net\/?p=1655","title":{"rendered":"What is NAT-Traversal??"},"content":{"rendered":"<p>Hi All, been awhile since my last post, however I believe this to be a good one!. So&#8230;the question arose the other day regarding NAT-Traversal. What is that? Why do we have it? What does it do? Most network engineers have heard of NAT-traversal before when configuring their Firewalls and VPN Clients, etc. But, I wanted to take a minute to explain where NAT-Traversals (NAT-T) need came from and the reason we still use it.<\/p>\n<p>In order to understand NAT-Traversal, we need to understand two Networking concepts. First we need to understand &#8220;The Network Flow&#8221;. HOw do two hosts on a Network maintain a communication session. The second, is Network Address Translation. Yes NAT&#8217;ing, is a big part of IPv4 networks, they are so common place that you are probably using NAT&#8217;ing right now when reading this article.<\/p>\n<h2>The Network Flow.<\/h2>\n<p>So in a typical end-to-end connectivity the network traffic flow is maintained by 4 main parameters.<\/p>\n<ol>\n<li><strong>Destination IP<\/strong><\/li>\n<li><strong>Destination Port<\/strong><\/li>\n<li><strong>Source IP<\/strong><\/li>\n<li><strong>Source Port<\/strong><\/li>\n<\/ol>\n<p>These 4 parameters provide a seamless flow of packets back and forth to each end-to-end device within a communication. It is how packets carrying your data arrive at their destination and it is how a return response knows how to get back to the requesting device. The IP requirement is usually pretty straight forward, it&#8217;s like the address of a house. You have to know the <strong>TO<\/strong> and <strong>FROM <\/strong>fields when sending a mail letter. So where does this port information come into play?? So Port number is like a sub-address of where the mailbox is located on a house. Usually a home will only have one mailbox, but imagine the same scenario with an apartment building or housing complex..Many mailboxes at a single address. Now depending on where you live you may need to prepend or add a apartment number to the address. Translate this same concept to port numbers. If my address is <strong>123 North St<\/strong> and I am sending to <strong>789 South St.<\/strong> My courier knows how to drive to each destination, but it doesn&#8217;t know where to put the actual mail envelopes since it is an apartment building with hundreds of apartments. This is where the port number comes in. So if on my envelope I put <strong>123 North St. Apt#100<\/strong> and I am sending to 789 South St. Apt#201. My mail will be delivered not only to the correct address but the correct mailbox.<\/p>\n<p>I like using the apartment analogy, because it makes us think about Address and Ports being used together to deliver mail. An address and port combination is called a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Network_socket\" target=\"_blank\" rel=\"noopener noreferrer\">Socket <\/a>in the networking world.<\/p>\n<p>Now in a typical request scenario, a client forms the TCP\/IP datagram. A Client&#8217;s machine fills in the destination IP and Destination Port based on the target and application type generating the request. For example, when you type <strong>http:\/\/ <\/strong>in your browser, the browser application knows to use port 80 as the Destination Port. The client then fills in it&#8217;s own IP address for the Source IP, and the OS chooses a Source Port at random. We call this random Source Port, the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Ephemeral_port\" target=\"_blank\" rel=\"noopener noreferrer\">Ephemeral Port<\/a>.<\/p>\n<h5>A typical TCP\/IP communication header.<\/h5>\n<p><span style=\"padding: 0px;\">Sent Packet:<\/span><\/p>\n<div style=\"width: 60%; margin-top: -20px;\">\n<table style=\"border: 0px solid transparent; background: #transparent; text-align: center;\">\n<tbody>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Dst IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Dst Port<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Src IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Src Port<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">192.168.10.10<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">80<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">192.168.1.100<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">49152<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><span style=\"padding: 0;\">Return Packet:<\/span><\/p>\n<div style=\"width: 60%; margin-top: -20px;\">\n<table style=\"border: 0px solid transparent; background: #transparent; text-align: center;\">\n<tbody>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Dst IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Dst Port<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Src IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Src Port<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">192.168.1.100<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">49152<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">192.168.10.10<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">80<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><!--more--><\/p>\n<h3>A Brief NAT&#8217;ing Lesson<\/h3>\n<p>How this works is a Network device in-between the source and destination networks, usually a <strong>Router or Firewall<\/strong>, performs Network Address Translation. When NAT&#8217;ing occurs the Network(Router or Firewall) device needs to maintain what has been translated, so it can be untranslated when it returns. The Network(Router or Firewall) device performing the NAT&#8217;ing creates it&#8217;s own local table of addresses it has translated. It maintains the identification of which packets have been translated by taking into account the random source port from above. <strong>Remember the<\/strong> <a href=\"http:\/\/en.wikipedia.org\/wiki\/Ephemeral_port\" target=\"_blank\" rel=\"noopener noreferrer\">Ephemeral Port<\/a>. This random source port is easy way for the Network device to keep track of open connections being translated.<\/p>\n<p><em>NAT&#8217;ing Example #1. In this example I am showing a packet before it passes through a router performing NAT&#8217;ing, &#8220;untranslated&#8221;, and showing a packet after it passess through a router performing NAT&#8217;ing, &#8220;translated&#8221;. Translating Source IP from 192.168.1.100 to 2.2.2.2)<br \/>\n<\/em><br \/>\n<strong><span style=\"padding: 0px;\">Untranslated Packet<\/span><\/strong><\/p>\n<div style=\"width: 60%; margin-top: -20px;\">\n<table style=\"border: 0px solid transparent; background: #transparent; text-align: center;\">\n<tbody>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Dst IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Dst Port<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Src IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Src Port<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">8.8.8.8<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">80<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">192.168.1.100<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">49152<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong><span style=\"padding: 0px;\">Translated Packet<\/span><\/strong><\/p>\n<div style=\"width: 60%; margin-top: -20px;\">\n<table style=\"border: 0px solid transparent; background: #transparent; text-align: center;\">\n<tbody>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Dst IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Dst Port<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Src IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Src Port<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">8.8.8.8<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">80<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">2.2.2.2<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">49152<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><em>NAT&#8217;ing Example #2. In this example I am showing how a router performing the NAT&#8217;ing maintains a NAT table of packets it has translated and untranslated. The example below also shows different Source IPs connecting to the same Destination IP. These Source IPs will need to be translated to a different address, 2.2.2.2.<\/em><\/p>\n<p><strong><span style=\"padding: 0px;\">Local NAT Table<\/span><\/strong><\/p>\n<div style=\"width: 85%; margin-top: -20px;\">\n<table style=\"border: 0px solid transparent; background: #transparent; text-align: center;\">\n<tbody>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Original Source IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Translated Source IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000; background: #FF0000;\">Source Port<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Destination IP<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">Destination Port<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">192.168.1.100<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">2.2.2.2<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000; background: #FF0000;\">49152<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">8.8.8.8<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">80<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">192.168.1.101<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">2.2.2.2<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000; background: #FF0000;\">49943<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">8.8.8.8<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">80<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">192.168.1.102<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">2.2.2.2<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000; background: #FF0000;\">49563<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">8.8.8.8<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">80<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">192.168.1.104<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">2.2.2.2<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000; background: #FF0000;\">49234<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">8.8.8.8<\/td>\n<td style=\"border: 4px solid #000000; text-align: center; color: #000000;\">80<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><em>Notice: The Soure Port is unique to each original IP. Both the Source IP, Source Port, and Destination IP and Destination Port are used together to maintain the Translation table, allowing the correct packets to be untranslated on their return. Sounds similar to &#8220;The Network Flow&#8221; from above right?<\/em><\/p>\n<h3><strong>The problem.<\/strong><\/h3>\n<p>In world of IPSEC, we do <span style=\"text-decoration: underline;\">not<\/span> use TCP or UDP protocols, in fact we use a completely different <a href=\"http:\/\/en.wikipedia.org\/wiki\/Network_layer\" target=\"_blank\" rel=\"noopener noreferrer\">Network Layer Protocol<\/a>(ICMP,ESP, OSPF, RIP,EIGRP,etc) \u00a0instead of a Transport Layer Protocol (TCP\/UDP). \u00a0In fact, the protocol is used to <span style=\"text-decoration: underline;\">protect and hide<\/span> the original IP information, which is the whole point of <strong>IPSec<\/strong>. <strong>IPSec<\/strong> uses an encapsulating protocal called <strong>Encapsulating Security Payload(ESP)<\/strong> to take the original IP information and securely encasulate it via encryption. This prevents wire-tapping or network sniffers from discovering the original IP information while it is in transit. This ESP protocol includes only a Source IP, Destination IP, and a ESP Header and Footer to maintain session state information. <strong>No TCP\/UDP port information can be used to create a NAT table binding!!!<br \/>\n<a href=\"https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3424\" src=\"https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-1-300x109.png\" alt=\"\" width=\"597\" height=\"217\" srcset=\"https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-1-300x109.png 300w, https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-1.png 734w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/a><br \/>\n<\/strong><\/p>\n<p><em>Notice: There is no TCP\/UDP Port information!! It has been replaced by the ESP protocol.<\/em><\/p>\n<p>The issue arises, when a Client attempts to initiate an ESP connection behind a network(Router or Firewall) device that performs Network Address Translation (NAT). NAT&#8217;ing involves the manipulation of the IP Header and TCP\/UDP port information to maintain sessions states as stated in the above section. The Network(Router or Firewall) device is unable to maintain a unique translation state with these packets and therefor a IPSec tunnel cannot be formed.<\/p>\n<h3>The Solution:<\/h3>\n<p><strong> NAT-Traversal to the rescue!!<\/strong> NAT-Traversal encapsulates the datagram yet again with a UDP Packet. By doing so, the Packet now includes a Destination Port and Source Port! We can now successfully perform NAT&#8217;ing and maintain the connection state in the NAT table.<\/p>\n<p><strong>NAT-T Dst\/Src port added to original ESP datagram:<\/strong><br \/>\n<a href=\"https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3425\" src=\"https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-2-300x131.png\" alt=\"\" width=\"600\" height=\"262\" srcset=\"https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-2-300x131.png 300w, https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-2.png 602w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><strong>NAT-T Encapsulation Datagram:<br \/>\n<a href=\"https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3429\" src=\"https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-3-300x67.png\" alt=\"\" width=\"600\" height=\"134\" srcset=\"https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-3-300x67.png 300w, https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-3-768x172.png 768w, https:\/\/infotechguy.net\/wp-content\/uploads\/2021\/03\/NAT-T-3.png 783w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><br \/>\n<\/strong><\/p>\n<h6>VPN Passthrough<\/h6>\n<p>I wanted to mention this feature, because it is very common among home routers utilizing Network address translation. VPN Passthrough is a Consumer router specific technology, used by Routers that cannot support VPN technologies natively. Meaning the router does not perform VPN, the client&#8217;s computer does. Such as a VPN Client, etc. The original issue of NAT&#8217;ing a ESP packet is still present, however the router does not support NAT-Traversal. If VPN Passthrough is enabled on the consumer router, the router inspects VPN traffic originating from it&#8217;s internal network devices and maintains a table similar to the NAT-T table, but via some other propritary means.<\/p>\n<h3><strong>The Requirement.<\/strong><\/h3>\n<p>Both ends need to support NAT-Traversal, since a UDP port is used instead of the ESP Layer 3 protocol. NAT detection also takes place at the start of a IPsec communication, called NAT-discovery. If during NAT discovery, NAT-Traversal is not detected, the IPSec will not be brough up over NAT-Traversal and will use straight ESP.<\/p>\n<h6 style=\"margin-bottom: -20px;\">Configuring NAT-Travesal on a Cisco ASA 5500<\/h6>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ASA# config terminal \nASA(config)# crypto isakmp nat-traversal 20 \nexit<\/pre>\n<h6 style=\"margin-bottom: -20px;\">Configuring NAT-Travesal on Openswan<\/h6>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">openswan# vi \/etc\/ipsec.conf \nconfig setup \n   nat_traversal = yes<\/pre>\n<h6 style=\"margin-bottom: -20px;\"><\/h6>\n<p><em>Notice: This will enable NAT-Traversal globally on the ASA, but remember both sides have to agree and support NAT-Traversal for it to actually work and be used.<\/em><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi All, been awhile since my last post, however I believe this to be a good one!. So&#8230;the question arose the other day regarding NAT-Traversal. What is that? Why do we have it? What does&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":4277,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[55,112],"class_list":["post-1655","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-network","tag-cisco","tag-security-2"],"_links":{"self":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts\/1655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1655"}],"version-history":[{"count":1,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts\/1655\/revisions"}],"predecessor-version":[{"id":4154,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts\/1655\/revisions\/4154"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/media\/4277"}],"wp:attachment":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}