Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am having trouble setting up permenant routes for my network interfaces,

below my config :

ETH0 : 172.23.137.27 Netmask /25 - 255.255.255.128 Gateway – 192.168.126.126

ETH1 : Trunk VLAN - VLAN ID : 305 172.21.107.123 Netmask /28 - 255.255.255.240 Gateway – 172.21.107.113

interfaces config are as follow :


cat ifcfg-eth0 
DEVICE=eth0
HWADDR=2C:59:E5:42:CB:EC
TYPE=Ethernet
#UUID=eefb4ac8-42ba-4fc3-9918-08aae7edef3b
ONBOOT=yes
#NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.126.27
NETMASK=255.255.255.128
GATEWAY=192.168.126.126
#USERCTL=no

cat ifcfg-eth1
DEVICE=eth1
HWADDR=2C:59:E5:42:CB:ED
UUID=68f6c45e-48ba-4b33-8da7-d4d7979eb72d
ONBOOT=yes
BOOTPROTO=none
NM_CONTROLED=no

cat ifcfg-eth1.305 
DEVICE=eth1.305
VLAN=yes
ONBOOT=yes
BOOTPROTO=static
TYPE=Ethernet
IPADDR=172.21.107.123
NETMASK=255.255.255.240
GATEWAY=172.21.107.113
#NM_CONTROLLED=no


route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.21.107.112  0.0.0.0         255.255.255.240 U     0      0        0 eth1.305
192.168.126.0   0.0.0.0         255.255.255.128 U     0      0        0 eth0
192.168.192.0   0.0.0.0         255.255.255.0   U     0      0        0 eth3
0.0.0.0         172.21.107.113  0.0.0.0         UG    0      0        0 eth1.30

The default route works only if i insert it manually : route del default gw 192.168.126.126 eth0

But did not work using : route-eth0 under /etc/sysconfig/network-scripts

share|improve this question

3 Answers 3

up vote 1 down vote accepted

You can specify the default gateway in the file /etc/sysconfig/network like this on its own line: GATEWAY=192.168.0.1

If you need multiple gateways you can create a shell script like this:


#!/bin/sh

ip rule add from 172.21.107.112/28 pref 200 lookup 201
ip route add default via 172.21.107.113 dev eth1 table 201

ip rule add from 192.168.126.0/25 pref 200 lookup 202
ip route add default via 192.168.126.126 dev eth0 table 202

ip route add default nexthop via 192.168.126.126 dev eth0
ip route append default nexthop via 172.21.107.113 dev eth0

ip route flush cache

chmod +x the file and add a call to it in your /etc/init.d/network file

share|improve this answer
    
Hi user16081, I tryed the GATEWAY parameter under /etc/sysconfig/network : did not work. Concerning the shell script, I thought about that but i prefered to have regular solution. I will give it a shout anyway. Thanks for the feedback. –  L1opardo Jan 14 at 20:43

You can specify only one GATEWAY, and if you added the GATEWAY in both interfaces files the GATEWAY of the higher interface number will be used as in your case eth1, which is correct from route -n you have displayed.

If you want to use multiple GATEWAYS you have to use policy routing as suggested in the previous answer.

share|improve this answer

For any network device which is not my default gateway, I usually set the default route flag to no:

DEFROUTE="no"

This seems to work without any issues for my servers with multiple network interfaces. If you then restart your network service or interfaces, you should be able to check the routes to see that this is actually working:

/sbin/route -n

Hopefully this helps.

share|improve this answer
    
Works well with your suggestion, thanks Jason –  L1opardo Jan 14 at 23:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.