How to Find Your Network Gateway IP Address in Linux

When troubleshooting network connectivity issues on a Linux machine, one of the first pieces of information you need is your default gateway IP address. The gateway is typically your local router — the device responsible for directing traffic from your local network out to the internet. Knowing this address is essential for diagnosing whether a connectivity problem lies within your local network or further upstream with your internet service provider.

If you can ping your gateway but cannot reach external websites, the issue is likely with your ISP or DNS configuration. If you cannot even reach the gateway, the problem is on your local network — perhaps a cable issue, Wi-Fi disconnection, or incorrect IP configuration.

Method 1: Using the ip Command (Recommended)

The ip command is the modern standard for network configuration and analysis in virtually all current Linux distributions. It has completely replaced older tools like ifconfig and route in most modern installations.

  1. Open your terminal emulator (Ctrl + Alt + T on Ubuntu-based distributions).
  2. Type the following command and press Enter:
    ip route

You will see several lines of output showing your system’s routing table. Look for the line beginning with the word default:

default via 192.168.1.1 dev eth0 proto dhcp metric 100

The IP address immediately following the word via (in this example, 192.168.1.1) is your default gateway.

Understanding the Output

Field Meaning
default This is the default route — where traffic goes when no specific route matches
via 192.168.1.1 The gateway IP address (your router)
dev eth0 The network interface used to reach the gateway (eth0, wlan0, etc.)
proto dhcp The route was learned via DHCP (automatic configuration from the router)
metric 100 The route priority — lower numbers are preferred when multiple routes exist

If you want to see only the default gateway without the full routing table, you can filter the output:

ip route | grep default

Or extract just the IP address:

ip route | grep default | awk '{print $3}'

Method 2: Using the route Command (Legacy)

The route command is a legacy tool that may not be installed by default on newer distributions but is still widely available and useful on older systems.

  1. Open your terminal.
  2. Type the following command and press Enter:
    route -n

The -n flag tells the command to display numerical IP addresses instead of attempting DNS resolution, which makes the output faster and easier to read.

A table will appear with columns including Destination, Gateway, Genmask, and others. Look for the row where the Destination column contains 0.0.0.0 — this represents the default route. The IP address in the Gateway column on that row is your router’s address.

If the route command is not found, you may need to install the net-tools package:

sudo apt install net-tools

Method 3: Using the netstat Command

Another legacy option that provides similar routing table information:

  1. Open your terminal.
  2. Type the following command and press Enter:
    netstat -rn

The -r flag displays the routing table, and -n ensures numerical output. As with the route command, locate the row with destination 0.0.0.0 and read the Gateway column.

Method 4: Using nmcli (NetworkManager CLI)

If your system uses NetworkManager (common on Ubuntu, Fedora, and most desktop distributions), you can use its command-line interface:

nmcli device show | grep IP4.GATEWAY

This will output something like:

IP4.GATEWAY: 192.168.1.1

For more detailed connection information:

nmcli connection show --active

Method 5: Checking the DHCP Lease

If your IP address was assigned automatically via DHCP, you can inspect the lease information:

cat /var/lib/dhcp/dhclient.leases

Look for the option routers line within your active lease — this contains your gateway address. The exact file location may vary depending on your distribution and DHCP client.

How to Test Connectivity to Your Gateway

Once you know your gateway IP address, you can test connectivity to it using ping:

ping -c 4 192.168.1.1

The -c 4 flag sends exactly four ping packets and then stops. If you receive replies, your connection to the local network is working correctly. If the ping fails, the issue is between your computer and the router.

Diagnostic Sequence for Network Problems

When troubleshooting, follow this sequence to isolate the problem:

  1. Ping your gateway: ping -c 4 192.168.1.1 — tests local network connectivity.
  2. Ping an external IP: ping -c 4 8.8.8.8 — tests internet connectivity bypassing DNS.
  3. Ping a domain name: ping -c 4 google.com — tests DNS resolution.
Result Likely Problem
Gateway ping fails Local network issue (cable, Wi-Fi, IP configuration)
Gateway works, external IP fails Router or ISP issue
External IP works, domain fails DNS configuration problem
All three work Application-specific issue

Multiple Gateways and Advanced Routing

Some systems may have multiple gateways — for example, a wired connection and a VPN connection each with their own gateway. The ip route command will list all routes, and the one with the lowest metric value takes priority.

To see all routes including their metrics:

ip route show

If you need to manually add or change a default gateway (useful for static IP configurations):

sudo ip route add default via 192.168.1.1 dev eth0

To remove a default gateway:

sudo ip route del default

Note that manual route changes made with ip route are temporary and will not survive a reboot. For permanent configuration, edit your network configuration files or use NetworkManager.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.