How Do I Find Out My Linux Gateway / Router IP Address?

How do I find out my gateway IP for a computer or a network device that allows or controls access to another computer or network under Linux / UNIX-like operating systems? How can I find out my Linux Gateway / Router IP address using the CLI?

A gateway is a network point that acts as an entrance to another network. On the Internet, a node or stopping point can be either a gateway node or a host (end-point) node. Both the computers of Internet users and the computers that serve pages to users are host nodes.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements ip/route/netstat
Est. reading time Less than a minute
The computers that control traffic within your company’s network or at your local Internet service provider (ISP) are gateway nodes. In the network for an enterprise, a computer server acting as a gateway node is often also acting as a proxy server and a firewall server. A gateway is often associated with both a router, which knows where to direct a given packet of data that arrives at the gateway, and a switch, which furnishes the actual path in and out of the gateway for a given packet.

Command to find out my Linux Gateway / Router IP address using ip command

The latest version of all Linux distribution based upon systemd. These Linux distros user can use the ip command to find out router IP address.
ip r
ip route

Command to find out my Linux Gateway Router IP address
From the above output it is clear that is the default gateway IP address.

How to find default Gateway IP in Linux

Some computers might have multiple default gateways. For example, OpenVPN or WireGuard client software might setup gateway for VPN traffic. Another case is static gateway IP address set up for different networks on your system. Here is how to filter out ip command outputs with grep command:
ip r | grep default
How to Find Default Gateway IP in Linux
In this above example and are the default gateway IP address. The gateway with lowest Metric is the first to be searched and used as the default gateway. In this case, has the 50 as metric cost and has the 100 as metric cost. Linux will always use the one with the lowest cost first. So all traffic will be routed using gateway IP address.

Find out Gateway / router IP address under Linux / UNIX using route command

You need to use the router command command. This command can manipulate the kernel’s IP routing tables. It can also be used to print gateway/router IP address. Type the following command to see default gateway.
$ route -n
Sample outputs:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 ra0         UG    0      0        0 ra0 is gateway IP address for our computer. The flag U indicates that route is up and G indicates that it is gateway. You can print gateway name, enter:
$ route
Sample output:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface     *        U     0      0        0 ra0
default         wrt            UG    0      0        0 ra0

Second column prints Gateway hostname / IP address. In our example wrt is gateway.

netstat command example to find out gateway/router IP on Unix/FreeBSD/OpenBSD/macOS

Open a terminal and type the following command:
$ netstat -r -n
Sample outputs:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface         UG        0 0          0 eth1   U         0 0          0 eth1

route and netstat command demo

Animated gif 01: Use route and netstat command to find out default gateway/router IP address on Linux

Animated gif 01: Use route and netstat command to find out default gateway/router IP address on Linux


I hope you learned about finding the default gateway IP in the Linux command-line option. Let us know if you need any more help in the comment section below.

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

🐧 37 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig 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
37 comments… add one
  • Khai Luc May 29, 2008 @ 19:37

    The route command you mentioned helps solve my problem. Thanks!

  • bob Sep 26, 2008 @ 2:54

    nice one

  • Jino Dec 15, 2008 @ 8:40

    Thank you very much for the information……….

  • ndjock-abanda arthur Mar 6, 2009 @ 12:09

    an add , if allowed :
    the command “netstat -r” could also reached the same result.

    thanks nix

  • Umesh Sonune May 22, 2009 @ 5:56

    in our college we have linux proxy server for internet, troughe is a bsnl DSL router. router ip is chenged by our administrator so, i just want to know router ip from my pc which have windows xp for direct internet acsses, can u tell me what i have to do for this? plzzzzzzzzzzz help me.

    • chetan Nov 1, 2012 @ 15:37

      there is a way, use a software called colasoft capsa on your computer. It will give all the IP address in use, now try each IP address you think may be a gateway and you will get to the internet. But I just want to know which BSNL router you are using?

    • chetan Nov 1, 2012 @ 15:38

      There is one more issue that if you are going through linux proxy server, it is difficult to go through it, remember it is difficult not impossible. Just you have to go 1 step ahead your administrator

  • ip address Jun 1, 2009 @ 6:32

    i’m working in corporate office … i want to know ip address of router even some of them told that default gateway is the ip address i telnet it but not connecting … how i have to found the ip address . send to my mail if u have the idea {snip_email_id_removed}

    • chetan Nov 1, 2012 @ 15:40

      Let me clear you can not telnet each device on the network. So try ping command first
      syntex is

  • Robert Jan 27, 2010 @ 0:53

    i tried that but it does not have anything except a (*) in the gateway column. what should I do?

  • vamsi Feb 26, 2010 @ 21:36

    route -nee

  • Veljko Mar 25, 2010 @ 9:12

    How to find gateways of multiple intrefaces? I have two interfaces, one is default, and it’s OK, but I need gateway of second interface …

  • Subnet Ninja Oct 15, 2010 @ 12:50

    For some reason, when I type the router’s IP address in a Firefox address bar, it doesn’t show up… any tips for solving this annoyance?

  • amar Feb 10, 2011 @ 11:53

    router -n

  • Subnet Ninja Feb 15, 2011 @ 19:43


  • Toshiba Feb 17, 2011 @ 3:22

    Hello Vivek,
    Is there a way to get version, model number and other pertinent info of Linksys router via linux? I have an ancient router with the relevant tags scratched up.

    • chetan Nov 1, 2012 @ 15:32

      Just open the router settings, you will get the model number and versions their

  • Luis Jul 2, 2011 @ 18:20

    Thank you .

  • Md.Amanullah Jan 13, 2012 @ 11:36

    thanx…simple way,,,

  • uuryg Feb 3, 2012 @ 10:30


  • Kottha anusha Feb 9, 2012 @ 10:59

    thank you very much .Information is very needful.

  • Ahsan Apr 4, 2012 @ 5:18

    Access Denied Help Me PLzzzzzZZZZzzzzz

    • Matthew Oct 22, 2012 @ 16:48

      Add “sudo” before it.

      • chetan Nov 1, 2012 @ 15:33

        sudo cant work if user is not added in sudoers file

  • Ricardo Meleiro Apr 9, 2012 @ 15:51

    Thanks for the information ! Very helpful!

  • joyce Aug 9, 2012 @ 10:05

    thank u so much… it was very helpful

  • Cristian Sep 27, 2012 @ 10:33

    THX man. learning linux now and i like it. it is so complex, so many things to learn :D

  • Zhei Kent Oct 3, 2012 @ 6:20

    thanks :)

  • dinesh Rao Jul 22, 2013 @ 13:19


  • Walle Apr 2, 2014 @ 5:12

    Hi. I ve seen a couple of very helpful replies here so I was hoping to get an answer to my problem here.

    I am located in Japan and got my self an internet contract. It looks like a DSL router. Though I am not sure what I actually ordered. The usual way to establish connection is only by a CD on Windows. I am pretty sure I can somehow make that darn thing work with Ubuntu as well, I just dont know how.

    If editing a DSL connection to the Network Manager it still doesnt work. But I am not very skilled with that. There I tiped in my User data and thats it. I dont know wether of how to fill out the PPPoE or do it automatically. I also wouldnt know the addresse to fill in here.

    Then I also tried some sudo pppoe config command but that wouldnt help me either. Afterwards I would always have to get to the etc/network/interfaces file to set everything back so that it wouldnt take 10 times longer to start the laptop cause of the wrong network configurations.

    I thought to myself it could be done by accessing the router with an Windows Laptop, but I dont know my neighbours too well to borrow one. However do you think that might be a solution as well ?

    Thanks for your comments in advance


    • jim Aug 6, 2014 @ 10:27

      if you plug the router in and turn it on, plug a network cable between your linux computer, it should connect just by using DHCP… The CDs ISPs give out have bloatware like anti-virus, online backup storage (never enough!), dumb wireless managers etc. A network is a netowrk, and there is no need for all the software on the CD…

  • Amit Saha Sep 14, 2014 @ 13:07

    Nice description…Thanks..

  • David Dykstra May 23, 2015 @ 18:43

    If you have curl installed you can also use:


  • Jj Jun 2, 2015 @ 14:53

    Hello i dont have this ip i have just U 0 0 0 venet0

    what is the good ip ?

  • coderkid Dec 5, 2016 @ 12:02

    i have been told to use ‘ip route’. does this work the same way? sorry if this is obvious i am new to linux
    any help is appreciated.
    thanks in advance

  • Sergio Araujo Mar 2, 2017 @ 18:46

    route -n | awk ‘/UG/ {print $2}’

  • R. H. Feb 8, 2021 @ 9:30

    unbrauchbar und am Ziel vorbei!
    Es soll angezeigt werden, wie IPV4-Adressen mit einem Linuxbefehl angezeigt werden

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum