I was studying something called 'Network Mapping'. I got to a point where when I click a link to www.google.com, a packet gets sent from my computer, NAT in the router translates the packet and sends it to the port 80 of google. Now, when the response packet comes to my router, the router somehow knows that this packet is for me and not other computer on the network. My question is how exactly does the router knows this packet is for my computer?

  • 2
    This is "How Does NAT Work", and I'm sure there's already a good answer on this site. Your NAT gateway keeps a table of what private address-port pairs are talking to which public address-port pairs, and which of the NAT gateway's public address-port pairs was used for the NAT conversion. When it gets a reply back on a public address-port pair, it uses that table entry to rewrite and forward the packet. – Spiff Jul 7 '14 at 15:30
  • @Spiff The website(google) knows which port has sent the request. But does it send the response on the same port? Please elaborate with the example ports.. Like my computer sends request from port 39986, router changes the port to 55090, it sends the request to port 80 of google and where does the google send the response to? – user341449 Jul 7 '14 at 15:48
  • it will send it back to the sender, to port 55090. – Karoly Horvath Jul 7 '14 at 15:51
  • possible duplicate of How does the router know which device to send packets to? – Ƭᴇcʜιᴇ007 Jul 7 '14 at 15:52
  • Yes, in your example, Google's server responds from its port 80 to port 55090 on your NAT gateway's public IP address, and your NAT gateway uses a lookup table to rewrite that for port 39986 on your client's private IP address. That lookup table was populated when the client first initiates the TCP connection. – Spiff Jul 7 '14 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.