21

What is the equivalent of Linux's netstat -tln on OS X?

Options:

-l, --listening (Show only listening sockets. (These are omitted by default.)
--numeric , -n (Show numerical addresses instead of trying to determine symbolic host, port or user names.)
-t, --tcp
4
  • 1
    What does netstat -tln actually do?
    – nohillside
    Nov 24 '14 at 9:04
  • You can just open a Terminar an execute on it. It will work.
    – jherran
    Nov 24 '14 at 9:07
  • 1
    @jherran No, OS X is using a BSD-based netstat which accepts different sets of options.
    – lolski
    Nov 24 '14 at 9:13
  • @patrix in Linux, it lists all open TCP ports on the machine, and whether it listens locally (127.0.0.1) or to remote connections (0.0.0.0).
    – lolski
    Nov 24 '14 at 9:16
23

Should be this command:

sudo lsof -iTCP:$PORT -sTCP:LISTEN 

Who is listening on a given TCP port on Mac OS X?

3
  • 1
    OP question didn't have a port argument, this answer requires one. This gives a useful command apple.stackexchange.com/a/327967/209603
    – goetzc
    Dec 6 '18 at 18:31
  • 4
    @goetzc Just use -iTCP instead of -iTCP:$PORT.
    – Navin
    Dec 24 '18 at 9:00
  • 2
    I would add -P since OP specified -n in their question. Also +1 to @Navin. sudo lsof -iTCP -sTCP:LISTEN -P is closer to netstat -tln
    – seeafish
    Nov 7 '19 at 15:28
18

The closest equivalent you can get on macOS is:

netstat -p tcp -van | grep '^Proto\|LISTEN'
  • tu options are not available, but they can be replaced by either -p tcp or -p udp, although you can't have both at the same time
  • -p option is replaced with -v which effectively gets you PIDs listed
  • -l option is not available, but you can work around it by using -a option (which includes servers in the listing) and grep LISTEN (to filter only for listening)
0
3

For real-time monitoring, try this:

nettop -p 60683

You can also restrict the interface type, like wifi or wired...

nettop -t wifi -n -p 60683

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .