PACC: Week IV [VM network connection]

For this week, I continued to work with M23 program. Particularly on problem how to get to VM IP adress from physical network and VM be able to see all the machines in it. There are some different ways to do that:

User network

  • You need a simple way to give virtual machine access to the Internet and in your local network

  • You do not need access to the virtual machine from the network or from other virtual machines

  • Note: user network does not support some features of networks, such as ICMP, so some applications (such as ping) may not work properly

Requirements

  • Tuned and running virtual machines

  • If you do not want to run it from a root-and, then, for your user needs to have read / write access to / dev / kvm

  • If the virtual machine you want to access the Internet or a local network, then the host system must have access to these networks

Implementation:

Just run the virtual machine with the parameters "-net nic-net user", for example: qemu-system-x86_64-hda / path / to / hda.img-net nic-net user

Remarks:

  • IP-address can be assigned automatically DHCP-server integrated into QEMU;

  • If you want to run multiple virtual machines, you do not need to assign them to different MAC-addresses; With the option "hostfwd" you can get access to a port on the virtual machine. For example, if you want to transfer a file from the host system to a virtual machine, start the car with the parameters "-net nic-net user, hostfwd = tcp :: 5555 -: 22". In this case, you redirect port 5555 from the host system on the virtual machine port 22. The command "scp-P 5555 file.txt root @ localhost :/ tmp", performed on the host system, copy the file to the virtual machine. You can also use a different address for the host system connection.

Public Bridge

You want to assign the IP-addresses of virtual machines and make them accessible from the local network;

** Requirements**:

  • Tuned and running virtual machines;

  • If you do not want to run it from a root-and, then, for your user needs to have read / write access to / dev / kvm;

  • If you do not want to run them from a root, for you will need to configure sudo to run them:

/ Sbin / ip / Usr / sbin / brctl / Usr / sbin / tunctl
  • The host system must have access to the Internet and the local network.

1st way:

Create a file / etc/net/ifaces/breth0/options with following:

TYPE = bri BOOTPROTO = dhcp HOST = eth0 DISABLED = no NM_CONTROLLED = no

Apply the new network configuration command:

/ Etc / init.d / network restart

Bridges interface breth0 should get IP-address, and interface eth0 should be without an address. Features VLANs If you are using VLANs but the virtual machine traffic is not reaching, run the following commands:

# Cd / proc / sys / net / bridge # Ls bridge-nf-call-arptables bridge-nf-call-iptables bridge-nf-call-ip6tables bridge-nf-filter-vlan-tagged # For f in bridge-nf-*; do echo 0> $ f; done

_2nd way: _

Create a bridge command:

sudo / usr / sbin / brctl addbr br0

Add a physical interface to the bridge, such as eth0:

sudo / usr / sbin / brctl addif br0 eth0

Create a qemu-ifup script as follows:

#! / Bin / sh set-x switch = br0 if [ -n "$1" ]; then /usr/bin/sudo /usr/sbin/tunctl -u `whoami` -t $1 /usr/bin/sudo /sbin/ip link set $1 up sleep 0.5s /usr/bin/sudo /usr/sbin/brctl addif $switch $1 exit 0 else echo "Error: no interface specified" exit 1 fi

Generate MAC-address manually or automatically using a script:

#! / Bin / bash # Generate a random mac address for the qemu nic printf 'DE: AD: BE: EF:% 02X:% 02X \ n' $ ((RANDOM% 256)) $ ((RANDOM% 256))

Run each virtual machine by replacing $ macaddress value obtained in the previous step:

qemu-system-x86_64-hda / path / to / hda.img-net nic, macaddr = $ macaddress-net tap

Remarks: If you do not want to run the machine from root-and the script qemu-ifup should work correctly on your person; You can create a system-wide script, calling it in / etc / qemu-ifup  or use any other name, indicating it when you start the machine:

qemu-system-x86_64-hda / path / to / hda.img-net nic, macaddr = $ macaddress-net tap, script = / path / to / qemu-ifup

Each virtual machine is connected to the internal virtual bridge must have its own MAC-address that is different from that of the other machines.

Comments