Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've a router and two local machines A and B with respective ip and are connected with this router. When A makes a http request to some server and corresponding response is received by router, then how is this response propagated to A (not to B)? Is each request associated with a specific port so that router knows it's for A not for B? In that case ports couldn't be shared on A and B?

share|improve this question

migrated from Jan 16 '10 at 8:40

This question came from our site for professional and enthusiast programmers.

In this case the Address Resolution protocol (ARP) and the Network Address Translation (NAT) are utilized.

NAT on HowStuffWorks

ARP on Wikipedia

share|improve this answer

Is each request associated with a specific port so that router knows it's for A not for B? In that case ports couldn't be shared on A and B?

Yes, ports are part of the game.

But your question is a duplicate. Check out this question:
How do two computers connect to same external address through NAT?

to see how NAT prevents address collisions.


    HOST A addr         HOST B addr
NAT (what external host sees) is router's global (internet) IP.

Every port number is unique in the NAT table. And of course the router does all the dirty job of modifying the source and destination addresses transparently.

share|improve this answer

The HTTP protocol operates on top of the TCP protocol, which operates on top of the IP protocol. TCP is a connection-oriented protocol, which means that a connection must be created before the client and server can communicate.

A TCP connection consists of [source IP, source port, destination IP, destination port]. This means that when a message is sent to the server, the server already has the IP address and port to which it should reply. Any reply is sent in IP datagrams directed to that address and port.

When any datagram is received by a router, it is routed to the next hop along the path back to where the datagram belongs. In your simple case, the next hop is right onto the LAN. When it gets to the LAN, the ARP protocol is used to find the MAC address to send to, assuming that address is not already in the router's address cache. In either case, given the MAC address, the router sends the datagram directly to that address on the LAN.

share|improve this answer

This is not done by ports ofcourse.

On a LAN, this is done by MAC addressed. Basically, each machine has a unique MAC address. Thus, when a user wants A to get an HTTP response from some server (IP given), these processes would be followed:

  1. Find MAC of router by sending an ARP whois to everyone.
  2. Only router replies with its MAC
  3. Router sends HTTP request to server and receives HTTP response
  4. If router has A's MAC in its cache, it forwards the response immediately. Else,
  5. Router sends an ARP whois to everyone
  6. Only A replies with its MAC
  7. Router forwards HTTP response to A
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.