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. Default route also known as default gateway is the IP where packet should discover their path if current network or interface (from which packet originated on server) does not know path for destination IP. This article is about discussing network routes in Linux. It will cover how to define network route for network interface, where and how to define 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.
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 config file /etc/sysconfig/network-scripts/route-ethX.
where –
  • gateway is default gatway for this interface
  • netmask is subnet mask value
  • IPaddr is IP address of this interface
Caution : Do not change gateways on live production system.
In Debian : You can put your route in file /etc/network/interfaces under intended interface.
In all Linux systems you can use ip route command to define static route. Command syntex 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).
Once set verify default gateway with commands shown in beginning of this article.
SHARE

sangeethakumar

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment