• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / Networking

Network routes in Linux

Published: June 1, 2017 | Modified: June 24, 2020



Learn networking basics in the Linux server. What is the network route, how to check routes, how to define static and default routes in the Linux system?

Network routes in Linux

Network routes on Linux servers are the paths or gateways packets should follow to reach their destinations. Routes can be configured on interface level and system level. The default route is also known as default gateway is the IP where the packet should discover their path if the current network or interface (from which packet originated on the server) does not know the path for destination IP. This article is about discussing network routes in Linux. It will cover how to define the network route for the network interface, where and how to define the default route or default gateway in Linux etc.

How to check current routes on system?

Current routes on system can be viewed using below commands.

# ip route
default via 172.31.0.1 dev eth0
172.31.0.0/20 dev eth0  proto kernel  scope link  src 172.31.4.137
# netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         ip-172-31-0-1.a 0.0.0.0         UG        0 0          0 eth0
172.31.0.0      *               255.255.240.0   U         0 0          0 eth0
# routel
         target            gateway          source    proto    scope    dev tbl
        default         172.31.0.1                                     eth0
    172.31.0.0/ 20                    172.31.4.137   kernel     link   eth0
      127.0.0.0          broadcast       127.0.0.1   kernel     link     lo local
     127.0.0.0/ 8            local       127.0.0.1   kernel     host     lo local
----- output clipped -----

You can observe 172.31.0.1 is defined as default gateway on above system.

How to configure static route in Linux?

In RHEL: You need to edit below parameters in the config file /etc/sysconfig/network-scripts/route-ethX.

GATEWAY=10.10.0.1
NETMASK=255.0.0.0
IPADDR=10.10.0.22

where –

  • gateway is the default gateway for this interface
  • the netmask is a subnet mask value
  • ipaddr is the IP address of this interface

Caution : Do not change gateways on live production system.

In Debian: You can put your route in the file /etc/network/interfaces under the intended interface.

auto eth0
iface eth0 inet static
      address 10.10.0.22
      netmask 255.0.0.0
      up route add -net 10.10.0.0 netmask 255.0.0.0 gw 10.10.0.1

In all Linux systems you can use ip route command to define the static route. Command syntax is :

# ip route ip-address via dest-address

where, ip-address is IP of host or interface and dest-address is next HOP address i.e. route IP

How to configure default gateway in Linux?

In RHEL: Define default gateway IP against GATEWAY parameter in /etc/sysconfig/network file and then restart network service.

In Debian: Define default gateway IP against gateway parameter in /etc/network/interfaces file and then restart network service.

Or you can try these commands on any Linux (ex gateway as 10.10.0.1).

# ip route add default via 10.10.0.1
# route add default gw 10.10.0.1

Once set verify the default gateway with commands shown at the beginning of this article.

⇠ Previous article
All you need to know about hostname in Linux
Next article ⇢
How to create RAM disk in Linux

Related stuff:

  • 4 step Network bonding / teaming configuration in Linux
  • How Docker container DNS works
  • Basics of iptables – Linux firewall
  • How to redirect port in Linux using iptables
  • How to forward port using iptables in Linux
  • Configuration of iptables policies

Filed Under: Networking Tagged With: default gateway in rhel, default gateway in ubuntu, how to set static route in linux, how to set static route in rhel, how to set static route in ubuntu

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2026 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.