Quickly Get a Router IP Address from the Command Line

Mar 23, 2012 - 7 Comments

Router IP Address

To quickly retrieve the IP address of the router you are connected through, type the following at the command line:

netstat -rn |grep default

The result will look something like this, showing the router IP directly after “default”:

default 192.168.1.1 UGSc 108 0 en0

netstat will work for both wired and wireless connections, the difference of which will be shown as the interface. These are typically en0 and en1, though the port interfaces will vary slightly with Macs that don’t include ethernet ports or AirPort wireless card, and for Macs with only one form of network connectivity it will almost always be en0.

For users who don’t want to bother with the command line, the router IP can also be found from the Network system preference panel.

Thanks to Hans and Jen for the tip

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: William Pearson in Command Line, Mac OS X, Tips & Tricks

7 Comments

» Comments RSS Feed

  1. Nyah says:

    Any way to change it?

  2. Andy says:

    Why not just finish off the command…

    `netstat -rn | grep default | awk {‘print$2′}`

  3. Jason Bush says:

    Check out the MAN page for networksetup
    That should get you started.

  4. maddler says:

    use:

    netstat -rn |grep default | awk {‘print $2′}

    this will print gateway IP only.

  5. maddler says:

    sorry, apostrophe characters among {} was replaced

  6. light says:

    is there any way I can tell which wireless network is being used?
    I have 2. I can see them both in airport utility
    and it looks like they use different IP address
    eg the wireless network with Internet uses ip starting with 195. etc..
    eg wirelessnetwork without Internet uses ip address starting with 10.0.0 etc…

    —–
    I ask as trying desperately to work put how to capture mb/data usage on the Internet wireless only
    —-
    I was using surplus monitor tool but it doesn’t differentiate between wireless network.

    I hope I explained myself clearly as not very technical at all
    but would love to monitory mb Internet usage as share broadband with upstairs.
    —-
    on 10.6x with MacBook pro timecapsule and iphone
    thankyou

  7. cirrus says:

    You can also try:
    route get default | grep gateway|awk ‘{print $2}’

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates