Each virtual machine (VM) has FIVE network interfaces.
eth0 - This interface provides the connection between your VMs and the outside world (including you). Through this interface your VM can connect to outside websites and download software to install. You connect to your VM to administer it via SSH through this interface.
eth1 and eth2 - These two interfaces are connected to virtual Local Area Networks (VLANs) which are shared with all other VMs, even those running on different hosts. These are shared VLANs and every VirtualNET user's VMs have access to them through their own eth1 and eth2 interfaces.
eth3 and eth4 - These interfaces are connected to VLANs which are shared ONLY with your own VMs. These are the private VLANs. All of your own VMs, even those running on different hosts, have access to these same two VLANs through their own eth3 and eth4 interfaces.
eth0, eth1 and eth2 are all used to communicate with hosts other than your own. These may be servers in the outside world in the case of eth0, or with the VMs of other users in the case of eth1 and eth2.
When your VM starts, each of these network interfaces will be configured with an IP address which will be unique in its own context to allow your VM to communicate without its addresses conflicting with any other hosts.
Part of this involves your CSE UID (or user ID).
Your UID is a positive integer which identifies you to CSE systems. If you haven't encountered this yet, you can find your UID by running the id
command at any command prompt. This number is unique to you on CSE systems.
During address calculation your UID is split into two parts:
These two parts are used as the last two octets of the IPv4 network addresses assigned to eth0, eth1 and eth2 when your VM starts up. See the sections below for specifics.
RFC1918 (also) defines three private IPv4 address ranges. These are addresses which will not be used on the public Internet and which are for private or “internal use” only. Of these, VirtualNET uses the range 172.16.0.0 - 172.19.255.255 for eth0, and 10.0.0.0 - 10.63.255.255 for eth1 and eth2.
The eth0 interface of each VM provides its connection to the outside world.
You can have four VMs per host and eth0 of each of these VMs will have its own address in the range 172.16.0.0 - 172.19.255.255. In particular:
The host uses Network Address Translation (NAT) to pass your VMs' traffic back and forth between the VM and the outside world. This means that anyone externally monitoring network traffic will see network traffic from your VMs as coming from/going to the host's own IP address.
Once you have started a VM, you can connect to it using SSH to one of the addresses shown above. Note that you cannot connect to a VM started on one host from a different host this way.
When your VM starts it will already have addresses assigned to eth1 and eth2. Because the VLANs to which eth1 and eth2 are connected are shared with all other VMs, including those of other users and including those on other hosts, the addresses are calculated to be unique so they will not conflict with the addresses used by any other VM.
The address will be in the format 10.X.uidhi.uidlo. uidhi and uidlo are derived from your UID and are the same as values as those mentioned earlier. X is calculated from the host ID on which the VM is running, the number of the host (0 to 8) and an offset of 64 if using eth2:
hostid = VLAB host name - “vx”. Thus, if your VM is running on vx5 the hostid will be 5.
Then, X = (hostid * 4) + (vmnum - 1) on eth1, or X + 64 for eth2.
If this is too complicated, which it probably is, we have a helpful table with all the values worked out.
When your VMs start, eth3 and eth4 are connected to the two private VLANs assigned to you, but neither interface has any addresses configured for it, and neither interface is enabled (up
).
eth1 and eth2 of your VMs are connected to eth1 and eth2 of all other users's VMs through two network hubs. These hubs ensure that the network packets your VMs send are received by all other VMs.
A notable characteristic of these hubs is that they retransmit all packets they receive to all VMs currently connected to them. This means that each VM will receive a copy of each network packet it sends.
This is typically not an issue, but if you use tcpdump
or wireshark
to monitor network traffic, you may notice these extra packets appearing on the interfaces.
eth3 and eth4 similarly connect to eth3 and eth4 of all of your own VMs through two network hubs. But in this case, the hubs don't connect to other users' VMs, just yours own.
When a VM starts up, its eth3 and eth4 are interfaces are not configured with IP addresses nor are they enabled. They are connected to their respective VLANs but until they are enabled and/or configured with IP addresses they cannot be used.
In the unlikely, but possible, event that all you want to use them for is to capture network traffic from other VMs using tools like tcpdump
or wireshark
, then all you need to do is set the network interface to up
as shown below (as root) prior to running the tools.
On the other hand, if you want to configure eth3 or eth4 so you can use a private VLAN to talk to one or more other VMs you have started, then you'll need to assign each VM its own unique IP address on the VLAN.
Because the VLANs connecting eth3 and eth4 together are completely private and only your VMs have access to them, you can configure them pretty much how you want. I'd recommend using one of the reserved private address ranges specified in the famous RFC1918, such as 192.168.0.0/24 (i.e., netmask 255.255.255.0).
In the examples below, replace “X” with either “3” or “4” depending on the interface you want to configure.
Configuring an address for an interface
ip addr add 192.168.0.1/24 dev ethX
The above will assign the address 192.168.0.1 to the specified interface. Note that you MUST also enable the interface (as shown below) before you can send or receive traffic through it.
Note: If you have a second VM running and you do the same thing but with a different address in the same range, such as 192.168.0.2, you will be able to ping each machine using these addresses.
Enabling an interface
ip link set ethX up
The above command enables a network interface.