Raspberry Pi

How to Check for Open Ports on Raspberry Pi using netstat

A port is basically a logical entity in computer networking that acts as a communication end point to identify a given application or process on the system. It’s a 16bit number that differentiates one application from others on several end points. These ports use the two widely used UDP and TCP protocols, allowing the system to communicate over the internet for receiving packets.

If you are looking for a way to check for open ports on Raspberry Pi for trouble shootings related problems, follow this guide.

How to Check Open Ports on Raspberry Pi

The “netstat” is widely used utility for network related activities and it’s already pre-installed in most Linux distributions, including Raspberry Pi as well. Follow the below mentioned command to check open ports on Raspberry Pi.

To check for open ports and their TCP listening states, you can use the following command.

$ netstat --listen

Though the above command doesn’t display the status of established UDP connection on different ports. To display this type of information, you can use the following command:

$ netstat -vautn

Another command that can display the open ports on current server.

$ netstat -lnt

To retrieve information of only TCP open ports on Raspberry Pi system, you can use the below-given command.

$ netstat -lnt | grep LISTEN | awk '{ print ( $4 ) }' | awk 'BEGIN{FS=":"} { print $(NF) }' | sort -n | uniq

In order to check only UDP open ports, you can execute the below-given command.

$ netstat -lnu | grep udp | awk '{ print ( $4 ) }' | awk 'BEGIN{FS=":"} { print $(NF) }' | sort -n | uniq

To see what ports are opened on your system, use the following command.

$ netstat -lptn

To see what process are being operated through the open ports on TCP connection, use the below-given command.

$ netstat --tcp --listening --programs --numeric

In contrast, to display all UDP open port connections, execute the below-given command.

$ netstat -vuln

For further guidance, you can open netstat manual using the following command:

$ man netstat

Conclusion

A port is a communication end point that is used to identify a given process or application on the system. The above-mentioned guidelines show different “netstat” commands to check for open ports on Raspberry Pi system. These commands will help users during network troubleshooting or blocking ports on Raspberry Pi for security purposes.

About the author

Muhammad Nasir

Hi! I am an engineer and technical blogger by profession and I enjoy getting things done with electronics. I am using this platform to share my knowledge in the field of Raspberry Pi, Linux, and Embedded Systems with others.