Bug 106269 - Default route is always out highest numbered interface on multihomed box.
Default route is always out highest numbered interface on multihomed box.
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: initscripts (Show other bugs)
rawhide
All Linux
medium Severity medium
: ---
: ---
Assigned To: Bill Nottingham
Brock Organ
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-10-04 10:34 EDT by Terje Bless
Modified: 2014-03-16 22:39 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-06-07 15:56:18 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Terje Bless 2003-10-04 10:34:58 EDT
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 01:26:45 EDT
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 08:20:57 EDT
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 15:23:05 EDT
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 17:06:27 EDT
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 17:55:08 EDT
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 15:56:18 EDT
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.

Note You need to log in before you can comment on or make changes to this bug.