How to Use the Netstat Command on Mac (2024)

What to Know

  • To run netstat and see detailed data about your Mac's network, open a new Terminal window, type netstat, and press Enter.
  • Limit netstat's output with flags and options. To see netstat's available options, type man netstat at the command prompt.
  • Use the lsof command to make up for netstat's missing or limited functionality, including displaying any files currently open in any apps.

This article explains how to run the netstat Terminal command in macOS so that you can see detailed information about your Mac's network communications, including the ways your Mac is talking to the outside world, across all ports and all applications.

How to Run Netstat

Learning how to use netstat can help you understand the connections your computer is making and why. The netstat command is available on Macs by default. You don't need to download or install it.

To run netstat:

  1. Go to Finder > Go > Utilities.

    How to Use the Netstat Command on Mac (1)

  2. Double-click Terminal.

    How to Use the Netstat Command on Mac (2)

  3. In the new Terminal window, type netstat and press Return (or Enter) to execute the command.

    How to Use the Netstat Command on Mac (3)

  4. A huge amount of text will begin scrolling on your screen. If you don't use any of the available flags (see below), netstat reports the active network connections on your Mac. Considering the number of functions a modern network device performs, you can expect the list to be lengthy. A standard report can run over 1,000 lines.

    How to Use the Netstat Command on Mac (4)

Netstat Flags and Options

Filtering netstat's output is essential to understanding what's happening on your Mac's active ports. Netstat's built-in flags allow you to set options, limiting the command's scope.

To see all netstat's available options, type man netstat at the command prompt to reveal netstat's man (short for "manual") page. You can also view an online version of netstat's man page.

Syntax

It's important to note that netstat on macOS doesn't work the same way as netstat on Windows and Linux. Using flags or syntax from those implementations of netstat may not result in the expected behavior.

To add flags and options to netstat on macOS, use the following syntax:

netstat [-AabdgiLlmnqrRsSvWx] [-c queue] [-f address_family] [-I interface] [-p protocol] [-w wait]

If the above shorthand looks completely incomprehensible, learn how to read command syntax.

Useful Flags

Here are some of the most commonly used flags:

  • -a includes server ports in netstat's output, which are not included in the default output.
  • -g displays information associated with multicast connections.
  • -I interface provides packet data for the specified interface. All available interfaces can be viewed with the -i flag, but en0 is typically the default outgoing network interface. (Note the lowercase letter.)
  • -n suppresses the label of remote addresses with names. This speeds up netstat's output while eliminating only limited information.
  • -p protocol lists traffic associated with a specific networking protocol. The full list of protocols is available at /etc/protocols, but the most important ones are udp and tcp.
  • -r displays the routing table, showing how packets are routed around the network.
  • -s shows the network statistics for all protocols, whether or not the protocols are active.
  • -v increases verbosity, specifically by adding a column showing the process ID (PID) associated with each open port.

Netstat Examples

Consider these examples:

netstat -apv TCP

This command returns only TCP connections on your Mac, including open ports and active ports. It also uses verbose output, listing the PIDs associated with each connection.

netstat -a | grep -i "listen"

This combination of netstat and grep reveals open ports, which are ports that are listening for a message. The pipe character | sends the output of one command to another command. Here, the output of netstat pipes to grep, letting you search it for the keyword "listen" and find the results.

Accessing Netstat Through Network Utility

You also can access some of netstat's functionality through the Network Utility app, which is included in macOS versions up to Catalina (it's not included in Big Sur).

To get to Network Utility, type Network Utility into Spotlight Search to launch the app, then select the Netstat tab to access the graphical interface.

How to Use the Netstat Command on Mac (5)

Options within Network Utility are more limited than those available through the command line. Each of the four radio button selections runs a preset netstat command and displays the output.

The netstat commands for each radio button are as follows:

  • Display routing table information runs netstat -r.
  • Display comprehensive network statistics for each protocol runs netstat -s.
  • Display multicast information runs netstat -g.
  • Display the state of all current socket connections runs netstat.

How to Use the Netstat Command on Mac (6)

Supplementing Netstat With Lsof

The macOS implementation of netstat doesn't include much of the functionality users expect and need. Although it has its uses, netstat isn't as useful on macOS as it is on Windows. A different command, lsof, replaces much of the missing functionality.

Lsof displays files currently open in apps. You can also use it to inspect app-associated open ports. Run lsof -i to see the list of applications communicating over the internet. This is typically the goal when using netstat on Windows machines; however, the only meaningful way to accomplish that task on macOS is not with netstat, but with lsof.

How to Use the Netstat Command on Mac (7)

Lsof Flags and Options

Displaying every open file or internet connection is typically verbose. That's why lsof comes with flags for restricting results with specific criteria. The most important ones are below.

For information on more flags and technical explanations of each, check out lsof's man page or run man lsof at a Terminal prompt.

  • -i displays open network connections and the name of the process that is using the connection. Adding a 4, as in -i4, displays only IPv4 connections. Adding a 6 instead (-i6) displays only IPv6 connections.
  • The -i flag also can be expanded to specify further details. -iTCP or -iUDP returns only TCP and UDP connections. -iTCP:25 returns only TCP connections on port 25. A range of ports can be specified with a dash, as it -iTCP:25-50.
  • Using -i@1.2.3.4 returns only connections to the IPv4 address 1.2.3.4. IPv6 addresses can be specified in the same fashion. The @ precursor can also be used to specify hostnames in the same way, but both remote IP addresses and hostnames cannot be used simultaneously.
  • -s typically forces lsof to display file size. But when paired with the -i flag, -s works differently. Instead, it allows the user to specify the protocol and status for the command to return.
  • -p restricts lsof to a particular process ID (PID). Multiple PIDs can be set by using commons, such as -p 123,456,789. Process IDs can also be excluded with a ^, as in 123,^456, which would specifically exclude PID 456.
  • -P disables the conversion of port numbers to port names, speeding up output.
  • -n disables the conversion of network numbers to hostnames. When used with -P above, it can significantly speed up lsof's output.
  • -u user only returns commands owned by the named user.

lsof Examples

Here are a few ways to use lsof.

lsof -nP -iTCP@lsof.itap:513

This complex-looking command lists the TCP connections with the hostname lsof.itap and the port 513. It also runs lsof without connecting names to IP addresses and ports, making the command run noticeably faster.

lsof -iTCP -sTCP:LISTEN

This command returns every TCP connection with the status LISTEN, revealing the open TCP ports on the Mac. It also lists the processes associated with those open ports. This is a significant upgrade over netstat, which lists PIDs at most.

How to Use the Netstat Command on Mac (8)

sudo lsof -i -u^$(whoami)

How to Use the Netstat Command on Mac (9)

Other Networking Commands

Other Terminal networking commands that might be of interest in examining your network include arp, ping, and ipconfig.

FAQ

  • How do I find out what's running through a specific port on my Mac?

    First, you need to figure out the number of the port you want to check. Then open terminal and type in lsof -i:[port number] to see what's running off of that port.

  • Can I find out a MAC address with netstat?

    You should see a computer's MAC address through netstat as the "local" address. It will be grouped with TCP (protocol) and the IP address (foreign).

Was this page helpful?

Thanks for letting us know!

Get the Latest Tech News Delivered Every Day

Subscribe

Tell us why!

How to Use the Netstat Command on Mac (2024)
Top Articles
Groen beleggen met belastingvoordeel | Consumentenbond
Wie hoch ist das Risiko bei Kryptowährungen? • WeltSparen
Instructional Resources
Online Reading Resources for Students & Teachers | Raz-Kids
Martha's Vineyard Ferry Schedules 2024
Google Jobs Denver
Geodis Logistic Joliet/Topco
Free Robux Without Downloading Apps
Best Cav Commanders Rok
Infinite Campus Parent Portal Hall County
A.e.a.o.n.m.s
Hillside Funeral Home Washington Nc Obituaries
Cnnfn.com Markets
Craigslist Edmond Oklahoma
Louisiana Sportsman Classifieds Guns
Mikayla Campinos Laek: The Rising Star Of Social Media
Evil Dead Rise - Everything You Need To Know
Dover Nh Power Outage
The best firm mattress 2024, approved by sleep experts
Laveen Modern Dentistry And Orthodontics Laveen Village Az
U Of Arizona Phonebook
Craigslistodessa
Best Boston Pizza Places
How To Find Free Stuff On Craigslist San Diego | Tips, Popular Items, Safety Precautions | RoamBliss
Meet the Characters of Disney’s ‘Moana’
Nearest Ups Ground Drop Off
Bayard Martensen
Allegheny Clinic Primary Care North
Fedex Walgreens Pickup Times
Chase Bank Cerca De Mí
Sedano's Supermarkets Expands to Orlando - Sedano's Supermarkets
Exploring TrippleThePotatoes: A Popular Game - Unblocked Hub
Lucky Larry's Latina's
Mp4Mania.net1
Retire Early Wsbtv.com Free Book
Frcp 47
Wsbtv Fish And Game Report
Sunrise Garden Beach Resort - Select Hurghada günstig buchen | billareisen.at
Dogs Craiglist
Devon Lannigan Obituary
Clausen's Car Wash
How Big Is 776 000 Acres On A Map
Cabarrus County School Calendar 2024
Streameast Io Soccer
Craigslist Pet Phoenix
Maplestar Kemono
Wpne Tv Schedule
Dineren en overnachten in Boutique Hotel The Church in Arnhem - Priya Loves Food & Travel
What Time Do Papa John's Pizza Close
Latest Posts
Article information

Author: Madonna Wisozk

Last Updated:

Views: 6156

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Madonna Wisozk

Birthday: 2001-02-23

Address: 656 Gerhold Summit, Sidneyberg, FL 78179-2512

Phone: +6742282696652

Job: Customer Banking Liaison

Hobby: Flower arranging, Yo-yoing, Tai chi, Rowing, Macrame, Urban exploration, Knife making

Introduction: My name is Madonna Wisozk, I am a attractive, healthy, thoughtful, faithful, open, vivacious, zany person who loves writing and wants to share my knowledge and understanding with you.