[Université Paris Diderot, INRIA]

Pierre Letouzey

Emulators: common network configuration

Even if it's not mandatory, it's _really_ convenient to establish a network communication between the host machine and the emulated one. This way, one can run an ssh session on the emulated machine, and in particular get rid of all the keyboard issues. Additionally, scp allows to solve the question on file transferts from/to the virtual machine.

VDE

I suggest to use VDE to configure our virtual network once and for all. Currently, both qemu and pearpc can be made to use this VDE virtual network, but not gxemul (see below).

apt-get install vde

Now, just add in /etc/networks/interfaces a configuration for a virtual network similar to this:

auto tap0
iface tap0 inet static
  address 192.168.1.1
  network 192.168.1.0
  netmask 255.255.255.0
  vde-switch vde-net
Warning: for this to work, your kernel must know about tun/tap networking. In debian this is default, otherwise check with modprobe tun.

Now start this network:

ifup tap0

You should also grant your regular user acces to this virtual network:

adduser yourself vde-net

DHCPD

it's really cool not to have to bother anymore about network configuration inside the emulated machines. For that, we can use a DHCP server on the host, that will answer to DHCP requests on this virtual network device tap0:

apt-get install dhcp
Then adapt /etc/dhcpd.conf to your needs, for example:
#
# Sample configuration file for ISC dhcpd for Debian
#

option subnet-mask 255.255.255.0;
default-lease-time 6000;
max-lease-time 7200;

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.2 192.168.1.10;
  option routers 192.168.1.1;
  option domain-name-servers XYZ.XYZ.XYZ.XYZ;
  option domain-name "fill.your.domain.here";  
}
Finally enable dcphd by editing /etc/default/dhcp:
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#       Separate multiple interfaces with spaces, e.g. "eth0 eth2".
INTERFACES="tap0"
And launch this daemon:
/etc/init.d/dhcp restart

NAT

Here is a small script that should provide internet acces to your virtual machines using NAT translation. WARNING: this script is _really_ permissive. Use with care, and adapt to you needs in term of security:
INET_IP="ABC.DEF.GHI.JKL"  #the IP of your real machine
INET_IFACE="eth0"          #the network device used to access internet

/sbin/modprobe ip_conntrack
/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_nat
echo "1" > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables -t nat -A POSTROUTING -o $INET_IFACE -j SNAT --to-source $INET_IP