After scouring the internet for answers on howto use Busybox’s ifupdown binary and configure /etc/network/interfaces to set a vlan for an interface I looked in the ifupdown.c code and there are no references to vlans at all!
Don’t panic! Just because there isn’t built in support for setting the vlans doesn’t mean you can’t use /etc/network/interfaces or have to resort to using some custom cockamamie script to set your vlans up! The answer is in front of your nose!
Lately I’ve been making extensive use of the ifupdown pre-up and post-up options for doing insane things like appending iptables rules, bringing up and down other interfaces, etc… The simple trick is to use pre-up|up to use vconfig to create your vlan. The configuration file’s default location is /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
auto eth0.192
iface eth0.192 inet static
address 192.168.0.77
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 4.2.2.1 4.2.2.2
pre-up ifconfig eth0 up
pre-up vconfig add eth0 192
I found that I had to add a second pre-up command to configure eth0 up because it has no configuration. This could be a fundamental misunderstanding on my part however; the configuration works impressively well.
For the ifupdown scripts to work we will need to have a service file be executed on startup to run ifup -a. This will be up to individual project’s requirements however; assuming the project will be using a pure Busybox solution, Busybox provides its own init that will walk through /etc/init.d and run start on the scripts it finds there. Here is an example script that buildroot provided my rootfs skeleton.
/etc/init.d/S40Network
#!/bin/sh
#
# Start the network....
#
# Debian ifupdown needs the /run/network lock directory
mkdir -p /run/network
case "$1" in
start)
printf "Starting network: "
/sbin/ifup -a
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
stop)
printf "Stopping network: "
/sbin/ifdown -a
[ $? = 0 ] && echo "OK" || echo "FAIL"
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
Let’s say you need high
availability. You can’t afford to have a switch go down or have a network card go bad. You need uptime and you need it now. Now let’s make this even more complicated. Let’s add non native vlans to this ordeal. My weapons of choice are bonding and Gentoo. We need a few things.
- Linux bonding module – Device Drives > Network device support > <M> Bonding drive support (you can make this a module or build it in but my howto only covers the module)
- VLAN support – Networking support > Network options > 802.1Q VLAN Support
- net-misc/vconfig
- net-misc/ifenslave
After building the modules in your Linux kernel, emerge net-misc/vconfig net-misc/ifenslave . Next you want to setup the bonding module to auto load with your settings. Note that you may have more modules in your autoload file.
# cat /etc/modules.autoload.d/kernel-2.6
…
bonding miimon=100 mode=1
…
Remember to run update-modules. The miimon setting is how often, in milliseconds, the link state of the interface is checked. If it does not have link it will remove the link from the pool. The mode setting indicates the way the interfaces are balanced. There are several modes, but most require that your switch also be configured to use them. In this howto’s case mode 1 is set. Mode 1 is active/backup where you may have one active link up and one or more backups or standbys. If the active fails a backup will take its place.
Next you need to configure the network. The network
configuration file for Gentoo is /etc/conf.d/net . Here is how to setup bonding.
config_eth0=( “null” )
config_eth1=( “null” )
slaves_bond0=”eth0 eth1″
config_bond0=( “192.168.0.1/24” )
routes_bond0=( “default via 192.168.0.254/24” )
Basically you set eth0 and eth1 to have no configuration. This allows the ethernets to be brought up to use, but not configured to do anything or assumed to be dhcp. The slaves_bond0 directive sets which
interfaces are members of the pool of available interfaces. Finally config_ and route_ sets the ip and gateway for your interface.
Now, let’s say you are going to add non native VLANs. The config_ and route_ lines won’t work now. Here is the new config.
config_eth0=( “null” )
config_eth1=( “null” )
slaves_bond0=”eth0 eth1″
config_bond0=( “null” )
vlans_bond0=”100 200″
mtu_bond0=”1496″
vconfig_bond0=( “set_name_type VLAN_PLUS_VID_NO_PAD” )
config_vlan100=( “192.168.0.1/24” )
routes_vlan100=( “default via 192.168.0.254” )
config_vlan200=( “10.0.0.123/24” )
Basically the only difference is the removal of routes_bond0 and setting config_bond0 to null. The vlans_bond0 sets which VLANS to attach the interface to, mtu_bond0 sets the MTU size, and vconfig_bond0 sets VLAN options. Finally it’s time to setup the actual VLAN interfaces, those are config_<vlanid>. In our case we’ve already set them with vlans_bond0, so we have config_vlan100 and config_vlan200. Our default route goes out vlan100, so routes_vlan100 is used and vlan200 is our private interface.
That concludes our bondage training. I hope you all enjoyed and found this informational.