0

So I've been learning about NAT and how it allows us to reuse IPv4 addresses by using a NAT table and having basically an alias for the private IP to a public IP and vice versa along with storing the port. But something I can't wrap my head around is that if there are packets being sent simultaneously which will use the same public IP address, how does the router know which device to send data to? Does it utilize MAC addresses? Does it utilize port numbers?

(If this doesn't belong here, guide me to which StackExchange site I should post this on)

1 Answer 1

1

Each TCP/UDP connection/association is uniquely identified by the tuple (source address, source port, destination address, destination port). So any connection/association (that ends up in the NAT tracking table) can be uniquely identified, even if multiple connections (same host or multiple hosts) exist to the same host:port.

MAC addresses are not involved because the LAN host could be in a different layer 2 network segment.

4
  • So ports do play a part in uniquely identifying the device that intended data is supposed to be going to? Commented Apr 8, 2021 at 19:26
  • 1
    Yes, they are essential.
    – Daniel B
    Commented Apr 8, 2021 at 19:26
  • And if that port is already being used I already assume that the computer will just pick another port depending on the protocol (TCP/UDP), right? Commented Apr 8, 2021 at 19:27
  • Keep in mind, with the exception of port forwarding, a router isn't interacting with the traffic at Layer4, so it doesn't have any open ports. its just routing traffic, so it has no problem with multiple stations on the inside of the NAT from using the same source port at the same time. return traffic is disambiguated by the Nat connection tracking tables. the router just passes the traffic to your PC's IP/Port. Port forwarding however does take up a port on the routers WAN, such that you can't have two port forward rules for the same port on the same WAN. Commented Apr 8, 2021 at 22:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .