netstat -an -p tcpAll TCP sockets with numeric addresses, including listening ones.
When to use it
Use netstat to see the routing table (which gateway and interface traffic uses), count connections by state, or check interface error counters. To find which app owns a socket, use lsof.
Steps
List connections
-a includes listening sockets, -n keeps addresses numeric, -p limits the protocol.netstat -an -p tcpOnly listening ports
Filter with grep.netstat -an -p tcp | grep LISTENRouting table
-r shows routes; -f inet or inet6 picks the family.netstat -rn -f inetInterface statistics
-i shows packets and errors per interface; -b adds bytes.netstat -ibLook up one route
route get shows which gateway and interface a destination uses.route -n get 1.1.1.1
Output explained
The routing table on a Mac on Wi-Fi:
Destination Gateway Flags Netif Expire
default 192.168.1.1 UGScg en0
192.168.1/24 link#14 UCS en0 !
192.168.1.1 72:1d:18:77:9c:11 UHLWI en0 717
- default is the route for everything not listed: via the router on en0.
- 192.168.1/24 link#14 means the local subnet is reached directly on that interface.
- Flags: U up, G gateway, S static, H host route, L link-layer address, W cloned, I interface-scoped.
Connections from netstat -an look like tcp4 0 0 192.168.1.23.60330 17.253.144.10.443 ESTABLISHED: macOS separates the port with a dot.
Options and variations
| Flag | Meaning | Example |
|---|---|---|
| -a | Include listening sockets | netstat -a |
| -n | Numeric addresses and ports | netstat -an |
| -p PROTO | Only tcp, udp, icmp… | netstat -an -p udp |
| -r | Routing table | netstat -rn |
| -f inet|inet6 | Address family | netstat -rn -f inet6 |
| -i / -ib | Interface packet / byte counters | netstat -ib |
Common errors
| Error | Cause | Fix |
|---|---|---|
| No process names | macOS netstat can't show the owning process | Use lsof -nP -i instead. |
| Two default routes | Several interfaces (Wi-Fi, Ethernet, VPN) are up | The first one in service order wins; check with route -n get default. |
Do it in the app
LightAtom's connections view shows netstat's connection list with the process, domain and bytes for each, and its Ports view the listening sockets with their owners.
Frequently asked questions
How do I see open ports with netstat on a Mac?
Run netstat -an -p tcp | grep LISTEN. It shows listening addresses and ports, but not the process; use lsof -nP -iTCP -sTCP:LISTEN for that.
What does netstat -rn show?
The routing table with numeric addresses: the default gateway, local subnets and host routes, and the interface each uses.
Why doesn't netstat -b work like on Windows?
On Windows -b shows process names. On macOS -b shows byte counts with -i. Process information comes from lsof on a Mac.