Jump to content

Can someone help me to understand public/private IP's/gateways???

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Shephard

Shephard

    Newbie

  • Members
  • Pip
  • 6 posts
How is data sent to a computer with a private IP address that is connecting to the internet through a gateway. If only the gateway is seen by the outside, then how is information sent to the individual machines behind it?

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
I'd advise you to just read this: http://en.wikipedia.org/wiki/Routing

All private IPs will be routed through a device such as a router or hub which will use the single public IP node, imagine it like using a phone splitter to connect two phones; You only have one outside connection because your phones share the line.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
zoranh

zoranh

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Private IPs work like this. Computers belong to a network (e.g. a company) have private IPs because company has got only one (or at most couple of) public IP address. This is in turn caused by the limited amount of addresses supported by IPv4, hence companies could not get as many adresses as they desired.

Now, according to TCP/IP, packets are addressed so to be sent to IP: port combination, where IP is the internet protocol address of the host - only one host can have one IP address in the world, and that address is kept in routing tables en route. Private IP addresses are taking from a much smaller part of the IP address space, and many computers in the world share the same private IP. Hence, thos IPs cannot be sent around and expected that any packet would find such a host.

So the question is - how does a computer with private address communicate to a host with public address, i.e. how can a host with public address return anything to the host with private address if that address is not unique?

The answer is NAT protocol (Network Address Translation). It works like this. Host with private IP address sends a packet through a gateway, addressed to public IP. Gateway intercepts the packet (that host is also known as NAT box) and changes the IP header.
private IP address is replaced with gateway's public IP address, and private computer's originating port number is replaced with newly allocated port number on the gateway. Also, that port number on NAT box is associated with private IP address and port number on originating host.

Once remote host sends any reply to the client with private IP address, that packet is actually addressed to NAT box's public IP and port that was specifically allocated for the host in private network. Once NAT box receives such packet, it changes its header to contain private IP address and original port number on the host in private network, and forwards that package further. Since private network is routed internally, private IP address is unique and there is no fear that packet would be missing.

To make this possible, at least one host must be with public IP address. Two hosts with private IP addresses cannot find each other.

Read article Network address translation on Wikipedia for a bit more detail.

Also, I would warmly suggest you to read the book Computer Networks from Andrew Tanenbaum. That will give you a deep insight how networks are built and operated today and help you understand many weird things that exist in practice.