0

I know how port forwarding works. but, if two devices in the same network are running the same process, for example suppose two devices are requesting for an HTTP response. Since both services will be running at the same port, how does the router identify the correct device for forwarding the packets

hades512k
  • 3
  • 3
  • Do these answer your question? https://superuser.com/questions/1545541/when-multiple-client-hosts-are-behind-a-nat-sharing-one-external-ip-address-h https://superuser.com/questions/1253022/how-does-an-internet-server-respond-to-a-request-from-a-private-ip – u1686_grawity Jul 28 '20 at 20:30

2 Answers2

1

Simplifying somewhat, every Internet packet has : a source IP, dest IP, source port and destination port. The source port is more-or less random and this is the key.

Your router builds a table mapping table which takes into account all the above and rewrites packets to/from itswan IP, using the source and destination - thus the source port can be used if 2 devices visit the same IP at the same time.

davidgo
  • 68,623
  • 13
  • 106
  • 163
0

servers identify packets like follow:

Level 2: Mac Addr:
Level 3: IP Addr
Level 4: Port 

So, for the demonstration, lets say you have 3 hosts in your network: ClientA, ClientB and ServerC. You have a Web Service running on port 80 on ServerC.

When ClientA make a request, the session is like:

ClientA (IPa, Porta) <-> ServerC(IPc, Portc)

which can be:

ClientA (192.168.1.51,10001) <-> ServerC(192.168.1.10,80)

When ClientB make a request, the session is like:

ClientB (IPb, Portb) <-> ServerC(IPc, Portc)

which can be:

ClientB (192.168.1.52,10001) <-> ServerC(192.168.1.10,80)

So on server, it has 2 uniq sessions:

192.168.1.51,10001-192.168.1.10,80
192.168.1.52,10001-192.168.1.10,80

If ClientA make a second request to the ServerC, we have:

ClientA (IPa, Porta2) <-> ServerC(IPc, Portc)

which can be:

ClientA (192.168.1.51,10002) <-> ServerC(192.168.1.10,80)

So on server, it has 3 uniq sessions:

192.168.1.51,10001-192.168.1.10,80
192.168.1.51,10002-192.168.1.10,80
192.168.1.52,10001-192.168.1.10,80

I hope I was clear enough.

Philip.

Stagira
  • 16