0

we know that Local machines use private ip address inside a company and share a single public ip address when communicate to the outside world, so does routers use MAC addresses to map request/response? (because we obviously don't send private address to the receivers via ip packet, we only send public address which is shared by multiple internal nodes) for example, a route has an internal memeory that cache request machine's MAC address with the desitination public ip address, so that when a request is sent back the router know how to route the response to the request origin machine. But what if there are two machines communicating to the same remote machine, then how does the route know which node to pass the response when the two requests have a same destination public address?

1
  • 1
    "we know that Local machines use private ip address inside a company and share a single public ip address when communicate to the outside world" That is not always true. Many companies own large blocks of public addresses. You are thinking like a home network user. In any case, MAC addresses are only ever seen or relevant on a local network, public or private. You need to research NAT, especially NAPT, often called PAT.
    – Ron Maupin
    Commented May 8, 2023 at 2:50

2 Answers 2

1

we know that Local machines use private ip address inside a company and share a single public ip address when communicate to the outside world, so does routers use MAC addresses to map request/response?

whoisit, I'd like to encourage you to read up on Network Address Translation (NAT) as this is the mechanism you're referring to above.

There are 3 primary types of Source NAT (SNAT) which can be implemented:

  1. Static NAT (stateless)
  2. Dynamic NAT/Pool NAT (stateful)
  3. PAT (Port Address Translation) / NAT Overload (stateful)

Static NAT creates a 1:1 mapping of two IPs (these could be public:private, private:private, etc.). This means all traffic destined for that particular IP will have the source address IPv4 field rewritten to replace the existing source IP with the mapped IP. All return traffic destined for the mapped IP will have the destination rewritten to the mapped IP. Technically you need to have Destination NAT also configured, though many routers put the reverse rule into place automatically. This is stateless because the router doesn't need to remember anything except what mapping the administrator statically configured.

Pool NAT allows for a pool of source address to be dynamically mapped (typically in a first come first serve basis). This requires the router to dynamically create and update a table which maps each source address to the target source address.

PAT is what is commonly used for internet access and is what you seem to be referring to in your question. PAT uses layer 4 information, like TCP and UDP port numbers, to map the source address. Consider this scenario:

(User) -------------------- (Router) ----------------- (Internet)

192.168.1.2 ------- 192.168.1.1 / 24.1.2.54 ---------- 1.1.1.1

User sends a TCP SYN packet to 1.1.1.1, the source TCP port is 29151 and destination port is 53. The packet will have the following fields set:

Source IP: 192.168.1.2

Source port: 29151

Source MAC: (User MAC)

Destination IP: 1.1.1.1

Destination port: 53

Destination MAC:(Router MAC)

The router has PAT configured. When it receives the packet, it performs the translation and forwards it on through the ISP. As it's leaving the router, the following fields are set.

Source IP: 24.1.2.54

Source port: 15121

Source MAC: (Router MAC)

Destination IP: 1.1.1.1

Destination port: 53

Destination MAC:(ISP Router MAC)

Notice that the source IP and port changed. The port might not change, depends on the router configuration. When the router performed this translation, it made a note that any traffic destined for 24.1.2.54:15121 should be untranslated and have the destination rewritten to 192.168.1.2:29151

This video provides a good explanation of Source NAT: https://ciscolessons.com/courses/cisco-ccna-200-301-complete-course/lessons/configuring-source-nat/

0

we know that Local machines use private ip address inside a company and share a single public ip address when communicate to the outside world

That is only true for IPv4 networks that use RFC 1918 addressing with NAT to communicate with the public Internet. Some companies use proxies and some use public addresses on the internal network as well, without requiring NAT. IPv6 does away with the NAT kludge altogether.

do routers use MAC addresses to map request/response?

No. Routers route by destination IP address.

You seem to be referring to NAT routers though - NAT routers build a NAT session table where they track the internal IP belonging to an outgoing connection for source NAT. In contrast, normal routers are stateless and track nothing.

Request/response happens on the application-layer (L7) which not even a NAT router has a concept of (a NAT router works on the network (L3) and transport (L4) layers alone).

MAC addresses (data link layer/L2) are used to send IP packets over a MAC-based network, mostly IEEE ones. The interaction between the network and the data link layer always works the same, regardless of hosts or routers, with or without NAT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.