# virtual DNS and DHCP



## marboxer (Feb 28, 2010)

Hi to all. Sorry for my bad english in this long message.
For auto-educational purposes I'm experimenting with a WinXP host and a virtual network using VirtualBox 3.1.2.56127.
I've created 3 virtual FreeBSD 8.0 PCs.
The REAL PC is connected to the internet with an ADSL router; real router has a static IP 192.168.0.1; real PC NIC address is 192.168.0.2.
The first virtual PC works as a gateway between two nets with this configuration:
- 1 NIC in NAT - DHCP - assigned address 10.0.2.15 (the standard IP automatically assigned by VirtualBox 3.1.2)
- 1 NIC in Internal Network - IP 172.16.1.1/24
- 1 NIC in Internal Network - IP 172.16.2.1/24
This configuration lets me go on the internet and gives me access to the clients on the 2 nets.
Both virtual clients ping the others virtual PCs and both clients can access FTP area of the others virtual PCs.
This is (part) of the virtual gateway's /etc/rc.conf:


```
hostname="fbsdgw.marbosoft.org"
#this is my real ADSL router
defaultrouter="192.168.0.1"      
ifconfig_em0="DHCP"
ifconfig_em1="inet 172.16.1.1 netmask 255.255.255.0"
ifconfig_em2="inet 172.16.2.1 netmask 255.255.255.0"
gateway_enable="YES"
```
This is first "client"'s rc.conf:


```
hostname="fbsdnw11.marbosoft.org"
ifconfig_em0="inet 172.16.1.2 netmask 255.255.255.0"
defaultrouter="fbsdgw"
```
The second "client" has a rc.conf file on a 172.16.2 net.

My basic idea is to create a virtual network which uses real PC and it's ADSL router (I'm working at home) only to allow my virtual gateway to access the internet (which is now possible).

I'm not interested in communicating with real PC. I'd like to simulate a Small Office situation with a gateway, which should be the only one with an internet access (the second group of problems came when I configured a DNS server and a DHCP server; maybe, in the future, I'll set up a NFS server, a Samba server ... and so on); the client virtual PCs should go on the internet through the gateway.

The problem is that virtual gateway accesses the internet, but the virtual clients don't.

This is the output for netstat -r from virtual gateway


```
Routing tables
Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            10.0.2.2           UGS         1       61    em0
10.0.2.0           link#1             U           0        0    em0
10.0.2.15          link#1             UHS         0        0    lo0
localhost          link#4             UH          0       20    lo0
172.16.1.0         link#2             U           0        0    em1
fbsdgw             link#2             UHS         0        0    lo0
172.16.2.0         link#3             U           0        0    em2
172.16.2.1         link#3             UHS         0        0    lo0
```
10.0.2.2 is the address of VirtualBox DHCP.

I've tried to configure em0 as a NIC with a bridge, but I've failed (probably for a fault of knowledge about bridges).

Second problem with DNS and DHCP.
Not considering the problem above, the situation is ok for DNS. 
Later, I've successfully installed DHCP, on both the server (the same which also acts as a DNS server) and on one client.
But when I try to make the server programs (*named* and *dhcpd*) to cooperate, I get lost in the documentation (I'm using different sources), and the situation collapses.
My client, which has a new DHCP assigned address, correctly pings the other virtual PC in the network, but when I ping this client from my virtual server, I see that it doesn't recognize the correct address (still present in the *zone* file); it always tries to ping *212.48.8.140*, and address which seems not to exist in the real world (or at least it seems not to be reachable from the real PC) nor, clearly, in my virtual little network.
Ok, I've made a mistake, normal. Actually, I haven't understood how the DHCP server updates zone files in the DNS server (both server programs are in the same virtual PC).
So I came back to static address for my client; both clients still ping the other, but my DNS server still tries to ping this mysterious (for me) address.
I've also uninstalled the BIND from ports and installed again, but nothing has changed.
So, two questions:
- Where can I find a document which explains how to use jointly the two servers (starting from a very basic point of view), how to use DNS and DHCP? When I read the documents I've found on the Internet, they correctly start considering security issues, but, for me, for now, that's not important; first I'd like to see them to work;
- what could be the reason of the strange behaviour of my virtual DNS server? I've solved starting with a new virtual PC, but I'd like to understand.
I hope this is not a too big post.

Thank for any help.

Marco


----------

