$ netstat -nr is great for outputting the Mac OS X IP routing tables.

However its output is long as it contains both IPv4 and IP6 routing tables.

Sometimes I wish to output only the IPv4 routing table. I wish to use short terminal command to only see the IPv4 routing table.

My best result is $ netstat -nr | sed -e '1,3d;/Internet6:/,$d;/^$/d'

Can this command be shortened?

  • 3
    Sorry, but I just can't help myself... One should read the manual page of a given command to see all that it is capable of before trying to figure out how to achieve desired output via piping to other commands. I'm saying this as much for myself as anyone else, because just recently I found myself in a similar situation. I was piping the output of lynx to awk when there was an option in lynx that was doing what awk was. I normally read the man pages however I'll admit I was just being lazy in this case. :) Commented Apr 9, 2016 at 13:11
  • @user3439894 I did read the manual pages multiple times. Could not find the option I needed.
    – Pro Backup
    Commented Apr 9, 2016 at 13:53
  • I skimmed the lynx man page for the option I missed however at 16 pages vs. 4 pages for netstat I didn't feel too bad when it was pointed out to me. :) BTW I was not the down-vote on your question. Commented Apr 9, 2016 at 14:41
  • 2
    Even now 1 month after I have asked, I couldn't remember the options, and I couldn't figure out the correct commands from the man pages. Luckily I have asked and that the question is still not deleted, so I can find the answer again.
    – Pro Backup
    Commented May 13, 2016 at 7:55

1 Answer 1

$ netstat -nr -f inet
Routing tables

Destination        Gateway            Flags        Refs      Use   Netif Expire
default        UGSc           10        0     en4
default             UGScI           0        0    ppp0
10                 ppp0               USc             0        0    ppp0
  • 2
    my usual follow-up question with network commands: why is it like this? In this case, what does inet have to do with IPv4? Why isn't this option more straightforward, like curl's -4 or --ipv4?
    – Mike B
    Commented Jul 12, 2022 at 19:45
  • its straightforward - inet for tcp4, inet6 for tcp6. In times before tcp6 - nobody knows about tcp6. And now it exists for backward compatibility
    – Reishin
    Commented Dec 13, 2022 at 5:12

You must log in to answer this question.

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