Using egrep I can filter the output using a OR logic that shows the lines that match either “Local Address” (one of the column names) or “LISTEN”. Proto Recv-Q Send-Q Local Address Foreign Address State It wouldn’t match a line that contains the word “LISTENING”.īut something is missing in the output, I would like to see what each column means… ~]$ netstat -na | egrep -w "Local Address|LISTEN" The grep command uses the -w flag to match the exact word “LISTEN”. If I want to verify which ports are open, I can use the command netstat -na together with the grep command to filter only ports that are in listening state: ~]$ netstat -na | grep -w "LISTEN" The main command to check open ports on a Linux system is netstat. Let’s start with the first command! Netstat Command to Check Ports Listening on Linux TCP stands for Transmission Control Protocol, UDP stands for User Datagram Protocol. The file /etc/services on Linux contains the details of all the reserved ports.įor example, using the grep command let’s find the port assigned to the SMTP protocol: ~]$ grep -i "^smtp" /etc/servicesĪs you can see port 25 is used by the SMTP protocol, it’s one of the well-known ports considering that its value is lower than 1023 (do you remember the previous table?)Īnother concept related to the concept of port is the socket.Ī Linux socket is the combination of IP address, protocol (e.g. They cannot be registered with IANA and they are used for automatically allocating ephemeral ports. They can be opened on a system without superuser privileges.ĭynamic or private ports. These ports are assigned by IANA for specific applications (e.g. Only processes with superuser privileges can open a port in this range on a Linux system. Used by system processes to provide standard network services. The following table shows the meaning of different port ranges: Port Range Ports are represented by numbers from 0 to 65535. When started, Apache opens ports (usually 80 or 443) that allow users to access static content or web pages hosted on our Linux system. I see often that the concept of port is not easy to grasp for those who start learning about Linux.Ī port is a communication channel opened on a Linux system when a process starts, ports allow users or programs outside of the Linux system to communicate with it.Īll the examples in this tutorial are based on a common application running on Linux systems, an Apache Web Server. Let’s go for it! What Ports Are Listening on Linux? We will also go through alternatives to netstat like lsof, ss and fuser. You will learn which netstat flags to use to show the port opened by a process on Linux and other tricks that can be very useful to manage a Linux system. You can also see which ports are opened on a Linux system using the lsof, ss and fuser commands. In the netstat output you can also see the port opened by a specific process. The netstat command allows to see the connections from and to our current Linux systems and it provides flags that also show which process a specific connection is related to. How do you find the port of a process running on Linux? This is a very common thing we need to know when we manage applications on Linux, especially if they have been configured by someone else. In this tutorial you will learn how to find the port of a process running on a Linux system.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |