K
K
KiRGx2017-10-28 23:11:01
Computer networks
KiRGx, 2017-10-28 23:11:01

How does a client connect to a server behind a router?

There is a client , for simplicity, let it be a Minecraft game client.
I have a Minecraft server running on port 25565 on a PC connected to the router.
The client tries to connect to the server using the ip+port pair. Let's say this is the first connection.
How does the router determine which computer within the network to forward the packets received from the client if the MAC address is initially unknown?
My assumption is that the first packet contains only ip and port, the broadcast address is specified as the MAC address, the router transmits it to all PCs that listen on ports when the packet arrives, and if a PC with an active port 25565 exists, then it sends the packet - response with its MAC address, and then the client adds it later to its packets when it is sent.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
Dmitry Plotnikov, 2017-10-29
@KiRGx

If you are connecting through a router, then you do not need to know about mac-addresses at all.
Everything related to MAC addresses works only within the local area network Ethernet (LAN) - Layer 2 protocol level. Thus, only the router will know about the MAC address of the server, the client does not know the MAC address of the server, the server does not know the MAC address of the client . The router has a table of MAC addresses and their corresponding IP addresses, and if it does not yet know the server's MAC address, then there is the ARP protocol (address resolution protocol).
The interaction between the client and the server starts with Layer 3 and higher protocols.
Due to the fact that NAT (address translation) mostly works on routers, in order to reach the server, you need to manually register port forwarding on the router (in this case 25565) to a specific server IP address. Those. An IP packet that arrives at the external IP address of the router is not redirected to the IP address of the server on the internal network, for this the NAT service of the router changes addresses on the fly (in the direction to the server - the recipient address, in the direction from the server - the source address) in packets. Well, if you don’t care much about security, then you can set up automatic registration of port forwarding via UPNP.

D
Dimonchik, 2017-10-28
@dimonchik2013

everything is easier for
anyone ,
but if you register port forwarding for the router (and where to forward the IP and the port to), it will forward

V
Viktor Belsky, 2017-10-28
@Belyj

If the router translates packets, that is, it works in NAT mode, then, as mentioned above, it must have a translation table indicating the destination host and port. The packet arrives on the WAN interface, on port 25565, the router looks to see if there is a destination port in the conversion table, if so, it changes the destination address (and, if necessary, the port) to an address from the local network, then the firewall rules are checked, then the routing table, finding out on which interface the destination address, and then an arp request (if it is not in the cache), to find out the mac address of the server.
If the router does not broadcast and the server has a white ip, then immediately the firewall rules, the routing table, the replacement of src mac. on the router's poppy and then arp request from the interface on which the server is available.
Z. Y. Everything is described a little exaggerated.

A
Alexander Karabanov, 2017-10-29
@karabanov

Something like this: https://youtu.be/-xxO5jdLvcE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question