netstat Command Cheatsheet

View Categories

netstat Command Cheatsheet

1 min read

The Linux netstat Command #

The Linux netstat command is a powerful networking tool used to display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. Though now often replaced by ss, it remains valuable in many Linux distributions for diagnosing network issues and monitoring system performance.

Key Usage and Syntax of the netstat Command #

The basic syntax of the netstat command is:

netstat [OPTIONS]

  • OPTIONS: Flags to control the behavior and output of netstat.

netstat Command Cheatsheet Table #

Command Description
netstat Displays active connections, routing tables, and interface statistics.
netstat -t Shows only TCP connections.
netstat -u Shows only UDP connections.
netstat -l Displays listening ports and sockets.
netstat -r Displays the routing table.
netstat -i Displays network interface statistics.
netstat -s Shows summary statistics for each protocol.
netstat -p Displays the PID and program name for connections.

Common Use Cases #

View Active Connections #

netstat

Displays all active network connections on the system.

Show TCP Connections #

netstat -t

Filters the output to display only TCP connections.

Monitor Listening Ports #

netstat -l

Lists all ports that are currently in the listening state.

View Routing Table #

netstat -r

Displays the system’s routing table, useful for diagnosing routing issues.

Check Process-Specific Connections #

netstat -p

Shows the process ID (PID) and program name associated with each connection.

Advanced Usage #

Interface Statistics #

netstat -i

Displays detailed statistics about network interfaces, including transmitted and received packets.

Summary Protocol Statistics #

netstat -s

Provides a summary of network statistics, grouped by protocol (TCP, UDP, ICMP, etc.).

Filter by Address #

Combine with grep to filter connections by address:

netstat -an | grep 192.168.1.1

Using netstat with RELIANOID Solutions #

In RELIANOID’s infrastructure, the netstat command is useful for diagnosing connectivity, analyzing load balancer performance, and monitoring system operations.

Monitor Load Balancer Connections #

netstat -tuln | grep ":80"

Displays connections on port 80 to monitor HTTP traffic through the load balancer.

Analyze Backend Service Traffic #

Track connections to backend servers:

netstat -an | grep 10.0.0.5

This shows connections to the backend server at 10.0.0.5.

Debug Proxy Configuration #

Verify that proxy services are running and accepting connections:

netstat -l | grep ":443"

Investigate Network Performance #

Use netstat to collect statistics on dropped packets or retransmissions to diagnose performance bottlenecks:

netstat -s | grep -i "retrans"

Security Considerations #

Always ensure that sensitive information, such as IP addresses and PIDs, is handled securely. Use access controls to prevent unauthorized users from running network diagnostics.

Summary #

The netstat command is a foundational tool for network management and troubleshooting. Though increasingly supplemented by tools like ss, its ease of use and versatility make it a staple for network professionals. RELIANOID incorporates netstat in its diagnostic and monitoring workflows to maintain robust, high-performance networking solutions.

SHARE ON:

Powered by BetterDocs