Page 1 of 1

How to find the IP Address of your Default Gateway

How to find the IP Address of your Default Gateway
   0

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         <strong>192.168.1.1</strong>     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         <strong>192.168.1.1</strong>     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.

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 no comments yet.
You can post your own comments by using the form below, or reply to existing comments by using the "Reply" button.



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.