Port numbers are assigned to applications and their communications on a local area network (LAN). They help to keep one particular "conversation" distinguishable from another. Default port numbers have been assigned to most applications or services. For example, standard web access (http) runs over port 80, and secure web access (https) runs over port 443. Official well-known port numbers can be found at the Internet Assigned Numbers Authority's website, which is linked in the Resources section. Many commonly known unofficial port numbers are in use by vendors as well.
Open a terminal. For Windows, open a command prompt by clicking on "Start" and typing "CMD" in the "Run" box. For a Mac, type "terminal" in the finder, or go to the Applications folder, open the Utilities folder and open "Terminal." These commands can be run from the client computer or from the server side. Oftentimes, you will not have access to the server side.
Run the command "netstat -an" from the terminal or command prompt. The output is similar for Linux, Windows and Mac. If your output has multiple sections, then scroll up until you find these column headings: Protocol, Local address, Foreign Address and State. The local and foreign address columns indicate the Internet protocol (IP) address and the port number, separated by a colon. Each row indicates an application that is either in a conversation with another computer or waiting to establish a conversation.
Look for a state of "listen" to find the port number of services running on your computer (your computer acting as a server.) "Listen" means your computer is waiting for another computer to request access to that application. Look under the "Local address" column of the associated row to determine the port number.
Look for the state of "established" to find the port number your computer uses to connect to services running on another computer (your computer acting as a client). "Established" means your computer is communicating with an application on another computer. Look under the "Foreign Address" column of the associated row to determine the port number.
Run "netstat -bn" and "netstat -abn" from a Windows command prompt to determine the port number in use by a particular application. On a computer running the application as a service (server side), look for the application in the "listening" state, and check the "Local Address" column to find that application's port number. On a computer trying to connect to the service (client side), open the application to establish the connection, and then run the "netstat -abn" command. Look for the application in the "established" state, and find that application's port number in the "Foreign Address" column.
This is harder to do for Linux or Mac, but the command "lsof -i" will sometimes show you the applications and the tcp ports they use.
Find the non-standard port number that was configured on the server. Do this by using one of the previous methods or by looking at the configuration preferences for the application running on the server. If you do not have access to the server, then ask the server's administrator which port number the application uses.
Each conversation is associated with two port numbers. The server's side is a standard or well-known port number ranging from 0 to 1023, and the client's side is a number randomly generated just for that brief conversation and ranging from 49152 to 65535.
When a server's application's port number has been configured to be a non-standard port, then a computer must modify the client's application's port number to match that of the server in order to connect to the service. If Google were configured to use port 8080 rather than the standard port 80, for example, you would access it by typing "http://google.com:8080" into your web browser; in this case, the browser would be the client application. Each client application has a different way to configure non-standard port numbers.
To see all the options for the netstat command, type "netstat /?" in a Windows command prompt, or type "man netstat" in a Mac or Linux terminal.
- NetGear: Port Numbers for Port Forwarding
- Microsoft: Netstat
- Experts Exchange: Anyone Know What Port Number VNC Uses?
- NetGear: Port Numbers for Port Forwarding
- Xbox: Network Ports Used by Xbox Live
- Microsoft Support: How to Change the Listening Port for Remote Desktop
- Internet Assigned Numbers Authority: Port Numbers