Page 1 of 1

How to find the IP Address of your Default Gateway

How to find the IP Address of your Default Gateway
   7

While exploring a suggestion of a visitor here, I wanted to find a solid way to retrieve the IP Address of the Default Gateway in a given network.
The most common reason is probably so you can access the modem or router and do some verifications or configurations.

So in this article I’ll show you how to determine the IP address of the default gateway of your network, on several platforms (Window, Linux, macOS, iOS, and Android).




IP Address of a Default Gateway?

What is a Default Gateway? 

In short: it’s the connection to the Internet for all devices in your network. At home, or small offices, this is typically your modem/router.

Wiki – A default gateway, is the node in a computer network, using the Internet protocol suite that serves as the forwarding host (router) to other networks when no other route specification matches the destination IP address of a packet. (more details in this Lifewire article)

There are several reasons why you’d want to know the IP address of your default gateway.

The most common reason is probably so you can access the modem or router and do some verifications or configurations.
But the default gateway can also be instrumental in fixing problems in your network, as it is the “center” of your (small) network.

For my project, I’m actually researching if I can reliably identify a network based on the MAC address of the Default gateway. Once I know the IP address, I can retrieve the MAC address, for example with arp <ip address>  .

Find the IP Address of your Default Gateway

In the next few paragraphs, I’ll describe how to get the IP address of your default gateway for several platforms.
Since most users that are willing to go this deep into their OS, I’ll start with the command line (Shell/Terminal/DOS) method, if available, followed by the graphical method.

Tip: You can try this website WhatsMyRouterIP.com. They will do a good attempt to determine the IP address of your router, which commonly is also your Default Gateway. Depending on the complexity of your Internet connection though, this may produce the wrong result though.

Windows

Command Prompt

When in DOS (Shell, Command Prompt, etc), you’ll end up using the ipconfig command to determine the IP address of the Default Gateway.
Open a Command Prompt (PowerShell works just as well), type “ipconfig”, and press Enter. You’ll see something like this.

Since this is my laptop, I have an Ethernet and a WiFi connection available – both using the same default gateway.
It can happen of course, in a situation like this, that Ethernet and WiFi use a different default gateway IP address. At most homes and small offices though this is not very likely (but not impossible).

Windows Command Prompt - ipconfig

Windows Command Prompt – ipconfig

Tip: you can use the “findstr” function to just get the line(s) with Default Gateway in to like so: ipconfig | findstr "Default Gateway"  .

Graphical User Interface

Finding the Default Gateway through clicking buttons and opening windows, very much depends on the Windows version you’d using.

In short, for Windows 10 and 11: You want to go to the Control Panel Network and Internet Network and Sharing Center

Other Windows versions work in a similar fashion, with possible some minor differences in nomenclature.

Tip: Under Windows 10/11, you can use a shortcut by pressing    R   , type  ncpa.cpl  and press ENTER.

Windows Graphical User Interface

Windows Graphical User Interface

Linux

Terminal

For Linux terminal commands we can use several tools to determine the IP Address of the default gateway.

Caution: ifconfig, netstat, route and arp are considered deprecated 

From what I could find online, some of the very common network tools, like ifconfig, netstat, route and arp, have been considered deprecated for quite a long time already (several decades!) in favor of tools like ip and iproute2. Reference: ifconfig wiki page.

However, these “older” tools are still actively being used and developed.
For some Linux distros this means that these tools may or may not be available on your system, and if you really want to use them, you may have to install them manually.
Some distro’s, for example Arch-Linux variants, refer to the core/net-tools as the package that contains these command line tools.

route

The “route” command can be used as shown below, where the column “Gateway” tells us what the IP address of the Default Gateway is (192.168.1.1):route -n or just route .


1
2
3
4
5
$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 ens33
192.168.1.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33
netstat

The “netstat” command can be used as such, where the column “Gateway” tells us what the IP address is (192.168.1.1): netstat -nr .
Notice the same output as “route” gave us?


1
2
3
4
5
$ netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 ens33
192.168.1.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33
ip

We can also use the “ip” command ip route show or short ip r , where the IP address of your default gateway appears in the first sentence, right after “default via“:


1
2
3
$ ip r
default via 192.168.1.1 dev ens33 proto dhcp metric 100
192.168.1.0/24 dev eth1  proto kernel  scope link  src 192.168.1.100  metric 100

Graphical User Interface

Fortunately, or unfortunately, the Linux GUI and available tools can be very different per distro. My lack of experience with all these distros doesn’t make it any easier. So I’m skipping that …

macOS

Terminal

Some of the Linux Terminal/Shell commands work under macOS, showing some of its “Unix” roots, and still has the older network tools, but also comes with Apple specific tools.

Route

We can use the “route” command under macOS, but it seems to want different parameters to get some info: route -n get default .


1
2
3
4
5
6
7
8
9
10
$ route -n get default                                                                                                                                                                  

   route to: default
destination: default
       mask: default
    gateway: 192.168.1.1
  interface: en0
      flags: <UP,GATEWAY,DONE,STATIC,PRCLONING,GLOBAL>
 recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
       0         0         0         0         0         0      1500         0

As you can see, the line “gateway” gives it away (note: the “-n” parameter is so we see an IP address instead of a network device name).
To make it limit to what we really want, use this: route -n get default | grep gateway .


1
2
3
$ route -n get default | grep gateway                                                                                                                                                    

  gateway: 192.168.1.1
networksetup

This tool, networksetup, can produce some very clean info, but can be a little weird at times.

First we need to know what the name is of our network connection.
These names are not your typical “en0” and “en1” device names. They are looking for names like “Ethernet 1“, “Ethernet 2” or “Wi-Fi” (these name are quite commonly used – mind your spelling!).

A list of these name can be retrieved with networksetup -listallhardwareports  like so:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ networksetup -listallhardwareports                                                                                                

Hardware Port: Ethernet 1
Device: en0
Ethernet Address: 00:3e:e1:c7:0f:e8

Hardware Port: Wi-Fi
Device: en2
Ethernet Address: 80:00:6e:f4:eb:aa

Hardware Port: Thunderbolt 1
Device: en3
Ethernet Address: 82:0e:12:d7:0e:05
 
... etc ...

Now that we know the network name, we can use it to retrieve the IP address of the default gateway.
Shown below with networksetup -getinfo "Ethernet 1"  (use the proper network name for your setup!).
The line “Router:” show the IP address we’re looking for …


1
2
3
4
5
6
7
8
9
10
11
$ networksetup -getinfo "Ethernet 1"  

DHCP Configuration
IP address: 192.168.1.245
Subnet mask: 255.255.255.0
Router: 192.168.1.1
Client ID:
IPv6: Automatic
IPv6 IP address: none
IPv6 Router: none
Ethernet Address: 00:3e:e1:c7:0f:e8
netstat

The “netstat” command can be used as such, where the column “Gateway” tells us what the IP address is (192.168.1.1).
However, on a Mac you will potentially see a long list of entries, and we’d only like to see the default gateway.
For this purpose we will use grep to only show those lines: netstat -nr | grep default .


1
2
3
$ netstat -nr | grep default                                                                                                        17:39
default            192.168.2.1        UGScg             en0      
default            192.168.2.1        UGScIg            en1

Note that you may see a lot more than just these two (like Bluetooth and Thunderbolt connections – even if you do not use them).

Graphical User Interface

You can find the IP address of your default gateway, by opening your macOS Preferences and opening the network settings.
Goto  System Preferences …  Network and select the desired network connection.
The IP Address of your default gateway will now be revealed as “Router:“.

macOS Default Gateway in the GUI

macOS Default Gateway in the GUI

Cell phones and Tablets

I’m just adding iOS and Android just for completeness ….
And with these kind of devices, updates seem more frequent, and in some cases devices will be “stuck” on older older OS versions, making it nearly impossible to cover them all.

iOS

In iOS 15, you’ll find it in Settings Wi-Fi     info icon   next to the word “Router” …

iOS - IP Address Default gateway

iOS – IP Address Default gateway

Android

Unfortunately, I do not have any Android devices near me so I have to write this down from what I have found online.

Go to Settings Network & internet Wi-Fi  – tap the icon next to your active WiFi connection. In the upcoming screen tap “Advanced” which should reveal the “Gateway” …

Android Default Gateway

Android Default Gateway

 

 

Support Us ...


Your support is very much appreciated, and can be as easy as sharing a link to my website with others, or on social media.

Support can also be done by sponsoring me, and even that can be free (e.g. shop at Amazon).
Any funds received from your support will be used for web-hosting expenses, project hardware and software, coffee, etc.

Thank you very much for those that have shown support already!
It's truly amazing to see that folks like my articles and small applications.

Please note that clicking affiliate links, like the ones from Amazon, may result in a small commission for us - which we highly appreciate as well.

Comments


There are 7 comments. You can read them below.
You can post your own comments by using the form below, or reply to existing comments by using the "Reply" button.

  • Aug 10, 2022 - 7:21 AM - Søren Theilgaard - Author: Comment Link

    On macOS I would find the Network Service Order first, like this:

    % networksetup -listnetworkserviceorder
    An asterisk (*) denotes that a network service is disabled.
    (1) USB 10/100/1000 LAN
    (Hardware Port: USB 10/100/1000 LAN, Device: en7)
    (2) USB 10/100/1000 LAN 2
    (Hardware Port: USB 10/100/1000 LAN, Device: en11)
    (3) Wi-Fi
    (Hardware Port: Wi-Fi, Device: en0)
    (4) iPhone USB
    (Hardware Port: iPhone USB, Device: en10)
    (5) Thunderbolt Bridge
    (Hardware Port: Thunderbolt Bridge, Device: bridge0)

    The reason that USB Ethernet devices appears first in the list is that they should override WiFi, if they are connected, At least that is default behaviour.

    This list will also show the device, like en0. Back in the day, Ethernet was the default network enterface, but that has been Wi-Fi (AirPort) for a long time.

    Then I can do as the article describes:

    % networksetup -getinfo "Wi-Fi"
    DHCP Configuration
    IP address: 10.5.0.63
    Subnet mask: 255.255.255.0
    Router: 10.5.0.1
    Client ID: 
    IPv6: Automatic
    IPv6 IP address: none
    IPv6 Router: none
    Wi-Fi ID: ab:cd:ef:12:34:56

    But all of this only find how it is configured. What if we want to know the DHCP value?

    % ipconfig getpacket en0
    op = BOOTREPLY
    htype = 1
    flags = 0
    hlen = 6
    hops = 0
    xid = 0x66890062
    secs = 0
    ciaddr = 10.5.0.63
    yiaddr = 10.5.0.63
    siaddr = 0.0.0.0
    giaddr = 0.0.0.0
    chaddr = bc:d0:74:4c:83:d3
    sname = 
    file = 
    options:
    Options count is 10
    dhcp_message_type (uint8): ACK 0x5
    server_identifier (ip): 10.5.0.1
    lease_time (uint32): 0x7080
    subnet_mask (ip): 255.255.255.0
    router (ip_mult): {10.5.0.1}
    domain_name_server (ip_mult): {10.5.0.1}
    renewal_t1_time_value (uint32): 0x3840
    rebinding_t2_time_value (uint32): 0x6270
    option_224 (opaque): 
    0000 46 47 54 36 30 46 54 4b 32 31 30 39 43 32 31 45 FGT60FTK2109C21E
    0010 00 .               
    end (none): 

    And even more info like this:

    % ipconfig getsummary en0
    <dictionary> {
      BSSID : 88:99:aa:bb:cc:dd
      IPv4 : <array> {
        0 : <dictionary> {
          Addresses : <array> {
            0 : 10.5.0.63
          }
          ChildServiceID : LINKLOCAL-en0
          ConfigMethod : DHCP
          DHCP : <dictionary> {
            LeaseExpirationTime : 08/10/2022 20:26:24
            LeaseStartTime : 08/10/2022 12:26:24
            Packet : op = BOOTREPLY
    htype = 1
    flags = 0
    hlen = 6
    hops = 0
    xid = 0x66890062
    secs = 0
    ciaddr = 10.5.0.63
    yiaddr = 10.5.0.63
    siaddr = 0.0.0.0
    giaddr = 0.0.0.0
    chaddr = bb:dd:aa:cc:11:22
    sname = 
    file = 
    options:
    Options count is 10
    dhcp_message_type (uint8): ACK 0x5
    server_identifier (ip): 10.5.0.1
    lease_time (uint32): 0x7080
    subnet_mask (ip): 255.255.255.0
    router (ip_mult): {10.5.0.1}
    domain_name_server (ip_mult): {10.5.0.1}
    renewal_t1_time_value (uint32): 0x3840
    rebinding_t2_time_value (uint32): 0x6270
    option_224 (opaque): 
    0000 46 47 54 36 30 46 54 4b 32 31 30 39 43 32 31 45 FGT60FTK2109C21E
    0010 00 .               
    end (none): 
            State : BOUND
          }
          IsPublished : TRUE
          Router : 10.5.0.1
          RouterARPVerified : TRUE
          ServiceID : E4B91CCC-1234-1234-1234-9CAABCD45DF3
          SubnetMasks : <array> {
            0 : 255.255.255.0
          }
        }
        1 : <dictionary> {
          ConfigMethod : LinkLocal
          IsPublished : TRUE
          ParentServiceID : E4B91CCC-1234-1234-1234-9CAABCD45DF3
          ServiceID : LINKLOCAL-en0
        }
      }
      IPv6 : <array> {
        0 : <dictionary> {
          ConfigMethod : Automatic
          DHCPv6 : <dictionary> {
            Mode : Idle
            State : Inactive
          }
          IsPublished : TRUE
          RTADV : <dictionary> {
            State : Acquired
          }
          ServiceID : E4B91CCC-1234-1234-1234-9CAABCD45DF3
        }
      }
      InterfaceType : WiFi
      LinkStatusActive : TRUE
      SSID : SSID_name
      Security : WPA2_PSK
    }

    I would expect `ipconfig` as well as `ifconfig` to work on Linux as well.

    Reply

    Søren Theilgaard

    • Aug 11, 2022 - 2:51 AM - Hans - Author: Comment Link

      Hi Søren!

      thank you very much for sharing the additional info – it is very much appreciated. 
      I definitely didn’t realize there was an “ipconfig” under macOS (probably because I’ve gotten used to ifconfig when I started working with Linux and macOS uses this as well).
      Here we see; we learn something new every day.
      Thanks again!

      Reply

      Hans

    • Aug 14, 2022 - 10:46 AM - Hans - Author: Comment Link

      What do you think of this approach?

      route -n get default | grep gateway
      Reply

      Hans

  • Aug 15, 2022 - 4:46 AM - Andrew Comment Link

    Haha, I had to laugh at Figure 4 … “SkyNet” 

    Reply

    Andrew

  • Oct 19, 2022 - 2:32 PM - kedihas445 Comment Link

    Do you mean, i want to change like this option?

    $ networksetup -getinfo “Ethernet 1”

    Reply

    kedihas445

    • Oct 20, 2022 - 3:34 AM - Hans - Author: Comment Link

      Not sure what you’re trying to ask?

      Note: 

      When doing a copy and paste, make sure the double quotes are normal quotes.
      The ones used in your message (probably placed automatically) are not the correct double quotes.
      It should be the ones used here, or use single quotes:

      networksetup -getinfo "Ethernet 1"
      networksetup -getinfo 'Ethernet 1'

      Both assume of course that your Mac has an Ethernet 1.

      Reply

      Hans



Your Comment …

Do not post large files here (like source codes, log files or config files). Please use the Forum for that purpose.

Please share:
*
*
Notify me about new comments (email).
       You can also use your RSS reader to track comments.


Tweaking4All uses the free Gravatar service for Avatar display.