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 PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain RealCajunRecipes.com in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. 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 *