Routing – How Can 2 Computers in Different Networks Communicate?

iplannat;routingwan

Suppose my friend and I are connected to the Internet via some local ISP (not necessarily same), which means we are on different networks, hence our computers have different private IP addresses. Is there any way I can send a message to him if I know his private, as well as public, IP address (which is the IP address of his gateway router)? If so, then how will the packets will reach him?

Best Answer

First, just because your two computers are connected via the Internet at two separate locations doesn't necessarily mean that you are using private addresses. That is certainly the most likely scenarios with IPv4, given the IPv4 address shortage, but it is still not necessarily true. If you are running IPv6, you are probably using public IPv6 addresses.

Let's assume you are using private IPv4 addressing behind a router using NAT.

Knowing the other private address does nothing for you at all, so just take that out of the equation.

Under normal, non-hacker circumstances, the NAT routers at each end would need to have port forwarding enabled for each PC's private address, or the routers would need to be using one-to-one NAT, to enable the two PCs to communicate via the public addresses. You could also use a VPN between the two PCs to get around the NAT problem. This all assumes that there are no firewalls in place to block traffic from the Internet into the private networks.

In one-to-one NAT, each network would have multiple public addresses which uniquely translate to a single private address, so using a public address will get you to the corresponding private address. This is also an unlikely scenario given the shortage of IPv4 addresses, but it is done in some places.

Port forwarding configures NAT to forward incoming traffic sent to a router's public address on a given port number to be sent to a particular inside private address at a given port number.

A VPN is a tunnel. Usually, traffic from one inside network is encapsulated within packets addressed to the public address of the other network and sent to the other network where it is de-encapsulated to the other inside network. This can be configured in such a way as to make the foreign network appear local to the tunnel interface of the local network.

A firewall on either end, or anywhere along the path, may be configured to block any or all of these methods.