cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
626
Views
0
Helpful
2
Replies

How does a device on one network connect to with a device on another network

arsalanpti
Level 1
Level 1

So if i have two routers and each router has lets say 2-3 computer devices.I am connected to the 1st router. So if i want to connect from my device to a device on the 2nd router than I will send the request to the public IP of the 2nd router. How does the router determine for which specific device the request is meant for?

  1. PUBLIC IP 1
  • A->10.0.0.1
  • B->10.0.0.2
  1. PUBLIC IP 2
  • C->10.0.0.1
  • D->10.0.0.2

I want to connect from A to C so how does that work. Does C need to be listening on a port on IP2 or is there some other way ?

One of the way I could find was port forwarding that request to a specific port on the router is forwarded to a specific IP. Does that mean router checks the port which is in the layer 4 or the transport layer segment?

And are there some other way in which the router determines for which specific IP my request is meant for.

2 Replies 2

Joseph W. Doherty
Hall of Fame
Hall of Fame

Ah, it took me a bit to understand what you're asking.

First, understand, IPs need to be unique in their L3 topology.  I.e. you cannot have two devices with 10.0.0.1 or 10.0.0.2 (without getting into special fail over cases).

Second, 10.0.0.0/16 are private IPs, i.e. you're not allowed to use these as public Internet IPs.

That noted, it's possible for hosts A or B, with those IPs, to communicate with hosts C and D, across the Internet.

The trick is, those hosts public IPs need to be "translated" to a public IP when they are submitted to the Internet.  Those IPs, again, need to be unique on their L3 topology, i.e. the Internet.

PUBLIC IP 1

A->10.0.0.1 aka 1.1.1.1
B->10.0.0.2 aka 1.1.1.2

PUBLIC IP 2

C->10.0.0.1 aka 2.1.1.1
D->10.0.0.2 aka 2.1.1.2

If hosts use their also known as public IPs, and NAT (network address translation), they can intercommunicate.  How they know what public IP to use for the remote hosts, is somewhat the same issue of how they would know what the other remote hosts' IP are.  How the routers "know", is they know how to route using public IPs, and if they are the NAT devices, they also know their own local, to them, private IPs.

Public IPs, at least IPv4 IPs, are very limited, so often we use PAT (port address translation).

PUBLIC IP 1

A->10.0.0.1:x aka 1.1.1.1:1501
B->10.0.0.2:y aka 1.1.1.1:1502

PUBLIC IP 2

C->10.0.0.1:x aka 2.1.1.1:1501
D->10.0.0.2:y aka 2.1.1.1:1502

Notice we only now use one public IP for both hosts A and B, and hosts C and D, but IP UDP/TCP port number need to be assigned, uniquely, for each host port being used.  How hosts A and B know which ports to use, both for their own port translations, and what the remote hosts are using, is a bit more problematic, especially as many UDP/TCP ports have predefined usages, and applications, can be a bit confused or not well support changing port numbers, especially when done, dynamically, using PAT.

Consider if both hosts A and B are web servers that both want to use port 80.  Dealing with this, can get a bit messy, especially when both sides are doing PAT.  However, from a routing perspective, routers ignore port numbers.

AnyatKorai90
Level 1
Level 1

Routers route packets between subnets. In order to do so, they must share a subnet between them. IP addresses are used to direct packets to their destination.

You seem to be referring to NAPT which breaks the original end-to-end paradigm and immensely complicates things. In your own network there's no need to use NA(P)T, however, and you can just forward transparently across routers.

Don't confuse the very common NAT setup with home routers with the normal setup. Businesses don't use NAT within their network, only on their network edge. greenuptown

if i want to connect from my device to a device on the 2nd router than I will send the request to the public IP of the 2nd router.

Only if they're not directly connected but over a public network.

How does the router determine for which specific device the request is meant for?

For a NAT router to forward anything from public IP to private IP space, the router requires a rule set aka port forwarding, destination NAT (DNAT) or reverse NAT. That rule set defines how to translate and where to forward the translated packet.

Generally, you use DNAT when you want to expose a service inside your private network to the general public. If you want to enable private service access across locations you should seriously consider VPN. Using a VPN tunnel, you can route transparently and securely between remote locations. There should be no address overlap between locations as in your example.

Review Cisco Networking for a $25 gift card