Hi,
How can I define static routes to be created at boot time with a specific metric? I have two NICs that ultimately end up at the same peer, but literally go through two completely different networks. IOW, each NIC connects to a different layer 3 device.
Also, note that the machine actually has three total NICs: the third is the owner of the default route. The two mentioned above are for a specialized sub net.
What I basically need to be able to do is this: route add -host h1 gw g1 metric 0 route add -host h1 gw g2 metric 10
Notice that everything is the same except the gateway and metric. I could put this in /etc/rc.local, but was wondering if there's a cleaner way to do it in e.g. the network-scripts directory.
Thanks, Matt
On 12/7/2011 10:03 AM, Matt Garman wrote:
Hi,
[...]
What I basically need to be able to do is this: route add -host h1 gw g1 metric 0 route add -host h1 gw g2 metric 10
Notice that everything is the same except the gateway and metric. I could put this in /etc/rc.local, but was wondering if there's a cleaner way to do it in e.g. the network-scripts directory.
If you create files in the /etc/sysconfig/network-scripts directory named according to the scheme
route-eth0 route-eth1 route-eth2
it will execute each line in the files as
/sbin/ip route add <line>
when each interface is brought up.
Look in the /etc/sysconfig/network-scripts/ifup-routes script for all the gory details and features.
Adding additional info for posterity, and in case anyone else runs across this...
On Wed, Dec 7, 2011 at 12:28 PM, Benjamin Franz jfranz@freerun.com wrote:
On 12/7/2011 10:03 AM, Matt Garman wrote:
Hi,
[...]
What I basically need to be able to do is this: route add -host h1 gw g1 metric 0 route add -host h1 gw g2 metric 10
Notice that everything is the same except the gateway and metric. I could put this in /etc/rc.local, but was wondering if there's a cleaner way to do it in e.g. the network-scripts directory.
If you create files in the /etc/sysconfig/network-scripts directory named according to the scheme
route-eth0 route-eth1 route-eth2
it will execute each line in the files as
/sbin/ip route add <line>
when each interface is brought up.
Look in the /etc/sysconfig/network-scripts/ifup-routes script for all the gory details and features.
I actually did just that---looked at the ifup-routes script. The thing that threw me off is the comments about "older format" versus "new format". I probably read into the comments too much, but I thought to myself, "I should probably use the new format, as they might some day deprecate the old format."
But anyway, the "older format" is what I need. With the older format, it's exactly what you said above: each line corresponds to running "ip route add <line>". So what I added were lines in this format:
<addr>/<mask> via <gateway> dev <device> metric <N>
A contrived example might be:
10.25.77.0/24 via 192.168.1.1 dev eth0 metric 5
The "new format" is where each group of three lines corresponds to a route. You have the ADDRESSxx=, NETMASKxx=, GATEWAYxx= lines. Clearly this is less flexible, particularly if you need to set a metric like me. :)
Anyway, hopefully that's useful for anyone in a similar situation!
-Matt
Hi, Matt.
Sorry for the top post, but my iPad mail client seems averse to allowing me to bottom post.
Just wanted to take a moment to note that I believe you've got things a little bit reversed.
The use Of the route-ethX files and the "ip" command are the "newer" method. Setting the NETMASK and ADDRESS in the ifcfg-ethX files has always been and continues to be the norm. Having the GATEWAY field in either the ifcfg-ethX files or in /etc/sysconofig/network is the older way of setting the default route.
You're right, though...it was certainly less flexible. ;-)
On Dec 15, 2011, at 12:54 PM, Matt Garman matthew.garman@gmail.com wrote:
Adding additional info for posterity, and in case anyone else runs across this...
On Wed, Dec 7, 2011 at 12:28 PM, Benjamin Franz jfranz@freerun.com wrote:
On 12/7/2011 10:03 AM, Matt Garman wrote:
Hi,
[...] What I basically need to be able to do is this: route add -host h1 gw g1 metric 0 route add -host h1 gw g2 metric 10
Notice that everything is the same except the gateway and metric. I could put this in /etc/rc.local, but was wondering if there's a cleaner way to do it in e.g. the network-scripts directory."
If you create files in the /etc/sysconfig/network-scripts directory named according to the scheme
route-eth0 route-eth1 route-eth2
it will execute each line in the files as
/sbin/ip route add <line>
when each interface is brought up.
Look in the /etc/sysconfig/network-scripts/ifup-routes script for all the gory details and features.
I actually did just that---looked at the ifup-routes script. The thing that threw me off is the comments about "older format" versus "new format". I probably read into the comments too much, but I thought to myself, "I should probably use the new format, as they might some day deprecate the old format."
But anyway, the "older format" is what I need. With the older format, it's exactly what you said above: each line corresponds to running "ip route add <line>". So what I added were lines in this format:
<addr>/<mask> via <gateway> dev <device> metric <N>
A contrived example might be:
10.25.77.0/24 via 192.168.1.1 dev eth0 metric 5
The "new format" is where each group of three lines corresponds to a route. You have the ADDRESSxx=, NETMASKxx=, GATEWAYxx= lines. Clearly this is less flexible, particularly if you need to set a metric like me. :)
Anyway, hopefully that's useful for anyone in a similar situation!
Vreme: 12/17/2011 05:43 AM, Mike Burger piše:
Hi, Matt.
Sorry for the top post, but my iPad mail client seems averse to allowing me to bottom post.
Just wanted to take a moment to note that I believe you've got things a little bit reversed.
The use Of the route-ethX files and the "ip" command are the "newer" method. Setting the NETMASK and ADDRESS in the ifcfg-ethX files has always been and continues to be the norm. Having the GATEWAY field in either the ifcfg-ethX files or in /etc/sysconofig/network is the older way of setting the default route.
You're right, though...it was certainly less flexible. ;-)
On Dec 15, 2011, at 12:54 PM, Matt Garmanmatthew.garman@gmail.com wrote:
No, you got it wrong,
he was talking about that route-ethX, not ifcfg-ethX, supports NETMASK, ADDRESS, GATEWAY (in separate lines) format. I used it from 2006. You can add as much routes that way as you please:
NETMASK0= ADDRESS0= GATEWAY0=
NETMASK1= ADDRESS1= GATEWAY1=
NETMASK2= ADDRESS2= GATEWAY2=
...
Vreme: 12/17/2011 05:43 AM, Mike Burger pie:
Hi, Matt.
Sorry for the top post, but my iPad mail client seems averse to allowing me to bottom post.
Just wanted to take a moment to note that I believe you've got things a little bit reversed.
The use Of the route-ethX files and the "ip" command are the "newer" method. Setting the NETMASK and ADDRESS in the ifcfg-ethX files has always been and continues to be the norm. Having the GATEWAY field in either the ifcfg-ethX files or in /etc/sysconofig/network is the older way of setting the default route.
You're right, though...it was certainly less flexible. ;-)
On Dec 15, 2011, at 12:54 PM, Matt Garmanmatthew.garman@gmail.com wrote:
No, you got it wrong,
he was talking about that route-ethX, not ifcfg-ethX, supports NETMASK, ADDRESS, GATEWAY (in separate lines) format. I used it from 2006. You can add as much routes that way as you please:
NETMASK0= ADDRESS0= GATEWAY0=
NETMASK1= ADDRESS1= GATEWAY1=
NETMASK2= ADDRESS2= GATEWAY2=
Aaahhh...yes, you're right...I did miss that point. Thanks for setting me straight. :-)
Vreme: 12/17/2011 05:43 AM, Mike Burger pie:
Hi, Matt.
Sorry for the top post, but my iPad mail client seems averse to allowing me to bottom post.
Just wanted to take a moment to note that I believe you've got things a little bit reversed.
The use Of the route-ethX files and the "ip" command are the "newer" method. Setting the NETMASK and ADDRESS in the ifcfg-ethX files has always been and continues to be the norm. Having the GATEWAY field in either the ifcfg-ethX files or in /etc/sysconofig/network is the older way of setting the default route.
You're right, though...it was certainly less flexible. ;-)
On Dec 15, 2011, at 12:54 PM, Matt Garmanmatthew.garman@gmail.com wrote:
No, you got it wrong,
he was talking about that route-ethX, not ifcfg-ethX, supports NETMASK, ADDRESS, GATEWAY (in separate lines) format. I used it from 2006. You can add as much routes that way as you please:
NETMASK0= ADDRESS0= GATEWAY0=
NETMASK1= ADDRESS1= GATEWAY1=
NETMASK2= ADDRESS2= GATEWAY2=
Although, thinking back, you've made a very similar point to mine:
That the standard of xxx.xxx.xxx.xxx/yy via zzz.zzz.zzz.zzz style of entry, invoking the "ip" command, is still the "newer" way of doing it, while the parameter-per-line method you noted above, just like putting the data into the ifcfg-ethX and the network files, is an older way of doing so.
Vreme: 12/18/2011 07:57 AM, Mike Burger piše:
Although, thinking back, you've made a very similar point to mine:
That the standard of xxx.xxx.xxx.xxx/yy via zzz.zzz.zzz.zzz style of entry, invoking the "ip" command, is still the "newer" way of doing it, while the parameter-per-line method you noted above, just like putting the data into the ifcfg-ethX and the network files, is an older way of doing so.
Depends on how old ip command in route-ethX is. If it is back from 2.4 kernel????
I will not bother to research, and I did not say it was older or newer, just that there is such convention.