<aside> 💡
In this chapter, we begin by discussing and exploring why, in the experiments from previous chapters, we were unable to successfully ping Google DNS from a self-created network namespace. This issue leads us to the main topic of this chapter: Network Address Translation (NAT), along with an explanation of its various types and Port Address Translation (PAT).
In the next chapter, we will conduct hands-on experiments using iptables to learn about SNAT, DNAT, and Conntrack, among other key concepts. Therefore, understanding NAT and PAT will serve as essential prerequisite knowledge for the upcoming chapter.
</aside>
In a previous article (05. Understand Linux Routing System - Part 2 ), we left an open question. We attempted to send a ping from our self-created network namespace ns1 to an external network service, Google DNS. However, we observed that while the ICMP Echo Request packets were successfully sent, the ICMP Echo Reply packets never arrived.
To better understand this issue, let’s break down the ping flow step by step.
We will use the diagram below to illustrate the packet flow of a ping command:
WAN (Wide Area Network) in the diagram represents the external public network.
176.12.0.9 represents a machine in the WAN that is on the same subnet as our Linux host.8.8.8.123 represents a machine in the WAN that is on the same subnet as Google DNS.ICMP Packet section below that shows the contents of the ICMP packet at each step along the arrows.ns1 to br0When we initiate a ping from ns1 to Google DNS, the ICMP Request packet travels through the virtual eth0 interface and enters the br0 bridge. At this point, the contents of the ICMP packet are as shown in the diagram.
br0 to wan (172.12.0.9)Next, as the packet travels from br0 to the host’s eth0, this segment is handled within the same kernel network namespace, so it can be considered internal kernel processing.
For the segment from the host’s eth0 to a machine in the WAN, assuming no additional mechanisms or external assistance, the ICMP packet’s Source and Destination IP addresses remain unchanged. This ensures that the packet knows where to send the reply. What does change, however, is the MAC address.
wan (8.8.8.123) to Google DNSNext, the ICMP Request packet may traverse multiple routers within the WAN and eventually reach Google DNS, hypothetically arriving from the machine with IP address 8.8.8.123. At this point, the contents of the ICMP packet are as shown in the diagram.
When the Google DNS host receives the ICMP Request packet, it sends back an ICMP Reply packet. However, we notice that the Destination IP of the reply is 10.22.33.4—a private IP within our internal network.
Since no one on the public network knows where this IP resides, the packet cannot be delivered to the correct destination and is ultimately dropped during routing.
Based on the ping flow above, we can now describe our issue more precisely.
<aside> 💡
Can’t route back to my host since nobody knows how to route according to the Destination IP (10.22.33.4)
</aside>