Welcome to my blog. Built with HTML in Pittsburgh, PA.

How to set up network interface bonding with netctl / Archlinux


Bonding is a useful type of Linux network interface that allows two or more network interfaces to be used for the same LAN. One use case is when a wired and wireless connection are both used and the wired connection should be preferred if the Ethernet cable is connected. Bonding allows seamless switching between using the wired and wireless connection as the cable is plugged and unplugged.

Below are the netctl configuration files I use. The bond mode should be set to active-backup. Note that the IP configuration is set in the bond configuration file, and not in the individual interface configurations. There is no configuration file for the ethernet interface because all that's needed to be done is for the interface to be brought up. netctl will bring up all interfaces listed in BindsToInterfaces when the bond configuration is started.

Be sure to change the interface names eth0 and wlan0 to match yours, and set the IP and wireless security settings appropriately.


Description='Ethernet primary with wifi backup'
BindsToInterfaces=(eth0 wlan0)
LinkOptions='miimon 100 primary eth0 updelay 100 downdelay 100'

primary eth0 indicates that the eth0 interface should be used if both are connected, while miimon, updelay, and downdelay specify the time in milliseconds to wait before checking for link connectivity and switching between interfaces.


Description='Wifi for bonding: no IP'

ForceConnect=yes ensures the wifi configuration will not fail to start if the bond configuration has already brought it up.

To use this configuration, run

# netctl start bond && netctl start wifi_bond

It's very important that the bond configuration is started before the wifi configuration, since an interface cannot be enslaved if it is "UP". If the wifi configuration is started first, the bond configuration will silently fail to enslave it and the wifi interface will not be used in the bond. A more sophisticated network manager than netctl can likely provide a better way to handle this.

For a thorough read on bonding, and an explanation of all options, see https://www.kernel.org/doc/Documentation/networking/bonding.txt.

Useful guides on bonding for other network managers:

Happy bonding!

How to use import statement inside of an eval in a ROS roslaunch file


Since ROS Kinetic (Ubuntu 16.04), roslaunch allows you to eval arbitrary Python expressions.

For example, you can do something like this to manipulate parameters found in two different files:

<arg name="parameter" default="$(eval float(open('config1').read().strip()) + float(open('config2').read().strip()))"/>

Something I've always wanted to do is to check for the existence of a file. However, since the os module has not been imported in roslaunch's eval environment, this seems impossible to do. Furthermore, roslaunch explicitly forbids double underscores, precluding the use of an expression import with __import__. However, it does so by searching for __! See line 345 at the roslaunch source, which references https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html.

We can get around this by nesting evals and creating the __import__ method using string addition of individual underscores.

<arg name="conf" default="$(eval 'b.txt' if eval('_' + '_import_' + '_(\'os\')').path.exists('b.txt') else 'a.txt')"/>

How to wire Pixracer serial to TX2 J121 UART 2

If pin 1 is the GND pin for both the Molex Pico (plugging into J7) and the JST GH (plugging into a UART on the Pixracer), then pin 2 on J7 connects to pin 5 on the JST GH and pin 3 on the J7 connects to pin 4 on the JST GH.

To talk to this port from Linux, you may need to use /dev/ttyTHS1 or /dev/ttyTHS3.