Fixing mis-named virtual network interfaces

From ExpressionPlot
Jump to: navigation, search

If you can log in to your virtual machine through the GUI but not via ssh, and if you can't connect from your virtual machine to the outside world (even to your host machine) then you may suffer from a mis-named network interface. I don't understand what causes this but would be happy if someone could explain (send a message to the ExpressionPlot discussion group). However, diagnosing and fixing this problem is a cinch.

After logging into your virtual machine run the following command to list all your network interfaces:

 ifconfig -a

The output might look like this:

 eth2      Link encap:Ethernet  HWaddr 08:00:27:da:ab:4e  
           inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
           inet6 addr: fe80::a00:27ff:feda:ab4e/64 Scope:Link
           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
           RX packets:41 errors:0 dropped:0 overruns:0 frame:0
           TX packets:39 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:1000 
           RX bytes:5826 (5.8 KB)  TX bytes:5424 (5.4 KB)
 
 lo        Link encap:Local Loopback  
           inet addr:127.0.0.1  Mask:255.0.0.0
           inet6 addr: ::1/128 Scope:Host
           UP LOOPBACK RUNNING  MTU:16436  Metric:1
           RX packets:0 errors:0 dropped:0 overruns:0 frame:0
           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:0 
           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

In this case the important thing to note is that first interface is called "eth2".

Next check the contents of the file /etc/network/interfaces by typing

 cat /etc/network/interfaces

It might look like this ("eth1" has been highlighted here for presentation purposes):

 # The loopback network interface
 auto lo
 iface lo inet loopback
 
 # The primary network interface
 auto eth1
 iface eth1 inet dhcp

This file is looking for an interface called "eth1" when the correct name should be "eth2". So both instances of "eth1" need to be changed to "eth2", so that /etc/network/interfaces now looks as follows:

 # The loopback network interface
 auto lo
 iface lo inet loopback
 
 # The primary network interface
 auto eth2
 iface eth2 inet dhcp

After saving these changes reboot the virtual machine with sudo reboot or by (virtually) power cycling your VM. The networking, both in and out, should now work.

Question: would it be enough to re-run sudo /etc/init.d/network-interface restart instead of rebooting the machine?

  • Fun fact: random internet angel Christophe Deprez has explained the cause of this issue and given me a fix for the next release!