Ubuntu Linux: Find Out Default Gateway

How do I find out default gateway IP address (default router IP assigned) for my Ubuntu Linux systems?

Use the route or ip command to get default routing table for Ubuntu Linux. Open the terminal and type the following command:
route -n
Sample outputs:

ADVERTISEMENTS

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     0.0.0.0         255.255.255.0   U     2      0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlan0
0.0.0.0         192.168.2.1     0.0.0.0         UG    0      0        0 wlan0

Destination for 0.0.0.0 is set to 192.168.2.1 via wlan0 interface i.e. 192.168.2.1 is default gateway. If you just type the route command with the -n switch it show word default instead of 0.0.0.0:
route
Sample outputs:

 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     *               255.255.255.0   U     2      0        0 wlan0
192.168.1.0     *               255.255.255.0   U     1      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
link-local      *               255.255.0.0     U     1000   0        0 wlan0
default         192.168.2.1     0.0.0.0         UG    0      0        0 wlan0

ip route Command

The following command does the same thing:
ip route show
Sample outputs:

192.168.2.0/24 dev wlan0  proto kernel  scope link  src 192.168.2.3  metric 2 
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.254  metric 1 
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1 
169.254.0.0/16 dev wlan0  scope link  metric 1000 
default via 192.168.2.1 dev wlan0  proto static 
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
1 comment… add one
  • srinivas Jun 24, 2013 @ 7:23

    How to find remote systems gateway from server in the same lan .

    we have multiple gateways in our network like 192.168.1.1 , 192.168.1.2 and 192.168.1.175 .

    how can find out that which system is using which gateway .

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.