NAT network and the virtual machines

To install VirtualBox guest additions, some packages are needed. Ubuntu server does not automount the CD and does not autostart the installation. The following commands do the installation:
frigo@dnsmasq:~$ sudo apt-get install build-essential dkmsThe VirtualBox guest additions are easy to install to client.vb.nat, using the graphical interface of the desktop Ubuntu.
frigo@dnsmasq:~$ sudo mount /dev/sr0 /mnt
frigo@dnsmasq:~$ sudo /mnt/VBoxLinuxAdditions.run
frigo@dnsmasq:~$ sudo eject
Preparation: hosts and interfaces
After installation, the /etc/hosts file contains the name of the server with the 127.0.0.1 IP address that leads to a lot of trouble, so fix it as the first step:frigo@dnsmasq:~$ sudo vi /etc/hosts
127.0.0.1 localhostThe second step of preparation is to set a fixed IP address for the DNS and DHCP server.
192.168.4.15 dnsmasq.vb.nat dnsmasq
frigo@dnsmasq:~$ sudo vi /etc/network/interfaces
# The loopback network interfaceTesting:
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.4.15
netmask 255.255.255.0
network 192.168.4.0
broadcast 192.168.4.255
gateway 192.168.4.1
dns-nameservers 8.8.8.8 # Google Public DNS
dns-search vb.nat
frigo@dnsmasq:~$ sudo service networking restart
Install and configure dnsmasq
The dnsmasq package is easy to install. The default configuration file contains 500+ lines of documentation and examples in the form of comments. The installation and the options that worked for me:frigo@dnsmasq:~$ sudo apt-get install dnsmasq
frigo@dnsmasq:~$ sudo vi /etc/dnsmasq.conf
# Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces.
bogus-priv
# Listen on eth0 (this option may be superfluous)
interface=eth0
# Set the domain for dnsmasq.
domain=vb.nat
# Enable the integrated DHCP server
dhcp-range=192.168.4.50,192.168.4.150,12h
# Override the default route supplied by dnsmasq
dhcp-option=3,192.168.4.1
Finished. Disable DHCP in VirtualBox.
Testing - use Alt-F1 and Alt-F2 to have two text consoles or use terminal windows in the graphical interface of client.vb.nat to ssh into dnsmasq:
frigo@dnsmasq:~$ tail -f /var/log/syslogYou can restart client.vb.nat and see the DHCP handshake in dnsmasq syslog. Some simple tests:
frigo@dnsmasq:~$ sudo service dnsmasq restart
frigo@client:~$ nslookup dnsmasq.vb.nat
Server: 127.0.1.1
Address: 127.0.1.1#53
Name: dnsmasq.vb.nat
Address: 192.168.4.15
frigo@client:~$ nslookup client.vb.nat
Address: 192.168.4.147
frigo@client:~$ nslookup ubuntu.com
Address: 91.189.94.156
Useful information
This blog entry was inspired by the three articles about configuring isc-dhcp-server and bind9 at raerek.blogspot.hu (in Hungarian):- http://raerek.blogspot.hu/2012/03/dhcp-szerver-ubuntu-1204-en.html
- http://raerek.blogspot.hu/2012/04/ddns-ubuntu-1204-en-elso-resz.html
- http://raerek.blogspot.hu/2012/04/ddns-ubuntu-1204-en-masodik-resz.html
- https://wiki.debian.org/HowTo/dnsmasq
- https://help.ubuntu.com/community/Dnsmasq
- http://xmodulo.com/2012/10/how-to-set-up-dhcp-server-using-dnsmasq.html
- http://edoceo.com/howto/dnsmasq