Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let's say i have a "server" program listening on address 1.2.3.4:69 (i.e. remote port 69)

When i connect from a "client" program to it, typically i would specify the IP address + port of the target or server system;

But what port would the client be using ? And how does the server know which port to connect back to the client on?

I understand this question is very general, but just wanting to get a general feel for how things work.

Then extending this to a specific protocol, say FTP (typical port 21), can I change it such that the server uses port 69, but the client uses port 100?

And similarly, for Remote Desktop in WinXP (typical port 3389), i know how to change the server port to be something other than 3389, but how does one change what port the client uses (if at all possible)?

share|improve this question
    
There's a related question on serverfault that might help you: serverfault.com/questions/78925/… –  sleske Mar 20 '11 at 15:45

1 Answer 1

up vote 2 down vote accepted

When i connect from a "client" program to it, typically i would specify the Ip address + port of the target or server system;

Yes, correct.

But what port would the client be using ?

The client usually uses a random port. More precisely: For TCP to work, the only requirement is that the combination of destination address, destination port, source address, source port is unique - because this is used to keep track of TCP connections. So in principle the OS could just increment the source port number for each new connection. Actually, many OSes used to do this, but it made certain kinds of attacks easier, because an attacker could predict the next port number. So most modern OSes now use random source ports.

And how does the server know which port to connect back to the client on?

A TCP packet contains both the destination and the source port, so each side knows both port numbers. See e.g. the diagram for the data inside a TCP packet on http://en.wikipedia.org/wiki/Transmission_Control_Protocol .

Then extending this to a specific protocol, say Ftp (typical port 21), can i change it such that the server uses port 69, but the client uses port 100?

Usually you can configure a server to use any port you choose (though this depends on the individual server application). So you could configure the FTP server to use port 69. The client port cannot be configured as far as I know. The same goes for any other protocol such as RDP.

At any rate, why would you want to change the client port?

share|improve this answer
    
Re why i would want to change the client port is because at work a firewall blocks most ports, except a few; if i make the client go out on a specific port that i know is open, then chances are i will get thru, right? –  joedotnot Mar 21 '11 at 4:38
1  
@joedotnot: Well, that depends on the firewall. However, most firewalls only block based on the destination port. Blocking based on the source port, while technically possible, is generally pointless, because it is usually chosen randomly. So I don't think this will help... –  sleske Mar 21 '11 at 9:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.