The Linux Host Setup
The following is the setup for my scenario:
- Machines in my LAN (host network) have IP addresses such as 192.168.0.X.
- The host IP address is 192.168.0.2.
- The two UML guest machines are named Uml1 and uml2 and their addresses are 192.168.0.201 and 192.168.0.202, respectively.
- The Internet gateway in the LAN has the IP address 192.168.0.1.
I had to add a bridge instance in the host machine using brctl, the utility provided by the bridge-util package for Ethernet bridge administration:
brctl addbr the_bridge
You can set other bridge parameters with the brctl utility as well (such as settings for variables affecting the Spanning Tree protocol), but these are related to complex network topologies and are beyond the scope of this article.
I then started up the bridge interface as I do with a normal network interface, by calling it the_bridge and assigning the IP address with a relative netmask that I would assign to the host if it were normally on the LAN:
ifconfig the_bridge 192.168.0.2 netmask 255.255.255.0 up
Once the bridge was up (you can check it with ifconfig), it was like I had a physical Ethernet switch with sockets to connect the other machines in the network. The first machine I needed to connect was the host itself. Every connection to the bridge consists of the configuration of a standard eth0 interface as a promiscuous one with the IP address 0.0.0.0, which has to be successively added to the bridge:
ifconfig eth0 0.0.0.0 promisc up
brctl addif the_bridge eth0
Then I needed to add my default gateway to access the Internet:
route add default gw 192.168.0.1
|Figure 1. Logic Schema of Network Solution: I had to plug in all the other UML machines that I wanted to power on inside the Linux host.|
Next, I had to plug in all the other UML machines that I wanted to power on inside the Linux host. Each UML in the host required that I:
- create the TAP interface to be associated to the network interface eth0 of UML and assign it to a particular user (host-user);
- configure and rise up the TAP as a promiscuous interface;
- add the TAP interface to the bridge.
For the first and second UML machines, I run as follows (see Figure 1):
tunctl -u host-user -t the_uml_conn1
ifconfig the_uml_conn1 0.0.0.0 promisc up
brctl addif the_bridge the_uml_conn1
tunctl -u host-user -t the_uml_conn2
ifconfig the_uml_conn2 0.0.0.0 promisc up
brctl addif the_bridge the_uml_conn2