Skip to content

netstat command in MacOS

The netstat command in MacOS allows users to display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. It helps troubleshoot network issues and monitor network activity effectively.

netstat Syntax:

Terminal window
netstat [ options ] [ parameters ]

MacOS netstat Options:

OptionDescription
-a, —allShow both listening and non-listening sockets.
-t, —tcpDisplay TCP protocol sockets.
-u, —udpDisplay UDP protocol sockets.
-i, —interfacesShow network interfaces.
-r, —routingDisplay the kernel routing tables.
-s, —statisticsDisplay network statistics.
-p, —programsShow process using sockets.
-A family, —address-family=familyShow only sockets of specified address family: inet, inet6, unix.
-n, —numericShow numerical addresses.
-l, —listeningShow only listening sockets.
-c, —continuousContinuously display information.
-F form, —fib=filenameDisplay routing information from file.

netstat Parameters:

ParameterDescription
destinationDisplay routing information for the specified destination.
interfaceDisplay information specific to the given network interface.
protocolDisplay information for the specified protocol (tcp, udp, etc).
hostDisplay information for the specified host.
portDisplay information for the specified port.

How to use netstat command:

Display All Listening Ports

Terminal window
netstat -l

Display a list of all listening ports on the system.

Display Statistics for All Protocols

Terminal window
netstat -s

Show statistics for all networking protocols.

Display Kernel Routing Table

Terminal window
netstat -r

Show the kernel routing table.

Display PID and Program for Each Connection

Terminal window
netstat -p

Display the PID and program name for each connection.

Display Network Interface Statistics

Terminal window
netstat -i

Display network interface statistics.

Display Only IPv4 Connections

Terminal window
netstat -4

Show only IPv4 connections.

Display Only TCP Connections

Terminal window
netstat -t

Show only TCP connections.

Display All Listening UDP Ports

Terminal window
netstat -u

Show all listening UDP ports on the system.

How do I use netstat in MacOS?

To use the netstat command in MacOS, execute the following command:

Terminal window
netstat --option <value>

How can I display active network connections with netstat in MacOS?

To display active network connections in MacOS using netstat, run the following command:

Terminal window
netstat -an

How do I check for listening ports with netstat on MacOS?

To check for listening ports in MacOS using netstat, use the following command:

Terminal window
netstat -tuln

How to show the PID/Program name along with network connections in MacOS using netstat?

To display the PID/Program name along with network connections in MacOS using netstat, execute the command below:

Terminal window
netstat -ap

How do I filter netstat output by a specific protocol in MacOS?

To filter netstat output by a specific protocol in MacOS, use the following command:

Terminal window
netstat -t -p tcp

How can I show the routing table in MacOS using netstat?

To display the routing table in MacOS using netstat, run the following command:

Terminal window
netstat -nr

How to display statistics for each protocol using netstat in MacOS?

To display statistics for each protocol in MacOS using netstat, execute the following command:

Terminal window
netstat -s

How do I show both listening and non-listening sockets in MacOS using netstat?

To show both listening and non-listening sockets in MacOS using netstat, use the following command:

Terminal window
netstat -a

How can I display only the numeric values in the output of netstat on MacOS?

To display only numeric values in the output of netstat in MacOS, run the following command:

Terminal window
netstat -n

Applications of the netstat command

  • Display network connections
  • Display routing table information
  • Display interface statistics
  • Display multicast group information
  • Display network protocol statistics