If am using Remote Desktop to login to a remote machine, how does the data for this connection get back into my machine if I don't open any ports on my router?
The same way any data gets back to your computer.
Your router is almost certainly running a stateful firewall and also NAT. This means it keeps track of connections you make through it.
RDP, like HTTP and many other protocls uses a stream socket. So if you make an RDP connection the RDP client will open a port on your client and then make a connection to the remote machine your connection might have details like this.
When initial packet passes through the firewall a entry is added to the state table that includes at least those details. If you are running NAT some additional information will be stored which will include what port the source port has been translated too. If the host you are attempting to connect to accepts your request it will respond to the source address/port that was in the packet. Your router will allow the incoming packet because it has an entry in the state table.
It doesn't get through if you don't have any ports open, nor should anything else. You need port 3389 open to establish a remote desktop connection.
|show 1 more comment|
But if your router uses NAT (or more specifically PAT, aka NAPT), a port is opened for you. Your router has a state table that keeps track of incoming ports, destination hosts, and destination ports; traffic on port
The connection without NAPT would be between port
Whoops, I completely forgot about the remote host being in the state table...