Bug 106269

Summary: Default route is always out highest numbered interface on multihomed box.
Product: [Fedora] Fedora Reporter: Terje Bless <link>
Component: initscriptsAssignee: Bill Nottingham <notting>
Status: CLOSED NOTABUG QA Contact: Brock Organ <borgan>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: rvokal
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-06-07 19:56:18 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Terje Bless 2003-10-04 14:34:58 UTC
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.

Comment 1 Bill Nottingham 2003-10-06 05:26:45 UTC
What does your /etc/sysconfig/network-scripts/ifcfg-* and /etc/sysconfig/network
look like in the case that doesn't work for you?

Comment 2 Terje Bless 2003-10-06 12:20:57 UTC
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

Comment 3 Bill Nottingham 2003-10-06 19:23:05 UTC
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?

Comment 4 Terje Bless 2003-10-06 21:06:27 UTC
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.

Comment 5 Bill Nottingham 2003-10-06 21:55:08 UTC
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.

Comment 6 Bill Nottingham 2004-06-07 19:56:18 UTC
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.