I
I
Ilya bow2018-06-03 02:01:14
Computer networks
Ilya bow, 2018-06-03 02:01:14

The browser for each site uses its own port of departure (i.e. 1 site 1 port). Right? If so, by what algorithm is the port number selected?

1. As I understand it: If the browser needs to load a site, it selects a random port and sends packets from it to the server.
And the server sends responses to the port that was chosen by the browser.
For each site (or session with the site), a port is selected.
Correctly?
2. How exactly does the browser choose a port? By what algorithm?
3. How will the gateway with nat behave if through it PC1 and PC2 send a packet to the X server from the same port?
It turns out that the gateway will not be able to what uh ... the response from the server to which PC belongs. What will the gateway do in this case? Is there any protection against the above described situation?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Mystray, 2018-06-03
@8889996

2. How exactly does the browser choose a port? By what algorithm?

The browser does not select ports itself, but relies on the operating system. And already she chooses according to her own algorithms
for the second outgoing connection, in addition to the sender's address, it will also change the port number, business. Or maybe it will change the first connection, if for some reason it decides that it is more convenient.

R
res2001, 2018-06-03
@res2001

1. Often a browser for one site opens more than one connection, but immediately a pack and downloads resources in parallel. Ports in this case are different for each connection. In addition, on the same page there may be links leading to different sites, for which the browser opens new connections.
2. As it was said, the port selects the OS. When opening a socket, the browser indicates that "any local port" is needed. Consider the OS picking the first free port from the dynamic range . It's actually more complicated, of course, but the specific algorithm is usually not important.
3.In the general case, a gateway with NAT replaces both the address and port, so the server will see not the address and port of the sender, but the address and port of the gateway. All this happens transparently for the server and for the client. The client thinks that he communicates directly with the server, and the server thinks that the client is a gateway with NAT and does not suspect that the real address / port of the client was spoofed by NAT along the path of the packet.

D
Dimonchik, 2018-06-03
@dimonchik2013

1) correct
2) every time (each tab) the port increases, but you won’t even open 1000 tabs - there won’t be enough memory or processor (I’m silent)
3) NAT distributes by IP address and doesn’t care about ports at all, look like firewalls implemented

A
Alexander Karabanov, 2018-06-03
@karabanov

3. That's what CG-NAT was invented for

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question