The netstat
command is a powerful tool used in Linux and other Unix-like operating systems to display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. It helps users understand the current state of the network and troubleshoot connectivity issues.
The basic syntax of the netstat
command is as follows:
netstat [options] [arguments]
Here are some commonly used options with the netstat
command:
-a
: Show all connections and listening ports.-t
: Display TCP connections.-u
: Display UDP connections.-n
: Show numerical addresses instead of resolving hostnames.-l
: Show only listening sockets.-p
: Show the process ID and name of the program to which each socket belongs.-r
: Display the routing table.netstat -a
netstat -t
netstat -l
netstat -n
netstat -p
netstat -r
netstat -tuln
will show all listening TCP and UDP ports with numerical addresses.grep
to filter results. For example, netstat -a | grep LISTEN
will show only listening connections.