NAT question

Status
Not open for further replies.

rookie1010

Fully Optimized
Messages
2,069
Hello

I was trying to understand how NAT worked.
what happens when two internal hosts in a network try to get to say www.tech-heaven.com.
According to what i understood in this article
http://en.wikipedia.org/wiki/Network_address_translation

"However, if two internal hosts attempt to communicate with the same external host using the same port number, the external port number used by the second host will be chosen at random."

does this mean that the web server for www.tech-heaven.com would accept requests made on say the random port 4565 since the request from the second host on the internal network would be port transalted from 80(HTTP) to random port 4565 by the NAT translator?
 
the down and dirty aspect of NAT is,,,,NAT lies to your isp.
In most cases when you turn on your router you acquire a WAN IP . That is on the internet side of the router. Then on the LAN side you have a private ip rangw say for Ummm , three PCs.
As each pc goes and makes a request on the internet NAT keeps track of the ip address that makes the rquest then NAT turns around and tells your ISP "NOPE ONLY ONE IP ADDRESS HERE". Then as the requests come back NAT sends them to the ip that requests them.

IF you did not have a router and you had say dsl. You had a modem and a hub and the three w/s's the first w/s on would grab the WAN ip from your isp the other two would not be able to connect.
 
thanks for the reply

so with a hub connected to the internet, only the first w/s would be able to surf the net.

and if on a router, two w/s make a request to the same ip address (www.tech-heaven.com), the NAT would be intelligent enough to send the correct response to the request to the correct w/s
 
Yes, kind-of. Wether it's a hub or a router doesn't really matter, it only matters that there's a NAT device inbetween the internet connection and your internal network.

The way NAT really works is by keeping track of what inside port the communication request is coming from. When you connect to a web server, you connect to port 80 on the web server, but the port on your computer you send from is somewhere in the range of 1024-65565. So NAT keeps track which external IP address traffic is going to and internal IP address/port each computer is sending traffic from, then routes all traffic from that external IP address destined to the specific port (1024-65565) to the internal IP address.

If you need a bit more explanation, feel free to ask.
 
thanks for the reply dude.

so you mean to say that if there are two PC's and a router say.

and PC1 and pC2 both want to go to www.tech-heaven.com, then they both send a request to the router on different ports, say PC1 sends in on 10001 (dynamic port selection between 1024-65565) and PC2 sends it on 10002, these requests are then routed by the router to the outside world through its port 80.

the response to the two requests arrive on the router on port 80, it routes the response for PC1 to port 10001 and the response for PC2 to port 10002. is my understanding correct?

if my understanding is correct, then who sets these arbitrary ports for the PC's?
 
That's correct in a sense. The router actually sends the requests out on the original port (10001 and 10002 repsectively).

Each PC sets the random port. When making a program that wants to access the internet, you wind up making a socket, then calling a low-level system call that basically says, hey TCP/IP stack, give me an open port that's not reserved for something else. That call returns a port that is in the range of 1024-65565 that's not currently in use.

There is the rare chance that both computers will use the same port for the reuqest. If this happens, whichever computer uses that port first will keep using that port. The second computer will not establish the connection, and thus try again with a new port.
 
Status
Not open for further replies.
Back
Top Bottom