J
J
jollygulf2020-12-12 20:52:47
Computer networks
jollygulf, 2020-12-12 20:52:47

How does the router determine which of the devices in the local area to send the request to?

Good day, I started studying Internet networks, trying to understand how it all works, I will be glad if they help me. There was a question:

1) Let's say I have a router and a couple of devices in LAN, the router has a WAN connection with a white IP address of the provider. I want to use one of the devices as a server, for example, I start listening on port 5000 using sockets from a computer. Any remote device via the Internet sends a request to open a TCP connection to my IP address and the desired (5000) port. How does the router, having received a packet with this request, understand which of my two devices in the local network this packet should be sent next?

- I have my own answer to this question, I would like to know if it is true or not: When I start listening on port 5000 using the OS socket, the device sends this data to the router, saying that I, with such a local IP and such a MAC address, start listening to our 5000 port, all the data that came to it, give it to me, does it work like that? That is, for example, I can listen to the same port 5000 from one device, and from another, for example, 5050?

I would be very grateful if you explain to me whether I understood everything correctly.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
galaxy, 2020-12-12
@galaxy

Any remote device via the Internet sends a request to open a TCP connection to my IP address and the desired (5000) port. How does the router, having received a packet with this request, understand which of my two devices in the local network this packet should be sent next?

No way, unless specifically configured (this is called "port forwarding").
Ok, there is also UPnP .

K
ky0, 2020-12-12
@ky0

The router does not want to know anything about ports, it just keeps a sign in memory with the correspondence of poppy addresses, IP addresses and ports (physical), so it knows where to send packets.
When you start listening on a port, the OS simply stops rejecting packets with this destination port, and starts passing them to the application. You can do something with these packets without listening to the port (for example, by setting up iptables in Linux) - for example, transfer to another port or even send it somewhere outside.

R
Ruslan, 2020-12-13
@msHack

The computer sends a packet to the router to the address 192.168.88.1 port 80 the router has a DHCP server, it receives and transmits to other clients read about routing and how DHCP works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question