Posts tagged: onboot

1 Shocking Trick To Add VLANs To Your Busybox ifupdown Configuration Developers Don’t Want You To Know! Number One Will Disintegrate You!

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
	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.

# Start the network....

# Debian ifupdown needs the /run/network lock directory
mkdir -p /run/network

case "$1" in
	printf "Starting network: "
	/sbin/ifup -a
	[ $? = 0 ] && echo "OK" || echo "FAIL"
	printf "Stopping network: "
	/sbin/ifdown -a
	[ $? = 0 ] && echo "OK" || echo "FAIL"
	"$0" stop
	"$0" start
	echo "Usage: $0 {start|stop|restart}"
	exit 1

exit $?