4

I installed Ubuntu server 14.04. and assigned static IP to it... then installed KVM and Virtual machine manager... then created a test virtual machine and it worked fine also with local IP address over NAT.

I have two LAN Card and only one is connected to internet.

What i want is configuration to bridge em2 to guest machines. So, that static ip address work also for guest machines. Right now if i assing static ip to guest machine there is no connectivity.

My ifconfig details is:

ifconfig -a

em1       Link encap:Ethernet  HWaddr 0c:c4:7a:4d:96:aa  
          UP BROADCAST MULTICAST  MTU:1500  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:1000  
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)  
          Memory:f7100000-f717ffff  

em2       Link encap:Ethernet  HWaddr 0c:c4:7a:4d:96:ab  
          inet addr:68.168.105.130  Bcast:68.168.105.255  Mask:255.255.255.0  
          inet6 addr: fe80::ec4:7aff:fe4d:96ab/64 Scope:Link  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
          RX packets:3717 errors:0 dropped:10 overruns:0 frame:0  
          TX packets:373 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:1000  
          RX bytes:269655 (269.6 KB)  TX bytes:239608 (239.6 KB)  
          Interrupt:20 Memory:f7200000-f7220000  

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:65536  Metric:1  
          RX packets:123 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:123 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:0  
          RX bytes:8881 (8.8 KB)  TX bytes:8881 (8.8 KB)  

virbr0    Link encap:Ethernet  HWaddr 52:54:00:23:1c:65  
          inet addr:192.168.100.1  Bcast:192.168.100.255  Mask:255.255.255.0  
          UP BROADCAST MULTICAST  MTU:1500  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)  

virbr0-nic Link encap:Ethernet  HWaddr 52:54:00:23:1c:65  
          BROADCAST MULTICAST  MTU:1500  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:500  
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B) 

and /etc/network/interfaces details is:

auto lo  
iface lo inet loopback  


auto em2  
iface em2 inet static  
        address 68.168.105.130  
       netmask 255.255.255.0  
       network 68.168.105.0  
       broadcast 68.168.105.255  
       gateway 68.168.105.1  
       # dns-* options are implemented by the resolvconf package, if installed  
        dns-nameservers 8.8.8.8  
        dns-search dedicated.codero.net 
  • Are you saying you have multiple public static IP addresses (for example 68.168.105.129), and you want to use additional ones on your quest VM's, bridged via em2? – Doug Smythies Jun 18 '15 at 18:29
  • Yes, this is dedicated server and i want to assign remaining 3 extra IP to different guest OS.. IP Pool i have is 68.168.105.101-68.168.105.103 and only lan card that is online is em2 already assigned static ip – mustking Jun 18 '15 at 19:02
  • O.K. it is just so unusual, is why I wanted to check. I posted an answer that should work. – Doug Smythies Jun 19 '15 at 0:27
  • meta.askubuntu.com/questions/14089/… – Tim Jun 28 '15 at 10:59
5

Step 1: Create the bridge

You probably have bridge-utils installed already, but in case you don't:

sudo apt-get install bridge-utils

In the host and as root, edit /etc/network/interfaces:

auto lo
iface lo inet loopback

auto br0
iface br0 inet static
address 68.168.105.130
netmask 255.255.255.0
network 68.168.105.0
broadcast 68.168.105.255
gateway 68.168.105.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 8.8.8.8
dns-search dedicated.codero.net 
bridge_ports em2
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off

Now you can either re-boot or:

sudo ifup br0

Reference

Step 2: Modify your VM definition to use the bridge

Note: There is probably a way to do this step using virt-manager, however I do not use it and do not know how.

Use virsh edit and change your interface definition lines to use bridging instead of what is currently being used. Here is an example from one of my VMs. Before:

<interface type='network'>
  <mac address='52:54:00:0d:ed:95'/>
  <source network='default'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>

after:

<interface type='bridge'>
  <mac address='52:54:00:0d:ed:95'/>
  <source bridge='br0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>

Step 3: Specify the static IP address in the guest VM

Now, while running the guest VM, which might have network issues for the moment, edit /etc/network/interfaces and add the static definition for the interface name. For example, and guessing a little for your setup:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 68.168.105.101
netmask 255.255.255.0
network 68.168.105.0
broadcast 68.168.105.255
gateway 68.168.105.1
dns-nameservers 8.8.8.8
dns-search dedicated.codero.net 

Notes:

The default editor used by virsh edit is as defined by the $EDITOR environment variable, or vi if it does not exist. add export EDITOR="/bin/nano" to your ~/.bashrc file to set, for example, nano as your default editor.

You MUST use virsh edit do not edit the XML file directly, as virsh edit will do a bunch of checks upon save and exit. From any directory, and for example, do:

virsh edit desk_tt
  • 2
    As far as I know virt-manager is regarded as a good tool, I just don't use it. A backup solution is a different question, and I don't know anyhow. I just use rsync to another computer. I spent considerable time on my answer. If it worked for you, please accept it. – Doug Smythies Jun 19 '15 at 18:20
  • are you suggesting to replace the existing entry em2 (presumably the hardware interface) with the entry for br0 in etc/network/interfaces? Or is the br0 entry added? – Mausy5043 Jun 28 '15 at 13:34
  • @Mausy5043: The existing entry is replaced. Notice that em2 is still referenced via the bridge_ports directive. – Doug Smythies Jun 28 '15 at 14:04
  • Thanks. Now manpages.ubuntu.com/manpages/precise/man5/… starts to make sense. ;-) – Mausy5043 Jun 28 '15 at 14:27
  • @CodeMed : Sorry, I don't have anything to add over what I said in my answer here. It should not be such a difficult thing as all you seem to be having to go through. – Doug Smythies Mar 24 '17 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.