1. List All Ports (both
listening and non listening ports)
List all ports using netstat -a
# netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:30037 *:* LISTEN
udp 0 0 *:bootpc *:*
List all tcp
ports using netstat -at
# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:30037 *:* LISTEN
List all udp
ports using netstat -au
# netstat -au
udp 0 0 *:49119 *:*
udp 0 0 *:mdns *:*
2. List Sockets which are in
Listening State
List only listening ports using netstat -l
# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:ipp *:* LISTEN
List only
listening TCP Ports using netstat -lt
# netstat -lt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:30037 *:* LISTEN
List only
listening UDP Ports using netstat -lu
# netstat -lu
List only the
listening UNIX Ports using netstat -lx
# netstat -lx
Active UNIX domain sockets (only servers)
3. 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
4. Display PID and program
names in netstat output using netstat –p
netstat -p option can be combined with any other netstat option.
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
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 ramesh-laptop.loc:52750 lax:www ESTABLISHED 2109/firefox
5. 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
6. Print netstat information
continuously
netstat
will print information continuously every few seconds.
# netstat -c
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 ramesh-laptop.loc:36130 101-101-181-225.ama:www ESTABLISHED
CLOSING
7. 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.
8. Display the kernel routing
information using netstat -r
# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth2
Note: Use netstat -rn to display routes in numeric format without
resolving for host-names.
9. Find out on which port a
program is running
# netstat -ap | grep ssh
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 1 0 dev-db:ssh 101.174.100.22:39213 CLOSE_WAIT -
Find out which process is using a particular port:
# netstat -an | grep ':80'
10. Show the list of network interfaces
# netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
lo 16436 0 4 0 0 0 4 0 0 0 LR
No comments:
Post a Comment