{"id":4126,"date":"2012-10-22T00:29:50","date_gmt":"2012-10-21T16:29:50","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=4126"},"modified":"2023-04-28T09:48:58","modified_gmt":"2023-04-28T09:48:58","slug":"how-to-find-default-gateway-ip-address-on-linux","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-find-default-gateway-ip-address-on-linux\/","title":{"rendered":"How to Find Default Gateway IP address on Linux"},"content":{"rendered":"<p>The default gateway is a network device that allows a computer to communicate with other networks, including the internet. Knowing your default gateway IP address is essential when configuring or troubleshooting network connectivity issues.<\/p>\n<p>In this guide, we will explain different methods to find the default gateway IP address on Linux systems.<\/p>\n<h2>Method 1: Using the route command<\/h2>\n<p>The route command is a classic method for viewing and manipulating the Linux kernel&#8217;s IP routing table. To find the default gateway IP address using the route command, run:<\/p>\n<pre>\r\nroute -n\r\n<\/pre>\n<p>Look for the line with the &#8220;UG&#8221; flags, which stands for &#8220;Up&#8221; and &#8220;Gateway&#8221;. The IP address in the &#8220;Gateway&#8221; column of that line is your default gateway IP address.<\/p>\n<pre>\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags Metric Ref    Use Iface\r\n192.168.1.0     *               255.255.255.0   U     0      0        0 eth0\r\nlink-local      *               255.255.0.0     U     1002   0        0 eth0\r\ndefault         192.168.1.1     0.0.0.0         UG    0      0        0 eth0\r\n<\/pre>\n<h2>Method 2: Using the ip command<\/h2>\n<p>The ip command is a newer and more versatile alternative to the route command. To find the default gateway IP address using the ip command, run:<\/p>\n<pre>\r\nip route show\r\n<\/pre>\n<p>The output will show the default route, which includes the default gateway IP address. Look for a line that starts with &#8220;default via&#8221;, followed by the IP address.<\/p>\n<h2>Method 3: Using the netstat command<\/h2>\n<p>The netstat command is another option for finding the default gateway IP address. To do this, run:<\/p>\n<pre>\r\nnetstat -rn\r\n<\/pre>\n<p>Similar to the route command, look for the line with &#8220;UG&#8221; flags. The IP address in the &#8220;Gateway&#8221; column of that line is your default gateway IP address.<\/p>\n<pre>\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface\r\n192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0\r\n169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0\r\n0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0\r\n<\/pre>\n<h2>Method 4: Checking the \/proc\/net\/route file<\/h2>\n<p>The \/proc\/net\/route file contains routing table information in the Linux kernel. You can find the default gateway IP address by examining this file:<\/p>\n<pre>\r\ncat \/proc\/net\/route\r\n<\/pre>\n<p>Look for the line with the &#8220;00000000&#8221; destination, which represents the default route. The IP address in hexadecimal format in the &#8220;Gateway&#8221; column of that line is your default gateway IP address. You can convert the hexadecimal IP address to a human-readable format using an online converter or a tool like printf.<\/p>\n<h2>Commands Mentioned:<\/h2>\n<ul>\n<li><span class=\"fw-bold\">route -n<\/span> &#8211; Displays the IP routing table using the route command<\/li>\n<li><span class=\"fw-bold\">ip route show<\/span> &#8211; Displays the IP routing table using the ip command<\/li>\n<li><span class=\"fw-bold\">netstat -rn<\/span> &#8211; Displays the IP routing table using the netstat command<\/li>\n<li><span class=\"fw-bold\">cat \/proc\/net\/route<\/span> &#8211; Displays the contents of the \/proc\/net\/route file<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>In this guide, we have demonstrated different methods to find the default gateway IP address on Linux systems. You can use the route, ip, netstat commands, or check the \/proc\/net\/route file to obtain this information. Knowing your default gateway IP address is essential when configuring your network or troubleshooting connectivity issues.<\/p>\n<p>If you have any comments or suggestions for improving this guide, please feel free to share your thoughts. We&#8217;re always eager to learn from our readers and make our content even better.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The default gateway is a network device that allows a computer to communicate with other networks, including the internet. Knowing your default gateway IP address is essential when configuring or&#8230;<\/p>\n","protected":false},"author":6,"featured_media":3673,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2055],"tags":[1328,1986,1536,1595,1985],"class_list":["post-4126","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","tag-default-gateway","tag-ip","tag-linux","tag-netstat","tag-route"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/4126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=4126"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/4126\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/3673"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=4126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=4126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=4126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}