Creating Linux bridging / tap devices with tunctl and openvpn

The more and more I play around with KVM virtualization, the more I realize just how useful Linux bridging is. In the Linux bridging world, a bridge device simulates a multiport Ethernet switch. To connect to the switch, you create a tap device that simulates a port on that switch. Once you have bridging configured on your host, there are two prevalent ways of going about creating taps. The first method is through the openvpn program:

$ openvpn –mktun –dev tap0

Fri Apr 24 15:14:26 2009 TUN/TAP device tap0 opened
Fri Apr 24 15:14:26 2009 Persist state set to: ON

This will create a tap device named tap0, which you can configure locally or assign to a virtual machine running on the host. The second way to create a tap is through tunctl:

$ tunctl -u root

Set 'tap0' persistent and owned by uid 0

This will also create a tap device named tap0, and will set the owner of the interface to root. Once a tap device is created, you can configure it just like any other Ethernet interface. Nice!

Leave a Comment