Ubuntu Linux Find Out Default Gateway / Route

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

A router is nothing but device that moves data between computer networks. If you have an internet connection at home or office, you may have a router installed by your ISP. Some people have all-in-one router that connects to the Internet and shares internet and other LAN resources via WiFi. Typically, the first router in your home/office is used by computer and mobile devices to access internet access. It is also known as a default gateway as it is your gateway to the internet. Let us see how to find out your Gateway on Ubuntu.

Ubuntu Linux Finding Out Default Gateway / Route Table

Use the route command or ip command to get default routing table (Gateway) for Ubuntu Linux using the command-line option. Open the terminal and then type the following commands.
route -n
Sample routing table. Always look for UG flag:

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
Here is what we see:

 
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

Possible flags and their meaning in Ubuntu Linux routing table:

  • U : route is up
  • H : target is a host
  • G : use gateway
  • R : reinstate route for dynamic routing
  • D : dynamically installed by daemon or redirect
  • M : modified from routing daemon or redirect
  • A : installed by addrconf
  • C : cache entry
  • ! : reject route

The ip route Command

The following command does the same thing as route is now replaced by the ip tool:
ip route show
My routing table on Ubuntu Linux:

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 

Here is another output showing various interfaces, subnets (CIDR) and their gateways:

$ ip route 
default via 172.26.0.1 dev eth0 proto dhcp src 172.26.9.151 metric 100 
10.147.164.0/24 dev lxdbr0 proto kernel scope link src 10.147.164.1 
172.26.0.0/20 dev eth0 proto kernel scope link src 172.26.9.151 
172.26.0.1 dev eth0 proto dhcp scope link src 172.26.9.151 metric 100 

Want to see default gateway for the 10.8.0.1, 1.1.1.1 and 192.168.2.17 IP address? Try:
$ ip -c route get 10.8.0.1
$ ip -c route get 1.1.1.1
$ ip -c route get 192.168.2.17

Conclusion

We explained how to obtain default gateway and routing able on Ubuntu Linux using route and ip commands. However, we strongly recommend that you use the ip command instead of the route command. Please man pages for more information by typing the following man command:
$ man ip
$ man route

See also


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

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 VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
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> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz