How NAT Traversal Works | Docs (2024)

Open inbound ports are a major security risk. That’s why Twingate’s platform is architected so it never requires inbound ports to be open anywhere. However, end users still need to be able to reach Connectors to gain access to your private resources. So, how does that happen if there aren’t any open ports?

There are two ways to do this under our security model:

  • Using an intermediary in a public cloud that Clients and Connectors can connect to and transfer packets to and from (this is the secondary role that our Relays play and the reason why we have Relays deployed across the globe).
  • Using something called network address translation (NAT) traversal to establish peer-to-peer tunnels between Clients and Connectors.

We’ll cover Relays later in this article, but because they are far more intuitive to understand than NAT traversal, we’ll focus on what it takes to establish a secure channel of communication (also called a peer-to-peer or P2P tunnel) between a Client and Connector without opening any public inbound ports.

Let’s peek behind the curtain and review what makes NAT traversal possible and how it works. First, we need to define a few things, including what NAT is, what ports are, and how firewalls work, at a high level.

What NAT is and how you use it every day at home

When Charlie connects to her Wi-Fi network in Seattle, her laptop gets assigned an IP address, say 192.168.1.4. When Linus is connected to his own Wi-Fi network in New York, his laptop is, coincidentally, also assigned 192.168.1.4 on that network.

Now, if both Charlie and Linus simultaneously connect from their devices to lego.com, the lego.com server needs to have a way to respond to both separately even though both devices have the same IP address.

The reason this works just fine and doesn’t break the internet constantly is because the IP address they both use (192.168.1.4) is not a public IP address. In fact, it’s part of a range of IP addresses that is reserved for private networks - they can be (and are) reused across many unrelated private networks. They cannot be used as public IP addresses.

Public IP addresses, on the other hand, are globally unique and are the reason why lego.com can respond to Charlie’s device without responding to Linus’ computer instead, even though they have the same private IP address.

From the perspective of the lego.com server, Charlie’s laptop sent a request from a unique public IP address assigned to her by her internet service provider (ISP) (say, 174.21.179.34), while Linus’s device is assigned a different public IP address by his ISP (say, 121.56.6.12). That’s why there is no ambiguity for lego.com and it can respond to everyone without internet wires getting crossed.

The process of getting traffic originating from a non-unique private IP address like 192.168.1.4 to becoming a request from a unique public IP address at 174.21.179.34 is NAT at work. As the “T” in NAT implies, NAT translates Charlie’s private network address (the “NA” in NAT) into a public IP address so that lego.com can respond to her without accidentally sending those packets to another device (and without knowing anything about Charlie’s private network).

How NAT Traversal Works | Docs (1)

NAT also works in the other direction. It translates packets sent to Charlie’s public IP address (from lego.com) back to her device’s private IP address on her private network. This is essential because, as we saw, when lego.com talks to Charlie at 174.21.179.34, it cannot know which device on that private network actually made the request (since lego.com knows nothing about Charlie’s private network. From lego.com’s perspective, all the devices in Charlie’s network making requests to lego.com look like they come from the same public IP address).

How then does the request come back to Charlie’s device at 192.168.1.4 and not to, say, her brother Moose who, from another device connected to the same private network, is also browsing lego.com at the same time (e.g. from 192.168.1.3)?

How NAT Traversal Works | Docs (2)

You guessed it, it’s also NAT. The NAT device (most likely a router for users at home) keeps track of what private IP addresses have sent packets to which public IP addresses, so when packets come back from that public address, the NAT device knows which private IP address they should go to, even though lego.com sends everything to the public IP address.

Now, before we get into how that process works, we need to explain what ports are.

Introducing ports

How does a router keep track of sessions initiated by different devices on its private network, in practice? It uses ports.

You can think of an IP address as a postal address to an apartment building with many units. If you want to visit your friend and know the address to their building, you’ll also need to know your friend’s apartment number. That’s what ports are: individual units you can visit (connect to) that are attached to a single (IP) address.

Each IP address comes with a staggering 65,535 ports. Quite the massive apartment complex.

In practice, ports are always used when your computer connects to another device: your laptop doesn’t just connect to another device’s IP address, it actually connects to a specific port + IP address combination.

You can observe this in your browser when you visit any website. Pick any URL you go to regularly and add “:443” right after the website’s domain name. Doing so will tell your browser that you want to connect port 443 on the server hosting the website. For instance, connect to https://lego.com:443 instead of https://lego.com.

See any difference when adding the port number? No? That’s because when you connect to https://lego.com, you automatically get connected to port 443. Your browser knows that https connections, by convention, occur over port 443, but hides that information because the majority of people do not need to know what port is being used.

How NAT uses ports

Back to our scenario. Charlie and Moose now both connect to lego.com from different devices on the same Wi-Fi network at home. Both devices have different private IP addresses, but from the perspective of lego.com, they both appear to have the same public IP address.

The reason it doesn’t create any ambiguity is because lego.com isn’t just responding to our unique public IP address, it’s actually responding to our unique public IP address on two different ports (one assigned to Charlie’s device, the other one to Moose’s). Since the public IP address + port combination is unique, it allows the router to determine which connection is meant for which device.

Practically speaking, the browser on Charlie’s device is assigned an arbitrary port (say 6789) and the browser on Moose’s device is assigned another one (say 6543). When they both connect to lego.com (or anything else on the internet), the NAT device replaces the source IP address (which is the private IP address in this case) and the source port with its public IP address (common to both Charlie and Moose) and a newly assigned port number (which is different for Charlie and Moose).

Now the lego.com server sees two incoming connections from the same public IP address, but one is from port 6789 and the other is from port 6543. All the server needs to do is to respond to the same public IP address on the appropriate port. In other words, the lego.com web server makes two separate connections: one on the port assigned to Moose’s device and one on the port assigned to Charlie’s device.

The NAT device at home performs the reverse translation when those packets flow back - that’s how it knows which packets are intended for which device.

(In reality it’s a bit more complex, but this is a good enough approximation for our purposes here.)

How NAT Traversal Works | Docs (3)

How firewalls typically work

Firewalls protect you from all the wild stuff on the internet and can also act as NAT devices that do roughly two things:

  • they let things out: that is, they allow network packets to flow from your private network out to the internet
  • they keep things out: that is, they block network packets from entering from the internet from connections initiated from outside the network to your public IP address

When it comes to NAT traversal, the most important thing to understand about firewalls is that they can let packets flow in from a public IP address and port combination if and only if packets first flowed out through that combination from a connection initiated from within the private network. That’s why the lego.com server is able to send its webpages to your browser - because your browser first connected and sent some packets to it.

How NAT Traversal Works | Docs (4)
How NAT Traversal Works | Docs (5)

It makes logical sense: if your computer on your private network tries to connect somewhere public (like a website), it is likely deliberate and safe, so it’s allowed through (and responses are allowed to come back). However, if something on the internet tries to connect into your private network (without any prior connection to it from within)… that probably isn’t safe at all.

Note that it is possible to configure your NAT device to allow incoming connections from the public internet. For example, if you wanted to connect to a device in your private home network when you are not at home.

This is often referred to as port forwarding in consumer grade routers and firewalls, where you can designate a port that accepts incoming connections from the internet (this is called an “open” port). But, before you open any port, let’s make something crystal clear: opening a port to the internet is generally a terrible idea and is asking for trouble.

As soon as you open a port, random things out on the internet will see it and try to connect to it. Bots continually scan public IP addresses for open ports and nefarious actors attempt to probe them for vulnerabilities. It doesn’t matter who you are - if you have a port open, it will get connection attempts dozens of times a day and nothing good will comes from that.

How VPN gateways work

If you want to remotely access your own private network, you already know what a VPN is - VPNs are designed to allow remote devices to securely connect to private networks, over the internet.

They are usually built based on a client-server architecture: a VPN client on a user’s device connects to a VPN server (or gateway) sitting behind the firewall; the VPN server verifies the user’s credentials and then grants their device access to the private network and assigns it a private IP address on it. From that point on, the device is considered to be “on” the private network even though it’s not physically connected to it in any way.

The server component of VPNs – the gateways – are not inherently bad, except for one critical aspect: for a VPN client to connect to a gateway, the gateway typically listens for inbound connections from clients on the internet via an open port which is, as we mentioned before, a bad idea. For example, if the VPN server has a vulnerability, that vulnerability could be exploited by anyone on the internet (there are numerous examples) of this occurring).

It matters little how robust server side security is - if a port is open and there exists some obscure technical method to circumvent its security and gain access, someone will figure it out and you will be in trouble.

Seriously, don’t open inbound ports to the internet.

Now, back to the central question: How can you securely allow a remote connection to a private network without opening any ports on your network devices?

Letting things in without opening a port

Solution 1: Relays

Since firewalls are basically one-way doors, why not allow the clients and servers to connect to some public third party that can facilitate connectivity between the two sides?

The way this works is that both the client and server initiate outbound connections to this intermediary, and the intermediary (which now has the ability to send packets back to both the client and the server) can facilitate two-way communications between both sides. This way, all parties behind a NAT device only need to make an outbound connection.

How NAT Traversal Works | Docs (6)

While this method can work well (and is one method Twingate uses), there are some considerations to keep in mind:

  • introducing an intermediary means more hops and therefore potentially more latency
  • the connection between the client and server should be encrypted in a manner that is outside of view of the intermediary so that it cannot decrypt the communications flowing through it (this is often referred to as end-to-end encryption)

Both of those considerations are the reason why Twingate maintains Relays worldwide and why Clients and Connectors encrypt their traffic without any involvement from Relays: it makes it impossible for the Relay to decrypt that traffic (short of breaking the encryption algorithm that was used).

Solution 2: NAT traversal

Introducing an intermediary can work, but what if we can remove the extra hop, cut out the intermediary, and establish peer-to-peer connection instead? That is where NAT traversal comes in.

How NAT traversal works

We have now established a couple of very important things about firewalls:

  • they allow network packets to flow from your private network to anywhere on the internet
  • they block network packets initiated from the internet and sent to your private network
  • network packets from a public IP address are allowed to flow back in if they first flowed out to the same address & port

To explain what happens when NAT traversal is at work, let’s abstract away the nuances of IP addresses, ports and firewalls and pretend that the Client and Connector are two unacquainted guests (Charlie and Linus) staying at the same hotel. Charlie and Linus want to securely send each other written notes.

Let’s also establish some rules:

  • Charlie and Linus can both send notes to any other hotel room but they need a hotel room number and the last name of the guest occupying the room to do so (Charlie is the Client and Linus is the Connector. They can both connect and send packets to anything public if they have an IP address and port)
  • Charlie and Linus can only receive a note from another hotel guest if they sent that guest a note first (the Client can only receive packets from the public IP and port of the Connector if the Client has previously sent packets to the Connector)
  • Charlie and Linus start with no knowledge of each other’s last name or hotel room number (the Client and Connector have no prior knowledge of each other’s public IP addresses or ports)
  • Charlie and Linus want to send each other notes without an intermediary (Client and Connector want to establish peer-to-peer communications)
  • Charlie and Linus can both call and rely on the hotel manager (the Relay acts as a trusted intermediary)

How Charlie and Linus establish a peer-to-peer connection

  • Charlie and Linus both call the hotel manager to report their own room number and last name (the Relay, in this case, acts as a STUN server, and is also a broker of information between both parties)
  • The manager responds to Charlie by sharing with her Linus’s last name and room number (and responds to Linus by sending him Charlie’s information)
  • Charlie then sends a note to Linus’s room while Linus simultaneously sends a note to Charlie (the Relay coordinates timing of the Client and Connector initiating outbound connections to one another at the same time)
  • Since Linus can receive a note from Charlie only if he already sent one to her, and since he sent a note to Charlie already, he is allowed to receive Charlie’s note (and vice versa)
  • Now Linus and Charlie can send notes to each other’s room back and forth without restriction!

How NAT Traversal Works | Docs (7)

How the Client and Connector establish a peer-to-peer connection

  • The Relay facilitiates the creation of a Relay-based end-to-end encrypted tunnel between the Client and Connector to be used as a messaging channel
  • The Client and Connector exchange their public IP address and port combination via the messaging channel
  • The Client sends packets to the Connector’s public IP address and port (and the Connector sends packets to the Client’s public IP address and port)
  • Because the Client sent packets to the Connector, it lets in packets sent from the Connector and vice versa
  • Now we have a peer-to-peer connection without having any open inbound ports!

How NAT Traversal Works | Docs (8)

This is basically how NAT traversal manages to allow a peer-to-peer tunnel without any inbound open port!

Note that certain network conditions may prevent a peer-to-peer connection from being established. For troubleshooting tips on peer-to-peer and NAT traversal, head over to our troubleshooting guide.

How NAT Traversal Works | Docs (2024)

FAQs

How does NAT traversal work? ›

How does NAT traversal work? NAT traversal employs NAT to set up communication between two endpoints. The process involves the use of techniques that allow the endpoints to communicate directly. It is particularly useful for peer-to-peer applications, which require direct connections for optimal performance.

How does NAT work step by step? ›

How Does NAT Work? NAT works by having a firewall act as an intermediary for traffic entering and leaving the protected network. Inbound traffic is directed to a public-facing IP address, which is translated to an internal IP address to the firewall before sending the traffic on to its destination.

How does Cisco NAT traversal work? ›

NAT Traversal is a feature that is auto detected by VPN devices. There are no configuration steps for a router running Cisco IOS Release 12.2(13)T. If both VPN devices are NAT-T capable, NAT Traversal is auto detected and auto negotiated. Enables higher privilege levels, such as privileged EXEC mode.

What is NAT traversal for dummies? ›

How NAT traversal works
  • they allow network packets to flow from your private network to anywhere on the internet.
  • they block network packets initiated from the internet and sent to your private network.
  • network packets from a public IP address are allowed to flow back in if they first flowed out to the same address & port.

What are the three methods of NAT? ›

The three main NAT types are static NAT, dynamic NAT, and port address translation (PAT).

How does NAT keep track of connections? ›

The NAT-enabled router stores each source computer's IP address and port number. It uses its own registered IP address and port numbers to replace the IP address and the port number that correspond to that packet's source computer in the table.

What is NAT for dummies? ›

NAT stands for network address translation. It's a way to map multiple private addresses inside a local network to a public IP address before transferring the information onto the internet. Organizations that want multiple devices to employ a single IP address use NAT, as do most home routers.

What is the 1 to 1 NAT rule? ›

The 1-to-1 NAT rule builds a static, bi-directional relationship between the corresponding IP addresses. When the 1-to-1 NAT rule is applied, the Firebox creates the bi-directional routing and NAT relationship between the pair of addresses. 1-to-1 NAT also operates on traffic sent from networks the Firebox protects.

How does NAT know which device? ›

So, instead of using the IP addresses to identify the source device, the router or NAT firewall uses port numbers to distinguish the traffic. These port numbers are assigned to devices on the network. They allow the router to return packets to multiple devices using a single public IP.

How does IPsec handle NAT traversal? ›

It works by having the IPsec endpoints use a special payload in their IKE messages to indicate their support for NAT-T and detect any NAT device between them. If both endpoints support NAT-T and detect a NAT device, they switch from using UDP port 500 to UDP port 4500 for the IKE messages.

How does Cisco NAT work? ›

Network Address Translation (NAT) is a service that enables private IP networks to use the internet and cloud. NAT translates private IP addresses in an internal network to a public IP address before packets are sent to an external network.

Does NAT happen before routing? ›

DNAT means the actual address of the internal network is hidden from the Internet. This step determines whether a route to the destination address actually exists. DNAT must take place before routing so that the unit can route packets to the correct destination.

What is the NAT traversal process? ›

Network address translation traversal is a computer networking technique of establishing and maintaining Internet Protocol connections across gateways that implement network address translation (NAT).

How is NAT like a firewall? ›

A network address translation (NAT) firewall operates on a router to protect a private network. It works by only allowing internet traffic to pass through if a device on the private network requests it. A NAT firewall protects the identity of a network and doesn't show internal IP addresses to the internet.

What is the difference between routing and NAT? ›

The main difference between these two modes is whether the clients on both sites can reach each other. In Route mode, clients on both sites can reach each other. In NAT mode, only clients on Dial-Out sites can reach the entire networks, but the clients on Dial-In site cannot access the network of Dial-Out site.

How does NAT reflection work? ›

NAT hairpinning, also known as NAT loopback or NAT reflection, is a feature in many consumer routers where a machine on the LAN is able to access another machine on the LAN via the external IP address of the LAN/router (with port forwarding set up on the router to direct requests to the appropriate machine on the LAN).

How does path traversal work? ›

A path traversal vulnerability allows an attacker to access files on your web server to which they should not have access. They do this by tricking either the web server or the web application running on it into returning files that exist outside of the web root folder.

How does a NAT translation table work? ›

Each row in the NAT table is a pairing of a private IP address/port number with an outside destination address and port number. A connection is characterized by source address, source port, destination address, and destination port. Once connections are closed, the entries are deleted from the table.

How does traversal work in order? ›

Inorder traversal is one of the most popular ways of traversing a tree data structure. It is a type of depth-first search. The idea behind inorder traversal is to visit the left child, then the root node, and finally the right child.

Top Articles
FxDoping – Forex & Bitcoin & Döviz & Ekonomi Haberleri
THE NEWEST REAL ESTATE SCAM - PHANTOM SELLER FRAUD - Augusta Business Daily
Bubble Guppies Who's Gonna Play The Big Bad Wolf Dailymotion
What happened to Lori Petty? What is she doing today? Wiki
30 Insanely Useful Websites You Probably Don't Know About
Green Bay Press Gazette Obituary
Riegler & Partner Holding GmbH auf LinkedIn: Wie schätzen Sie die Entwicklung der Wohnraumschaffung und Bauwirtschaft…
What is a basic financial statement?
Santa Clara Valley Medical Center Medical Records
Https //Advanceautoparts.4Myrebate.com
5808 W 110Th St Overland Park Ks 66211 Directions
What Time Chase Close Saturday
Busty Bruce Lee
Lake Nockamixon Fishing Report
WEB.DE Apps zum mailen auf dem SmartPhone, für Ihren Browser und Computer.
Obsidian Guard's Cutlass
Honda cb750 cbx z1 Kawasaki kz900 h2 kz 900 Harley Davidson BMW Indian - wanted - by dealer - sale - craigslist
Bank Of America Financial Center Irvington Photos
Nine Perfect Strangers (Miniserie, 2021)
Ruse For Crashing Family Reunions Crossword
Teacup Yorkie For Sale Up To $400 In South Carolina
Purdue 247 Football
Gran Turismo Showtimes Near Marcus Renaissance Cinema
At 25 Years, Understanding The Longevity Of Craigslist
Narragansett Bay Cruising - A Complete Guide: Explore Newport, Providence & More
Truck from Finland, used truck for sale from Finland
Tom Thumb Direct2Hr
Criglist Miami
Albertville Memorial Funeral Home Obituaries
Miles City Montana Craigslist
Little Einsteins Transcript
Craigs List Jax Fl
Free Tiktok Likes Compara Smm
Calculator Souo
Jambus - Definition, Beispiele, Merkmale, Wirkung
Texas Baseball Officially Releases 2023 Schedule
450 Miles Away From Me
Bbc Gahuzamiryango Live
Download Diablo 2 From Blizzard
O'reilly's El Dorado Kansas
Ds Cuts Saugus
Top 40 Minecraft mods to enhance your gaming experience
Watch Chainsaw Man English Sub/Dub online Free on HiAnime.to
Dicks Mear Me
Mcoc Black Panther
tampa bay farm & garden - by owner "horses" - craigslist
Mytmoclaim Tracking
Mike De Beer Twitter
Provincial Freeman (Toronto and Chatham, ON: Mary Ann Shadd Cary (October 9, 1823 – June 5, 1893)), November 3, 1855, p. 1
Jasgotgass2
Overstock Comenity Login
Qvc Com Blogs
Latest Posts
Article information

Author: Patricia Veum II

Last Updated:

Views: 5797

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.