4

$ 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 IPv6 routing table. Which short terminal command can I use to only see the IPv6 routing table?

4

To output only IPv6 info, use the -f address_family option.

Example: netstat -nr -f inet6

From the netstat man page:

−f address_family

Limit statistics or address control block reports to those of the specified address family. The following address families are recognized: inet, for AF_INET, inet6, for AF_INET6 and unix, for AF_UNIX.

  • why use '-nr' instead of just '-r' ? – shouldbeq931 Apr 26 '18 at 11:20
  • @shouldbeq931, you asked, "why use '-nr' instead of just '-r' ?". Well you'd have to ask Pro Backup, as netstat -nr was what's used in the OP and wanted to restrict the output to "only the IPv6 routing table" and hence why I added the -f inet6 option to the command already presented. Obviously, one can use whatever options are needed to produce the desired output for their use case. – user3439894 Apr 26 '18 at 11:46
  • my wording could have been better, I was trying to ask what would be the point of using -n (numbers only) with -r (routing table). – shouldbeq931 May 1 '18 at 22:53
  • @shouldbeq931, I'd suggest you delete your comments to my answer and place a comment under the OP because it is not me that is using the command, only offered a more direct way then piping to another utility. You certainly can try the command with and with out to see the differences in output and how it might fit your own needs. – user3439894 May 2 '18 at 1:38
0
$ netstat -nr | sed -e '1,/Internet6:/d'
Destination                             Gateway                         Flags         Netif Expire
::1                                     ::1                             UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en4/64                           link#4                          UCI             en4
fe80::ae7f:3eff:fee6:5fc7%en4           ac:7f:3e:e6:5f:c7               UHLI            lo0
fe80::%en0/64                           link#5                          UCI             en0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%en4/32                           link#4                          UmCI            en4
ff01::%en0/32                           link#5                          UmCI            en0
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%en4/32                           link#4                          UmCI            en4
ff02::%en0/32                           link#5                          UmCI            en0
  • 1
    You do not need to pipe to sed, just use: netstat -nr -f inet6 – user3439894 Apr 9 '16 at 11:51
  • @user3439894 Your comment is a good answer in my opinion. Why not post it as an answer so I can accept your answer? – Pro Backup Apr 9 '16 at 11:55

You must log in to answer this question.

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