Given a host with two Ethernet interfaces -- eth0 and eth1 -- where eth0 is Internet-facing with a public address, and eth1 is on a private network; ifup et al appear to always add a default route out eth1 (the highest numbered/last brought up interface). There appears to be no way to configure the default route to go out eth0, or to go to a different gateway device. Parsing of /etc/sysconfig/static-routes prepends a "-" to each line before passing it to /sbin/ip and the syntax for setting a default route is "ip route add default gw ..." (note no "-" before "default"). Setting "GATEWAYDEV=device" in /etc/sysconfig/network -- but *not* setting "GATEWAY=ipaddr" -- /appears/ to work, but this is undocumented (that I can find), non obvious, and may be incidental for all I know. I reccomend adding a specific (and documented!) way to set the default gateway -- possibly by using "DEFAULTGW=ipaddr" in /etc/sysconfig/network -- or to document the behaviour of GATEWAY and GATEWAYDEV and make them behave consistently.
What does your /etc/sysconfig/network-scripts/ifcfg-* and /etc/sysconfig/network look like in the case that doesn't work for you?
I modified the IPs and snipped the MAC addresses (on general principle). You can assume the 192.168.1.0/24 network is a public IP network (i.e. non-RFC1918). The below is the non-working version; adding "GATEWAYDEV=eth0" to /etc/sysconfig/network makes it work. :::::::::::::: /etc/sysconfig/network :::::::::::::: NETWORKING=yes HOSTNAME=lamb.example.com GATEWAY=192.168.1.1 :::::::::::::: /etc/sysconfig/network-scripts/ifcfg-eth0 :::::::::::::: # Intel Corp.|82801BA/BAM/CA/CAM Ethernet Controller DEVICE=eth0 BOOTPROTO=none BROADCAST=192.168.1.255 HWADDR=[snipped] IPADDR=192.168.1.12 NETMASK=255.255.255.0 NETWORK=192.168.1.0 ONBOOT=yes TYPE=Ethernet USERCTL=no PEERDNS=no GATEWAY=192.168.1.1 :::::::::::::: /etc/sysconfig/network-scripts/ifcfg-eth1 :::::::::::::: # Macronix, Inc. [MXIC]|MX987x5 DEVICE=eth1 BOOTPROTO=none HWADDR=[snipped] ONBOOT=yes TYPE=Ethernet USERCTL=no PEERDNS=no NETMASK=255.255.255.0 IPADDR=172.20.100.21 GATEWAY=172.20.100.1
So, it sets the default route via 192.168.1.1, yet on device eth1? Or it makes 172.20.100.1 the default route?
It sets the default route to 172.20.100.1. As best I've been able to tell from browsing the relevant bits of code, what happens is that on the interface last brought up it will forcibly remove any existing default route and add in a new one. I suspect it's this code from line 360 of "ifup": -- cut # Set a default route. if [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]; then # set up default gateway. replace if one already exists if [ -n "${GATEWAY}" -a "`ipcalc --network ${GATEWAY} ${NETMASK} 2>/dev/null`" = "NETWORK=${NETWORK}" ]; then ip route replace default via ${GATEWAY} ${WINDOW:+window $WINDOW} ${SRC} elif [ "${GATEWAYDEV}" = "${DEVICE}" ]; then ip route replace default ${SRC} ${WINDOW:+window $WINDOW} dev ${REALDEVICE} fi fi -- cut But I'm afraid I speak shell too little to be sure I grok this.
IIRC, the problem is that the GATEWAY in ifcfg-* will override the GATEWAY in /etc/sysconfig/network. So you don't know that there's a global preference without GATEWAYDEV.
The documentation in sysconfig.txt has been clarified a little in CVS for future builds. The behavior you're seeing is pretty much what's expected in the absence of GATEWAYDEV, though.