GenVM - Scripts host - Configure network

This script configure network of virtual machine from host.

Configuring by DHCP

# GenVM script: Configure network (using DHCP)

cat > "${MOUNT_POINT}/etc/network/interfaces" <<[*_EOF_*]
auto lo eth0

iface lo inet loopback

iface eth0 inet dhcp

[*_EOF_*]

You need to install ifupdown and udhcpc or isc-dhcp-client.

Configuring fixed IP

# GenVM script: Configure network (fixed IP)

## parameters ##

_ip_=<your ip>
_netmask_=<netmask>
_gateway_=<your gateway>
_nameservers_=<list of nameservers separate by space>
_domain_=<your domain>
_other_domains_=<other domain for searches>

## main ##

IFS=$' \t\n'

cat  > "${MOUNT_POINT}/etc/network/interfaces" <<[*_EOF_*]
auto lo eth0

iface lo inet loopback

iface eth0 inet static
	address ${_ip_}
	netmask ${_netmask_}
	gateway ${_gateway_}
	dns-search ${_domain_} ${_other_domains_}
	dns-nameservers ${_nameservers_}
[*_EOF_*]

cat > "${MOUNT_POINT}/etc/resolv.conf" <<[*_EOF_*]
domain ${_domain_}
search ${_domain_} ${_other_domains_}

[*_EOF_*]

for srv in ${_nameservers_} ; do
	echo "nameserver ${srv}" >> "${MOUNT_POINT}/etc/resolv.conf"
done

Configure parameters to your needs, example:

_ip_=192.168.0.111
_netmask_=255.255.255.0
_gateway_=192.168.0.1
_nameservers_="192.168.0.254 8.8.8.8 8.8.4.4"
_domain_=genvm.eu
_other_domains_="intranet.genvm.eu dmz.genvm.eu"

You need to install ifupdown and iproute2.

Downloads

Download script: