Identifying the active bridge adapter for use with a headless virtual machine on VirtualBox

I mentioned in an earlier post that it is possible to use the command line to set the particular bridge adapter required to run VirtualBox, resolving an error that aborts start-up of the virtual machine.

Which adapter is in use depends on how the host machine is expecting to connect to the internet, even if it is not actually connected at the moment. Different airport and ethernet cards identify themselves using (in theory) different MAC addresses and will be assigned different BSD interface names, “en0″, “en1″, and so on. (These names are always of the format [letters][integer].) Since interface names are assigned at system start-up, they may occasionally be different from what you are used to seeing, so it is not a good idea to treat them as fixed.

To direct VirtualBox to use a particular interface — en0, for instance — for a virtual machine “himself”, use

vboxmanage modifyvm himself --nic1 bridged \
--bridgeadapter1 en0

at the command line.

But sometimes it isn’t easy to figure out which interface to use. On models of MacBook Air that have no built-in ethernet card, an external (USB) ethernet adapter is needed, and different USB adapters will have different MAC addresses, meaning that they will each be assigned different interface names. How do you know which interface name should be passed to VirtualBox?

Active interface names are reported by the network interface configuration tool ifconfig when run without options. You can pipe that output through awk to return just the active en- interface name to standard output:

ifconfig | awk -F: '/^en/ { print $1 }'

If you like, you can pass the output of that whole expression to vboxmanage in a one-line instruction:

vboxmanage modifyvm himself --nic1 bridged \
--bridgeadapter1 `ifconfig | awk -F: '/^en/ { print $1 }'`

That should configure VirtualBox correctly so that the virtual machine will boot successfully. The only caveat is that if the virtual machine is already running, you will get an error. Occasionally, when even running ipconfig getifaddr does not return an IP address for the active interface name, I have found it helpful to reboot my hardware and run the filesystem consistency check, fsck.

Alfred Aho on the origins of awk (2008)

From an interview by Naomi Hamilton:

Language design is a very personal activity and each person brings to a language the classes of problems that they’d like to solve, and the manner in which they’d like them to be solved. I had a lot of fun creating AWK, and working with Kernighan and Weinberger was one of the most stimulating experiences of my career. I also learned I would not want to get into a programming contest with either of them however! Their programming abilities are formidable.

Interestingly, we did not intend the language to be used except by the three of us. But very quickly we discovered lots of other people had the need for the routine kind of data processing that AWK was good for. People didn’t want to write hundred-line C programs to do data processing that could be done with a few lines of AWK, so lots of people started using AWK.

[The name] was not our choice. When our research colleagues saw the three of us in one or another’s office, they’d walk by the open door and say ‘AWK! AWK!’. So, we called the language AWK because of the good natured ribbing we received from our colleagues. We also thought it was a great name, and we put the AUK bird picture on the AWK book when we published it.

What AWK represents is a beautiful marriage of theory and practice. The best engineering is often built on top of a sound scientific foundation. In AWK we have taken expressive notations and efficient algorithms founded in computer science and engineered them to run well in practice.

Alfred Aho, interviewed by Naomi Hamilton, “The A-Z of Programming Languages: AWK”, Computer World, 20080527, accessed 20111029.

Appreciation of awk

Most of my early programing was with Pascal. With the discovery of this book, and the awk program provided by the Thompson Automation Software (a super-set of the traditional Awk. Unfortunately TAS is now extinct) for the past 20 years all of my programing has been with AWK. From small one line scripts to 5 pages of code, all done with AWK (TAWK). It’s been a great ride. I’m 80 now, and still at it.

Comment by “Tom” on The AWK Programming Language by Alfred V. Aho, Brian W. Kernighan, and Peter J. Weinberger http://www.goodreads.com/book/show/703101.The_AWK_Programming_Language (dated Nov 10, 2010, seen 20110217)


Imagine the pleasure of using just one small but powerful tool for all tasks!