-->
🏠 🔍
SHAREOLITE

How to Configure static ethernet Routes in Linux

In this post, we show you how to configure a static route for LAN ethernet interfaces on a Redhat Linux platform. This can be acheived using two procedures as explained below -


  •     Procedure 1     


Step 1
Login as root user
vim /etc/sysconfig/network-scripts/route-eth0

Step 2
Add the lines having the destination address , netmask and gateway details and save the file.
ADDRESS0=10.30.10.108
NETMASK0=255.255.255.255
GATEWAY0=10.30.19.254

ADDRESS1=10.30.10.109
NETMASK1=255.255.255.255
GATEWAY1=10.30.19.1

Step 3
As root user execute the command
service network restart


Verify whether routes are existing after restart by typing the command as root user
route       OR
netstat -nr


  •    Procedure 2    


Step 1: 

Execute the below command as root user to view the existing routes

[root@shareolite ~]# ip route show
10.2.10.5 via 10.2.10.17 dev eth3
10.2.10.5 via 10.2.10.17 dev eth1
10.1.4.195 via 80.4.6.254 dev eth0
10.2.10.6 via 10.2.18.17 dev eth3
10.2.10.6 via 10.2.17.17 dev eth1
10.2.3.10 via 10.2.18.17 dev eth3
10.2.3.10 via 10.2.17.17 dev eth1
10.2.3.26 via 10.2.18.17 dev eth3
10.2.3.26 via 10.2.17.17 dev eth1
10.2.18.16/29 dev eth3  proto kernel  scope link  src 10.2.18.18
10.2.17.16/29 dev eth1  proto kernel  scope link  src 10.2.17.18
169.254.0.0/16 dev eth3  scope link
192.0.0.0/8 dev eth0  proto kernel  scope link  src 192.2.75.17
default via 203.116.219.111 dev eth2

Now lets say you want to create static routes for eth3, execute the below command and grep for port eth3.

[root@shareolite ~]# ip route show |grep eth3
10.2.10.5 via 10.2.10.17 dev eth3
10.2.10.6 via 10.2.18.17 dev eth3
10.2.3.10 via 10.2.18.17 dev eth3
10.2.3.26 via 10.2.18.17 dev eth3
10.2.18.16/29 dev eth3  proto kernel  scope link  src 10.2.18.18
169.254.0.0/16 dev eth3  scope link


Step 2 :

vim /etc/sysconfig/network-scripts/route-eth3  and copy the lines displayed.
Save the file.


Step 3 :

Execute command , service network restart

Verify whether routes are existing after restart by typing the command as root user
route       OR
netstat -nr


Hope this helps to some techies.

Comments

–>