Linux Commands | Network | netstat Check Network Status
netstat Command
Short for network statistics, netstat is software or a tool that shows statistics for network interfaces or protocols. It is commonly used to measure network status and performance and to identify problems on the network.
netstat Usage
netstat [options] [| grep port-number or service-name]
Options:
-l(listen): Listening state-n(number port): Port number-t(tcp): TCP-u(udp): UDP-p(Program name / PID): Program name / PID. Shows which process is using the communication.-a(all): All. Shows socket information for all states, not only ESTABLISHED.
netstat Usage Example
$ netstat
Active Internet connections
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp4 0 0 192.168.0.1.62123 111.111.11.111.https ESTABLISHED
- Proto: Indicates the protocol used by the communication.
- Recv-Q, Send-Q: Indicates the socket-size buffer used by the communication.
Recv-Qmeans data that has not yet been processed throughrecv(), andSend-Qmeans the size of data sent throughsend()that has not yet been completely sent outside. - Local Address, Foreign Address: The local address and destination address used by the communication.
- (state): Indicates a state such as ESTABLISHED or LISTEN.
NOTE
Port
A port is like an open door on a server and is represented by a number.
When connecting to a server by IP, the server may have multiple ports.
TCP and UDP
TCP: lower speed, bidirectional communication (higher reliability), request-response supported, stream
UDP: higher speed, one-way communication (lower reliability), no request-response, datagram (dgram)
Common netstat options
The netstat options are often used as -lntup.
Other combinations such as -antup, -ltup, and -atup are also used.
/etc/services
/etc/services is a file that defines service names and ports, and it can be used to check port numbers.