netstat
netsat command allows you to check the state of ports on the local host.
- used to:
- check for service misconfigurations
- e.g., host running a web or FTP server that a user installed without authorization
- identify suspicious remote connections to services on the local host or from the host to remote IP addresses
- check for service misconfigurations
Usage
Windows
- on Windows,
netstatoutputs active TCP connections showing the local and foreign addresses and portsnetstat -adisplays all open ports- includes:
- active TCP and UDP connections
- ports in the listening states
- includes:
netstat -p TYPEshows connections by TYPE (TCP, TCPv6, UDP, or UDPv6)-oshows the process ID (PID) that has opened the port-bshows the process name-ereports Ethernet statisticsnetstat -nnruns netstat continuously, where nn is the refresh intervals in seconds
Linux
- on Linux,
netstatshows active connections of any type- to show different connection types:
-tfor TCP-ufor UDP-wfor raw connections-xfor UNIX sockets/local server ports
netstat -ashows active connections and ports in the listening statenetstat -lshows only ports in the listening state- omits established connections
netstat -4/6filters sockets by IPv4 or IPv6 addresses-pshows the PID and process name-Ireports Internet (Ethernet) statistics-cruns netstat continuously
Info
- netstat on Linux is part of the deprecated net-tools package
- the preferred package is iproute2
- contains a number of different commands to replace
netstatfunctionality- most port scanning functions are performed by
ss- interface statistics are reports by
nstat
Both
- Both OS,
netstat -ndisplays ports and addresses in numerical format- skipping name resolution speeds up each query
netstat -sreports per protocol statistics- packets received, errors, discards, unknown requests, port requests, failed connections, etc.
-rdisplays the routing table