Friday, 13 March 2009

ifup: network-functions: line 52: eth0: No such file or directory

The (external) power supply on my Linux box broke the other day. Tranquil PC sent me a new one, so I booted the machine up for the first time in ages. I noticed an error message as it was trying to bring up the eth0 interface (which is nicknamed "moors" on my machine):

ifup: network-functions: line 52: eth0: No such file or directory

This appeared twice every time I booted the machine.

I looked in /etc/sysconfig/network-script/network-functions, and line 52 was the (rather unhelpful):

. $CONFIG

I went through a prolonged debugging session, putting trace code in ifup and network-functions, and I found the problem was caused by line 155 of ifup:

is_available ${REALDEVICE}

REALDEVICE at this point is "eth0". is_available starts like this:

LC_ALL= LANG= ip -o link | grep -q $1
[ "$?" = "1" ] || return 0

alias=`modprobe -c | awk "/^(alias|install)[[:space:]]+$1[[:space:]]/ { print \\$3 }"`
if [ -z "$alias" -o "$alias" = "off" -o "$alias" = "/bin/true" ]; then
return 2
fi
modprobe $1 > /dev/null 2>&1 || return 1
# if it is a mainframe ccwgroup device, configure it before
# trying to rename it:
need_config ${1}

I haven't figured out what all the tests at the top do, but (for eth0 only, and only when rebooting) control comes through to the call to need_config. need_config looks like this:

CONFIG="ifcfg-${1}"
[ -f "${CONFIG}" ] && return
CONFIG="${1}"
[ -f "${CONFIG}" ] && return
local addr=`get_hwaddr ${1}`
if [ -n "$addr" ]; then
local nconfig=`get_config_by_hwaddr ${addr}`
if [ -n "$nconfig" ] ; then
CONFIG=$nconfig
[ -f "${CONFIG}" ] && return
fi
fi

So CONFIG gets changed from "ifcfg-moors" (which is what it was to start with) to "eth0" - and there is no such file (nor an ifcfg-eth0) in /etc/sysconfig/network-scripts.

I have "fixed" the problem by adding a line to the top of need_config:

[ -f "${CONFIG}" ] && return

but this is the ravings of someone who doesn't really know what is going on!

Helpful suggestions welcome.

Thursday, 5 March 2009

Adding a second Internet connection - part 2

Now I have routing working properly on my new router, I took the opportunity to move it onto eth0 (my firewalled, "dirty" interface).


First, I set up a new aliased ethernet port on the Linux box, using the Gnome System Settings/Network tool. I gave this IP address 192.168.0.1 (no default gateway).


Then I connected to the new router, and changed its IP address to 192.168.0.250. I physically moved it onto the eth0 network. Finally I telnetted to it and set up its own routes, as follows:

D-Link> ip route addrom index 1
D-Link> ip route addrom name gbit
D-Link> ip route addrom set 192.168.3.0/24 192.168.0.1 1
D-Link> ip route addrom save
ip route addrom: save ok
D-Link> ip route addrom index 2
D-Link> ip route addrom name mbit
D-Link> ip route addrom set 192.168.1.0/24 192.168.0.1 1
D-Link> ip route addrom save
ip route addrom: save ok
D-Link> ip route addrom index 3
D-Link> ip route addrom name dirty
D-Link> ip route addrom set 192.168.2.0/24 192.168.0.1 1
D-Link> ip route addrom save
ip route addrom: save ok

This set up the following static routes:

Dest FF Len Device Gateway Metric stat Timer Use RN
192.168.0.0 00 24 enet0 192.168.0.250 1 041b 0 1150
192.168.1.0 00 24 enet0 192.168.0.1 1 001b 0 0
192.168.2.0 00 24 enet0 192.168.0.1 1 001b 0 0
192.168.3.0 00 24 enet0 192.168.0.1 1 001b 0 445

Then I altered the routes on the Linux box as follows:

ip route add 192.168.2.0/24 dev eth0 src 192.168.2.1 table ISP1
ip route add default via 192.168.2.5 table ISP1

ip route add 192.168.0.0/24 dev eth0 src 192.168.0.1 table ISP2
ip route add default via 192.168.0.250 table ISP2

ip route add 192.168.2.0/24 dev eth0 src 192.168.2.1
ip route add default via 192.168.2.5

ip rule add from 192.168.2.1 table ISP1
ip rule add from 192.168.0.1 table ISP2

I also set up static routes for some IP addresses I wanted to reach via one or other ISP (e.g. their DNS servers).


That all works - I can connect in from outside via either of the two routers (I have set up identical NAT mappings on both). I can easily switch to the secondary router like this:

ip route del default
ip route add default via 192.168.0.250

I am now considering load balancing between the two routers. I think the commands to do this would be:

ip route del default
ip route add default scope global nexthop via 192.168.2.5 dev eth0 weight 6 nexthop via 192.168.0.250 dev eth0 weight 1