Question: how are ephemeral ports assigned?
Answer: An ephemeral port is a short-lived transport protocol port for Internet Protocol (IP) communications. Ephemeral ports are allocated automatically from a predefined range by the IP stack software. ... After completion (or timeout) of the communication session, the ports become available for reuse.