Command netstat displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships etc.
1. List All Ports (both listening and non-listening ports)
# netstat -a
2. Active UNIX domain sockets (servers and established)
List all tcp ports using netstat -at
# netstat –at
List all udp ports using netstat -au
# netstat -au
3. List Sockets which are in Listening State
List only listening ports using netstat -l
# netstat -l
List only listening TCP Ports using netstat -lt
# netstat -lt
List only listening UDP Ports using netstat -lu
# netstat -lu
List only the listening UNIX Ports using netstat -lx
# netstat -lx
4. Show the statistics for each protocol
Show statistics for all ports using netstat -s
# netstat -s
Show statistics for TCP (or) UDP ports using netstat -st (or) -su
# netstat -st
# netstat -su
5. Display PID and program names in netstat output using netstat -p
This will add the “PID/Program Name” to the netstat output. This is very useful while debugging to identify which program is running on a particular port.
# netstat -pt
6. Don’t resolve host, port and user name in netstat output
When you don’t want the name of the host, port or user to be displayed, use netstat -n option. This will display in numbers, instead of resolving the host name, port name, user name.
This also speeds up the output, as netstat is not performing any look-up.
# netstat -an
If you don’t want only any one of those three items ( ports, or hosts, or users ) to be resolved, use following commands.
# netsat -a --numeric-ports
# netsat -a --numeric-hosts
# netsat -a --numeric-users
7. Print netstat information continuously
netstat will print information continuously every few seconds.
# netstat -c
8. Find the non-supportive Address families in your system
netstat --verbose
At the end, you will have something like this.
netstat: no support for `AF IPX' on this system.
netstat: no support for `AF AX25' on this system.
netstat: no support for `AF X25' on this system.
netstat: no support for `AF NETROM' on this system.
9. Display the kernel routing information using netstat -r
# netstat -r
Note: Use netstat -rn to display routes in numeric format without resolving for host-names.
10. Find out on which port a program is running
# netstat -ap | grep ssh
11. Find out which process is using a particular port:
# netstat -an | grep ':80'
12. Show the list of network interfaces
# netstat -i
Display extended information on the interfaces (similar to ifconfig) using netstat -ie:
# netstat -ie
No comments:
Post a Comment