OS X: Find Network Gateway using the Comand Line

This is a bit more complex than it should be; I was hoping networksetup would make this easier but, alas. Using netstat -nr appears to be the best way to find your gateway from the command line:

netstat -nr | grep ‘^default’ | awk ‘{ print $2 }’

If you haven’t played around with networksetup, I recommend checking out networksetup -getinfo “Airport” and networksetup -listnetworkserviceorder.

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, and holds a number of certifications, including those relating to SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in OS X & iPhone

Leave a Reply

Your email address will not be published. Required fields are marked *

*