VM as DHCP server for your network

Discussions related to using VirtualBox on Windows hosts.
Post Reply
datatraveler
Posts: 3
Joined: 15. Jul 2021, 12:52

VM as DHCP server for your network

Post by datatraveler »

I'm new to networking and only vaguely familiar with VirtualBox; but most of what I'm trying to achieve went smooth. I'm stuck with the DHCP server and at this point I'm not even sure if my configuration of my Virtual machine is done correctly.

I have a windows Host, running Virtualbox 6.1. for an Ubuntu 20.04 Guest. On that physical machine I have two ethernet ports. One is wired to a modem, the other is wired to a switch. The goal is to have my ubuntu Guest act as a DHCP server for all machines connecting to that switch. Like the image below: (can't post it as a link)
i.ibb.co/RjJKmSJ/Screenshot-2021-07-15-135517.png


In the networktab I have enabled two adapters:
- adapter 1 is set to a Bridged Adapter using port X ==> Port X goes to the modem == enp0s3
- adapter 2 is set to a Bridged Adapter using port Y ==> Port Y goes to the switch == enp0s8

When I run that Virtual machine I see both network interfaces. enp0s3 and enp0s8. I have configured ICS DHCP to use interface enp0s8. I've done that in /etc/default/isc-dhcp-server/isc-dhcp-server by setting INTERFACES="enp0s8"

Now I have a switch set upwith a wired connection to a laptop.

journalctl -u dhcpd gives me no logs

journalctl -u isc-dhcp-server gave me error messages when I set up the system, yet after tripplechecking the config it claims to receive DHCPREQUESTS.

Code: Select all

timestamp serverhostname dhcpd[895]: DHCPREQUEST for 10.0.1.3 from macadres (hostnameOfConnectedPC) via enp0s8
timestamp serverhostname dhcpd[895]: DHPACK on 10.0.1.3 to macadres (hostnameOfConnectedPC) via enp0s8
timestamp serverhostname dhcpd[895]: reuse_lease: lease age 17 (secs) under 25% threshold, reply with unalter, exist>
the above three lines keep repeating themselves.

On the connected laptop when I run ipconfig I can see the assigned 10.0.1.3 address.

my ipconfig for the ethernet port shows:

Ethernet adapter Ethernet:

Connection-specific DNS Suffix . : intranetDOTmedusaDOTorg
IPv4 Address. . . . . . . . . . . : 10.0.1.3
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.0.1.1

When I log in on the guest machine and visit 10.0.1.1 I can

However
I can not ping 10.0.1.1 and when I look disconnect the wifi and look at the networkstatus; my wired connection is stuck on 'identifying' or 'Unidentified network'

The moment I disconnect the wire from the switch, my laptop correctly loses the Connection-specific DNS Suffix. Is there something wrong in my setup in VirtualBox, or do I relook my ISC DHCP configuration. I've checked the ISC DHCP knowledgebase, but I don't see any articles on Virtualbox. I'd also expect my gateway to be 10.0.0.1 as that is how ISC DHCP is configured. Is the windows HOST OS intervening somewhere? Also, what is the proper name for such a setup, so I know what to look for.

Many thanks in advance!
BillG
Volunteer
Posts: 5102
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: VM as DHCP server for your network

Post by BillG »

I doubt that it has much to do with VirtualBox. When you set a NIC to bridged mode, the vm will behave just as if it was connected directly to the network it is bridged to. In other words, the vm appears to be connected to the physical network, just like the physical NIC it is bridged to - the bridging software allows the vm and the host to share the same physical connection. I have done quite a bit of emulating physical networks in virtual ones and have never found any odd behaviour.

As a first move, I would reconfigure the DHCP server using a completely different IP subnet, like 192.168. 45.0/24 so it is obvious what happens.
Bill
datatraveler
Posts: 3
Joined: 15. Jul 2021, 12:52

Re: VM as DHCP server for your network

Post by datatraveler »

Hey Bill;
Thanks for shedding a light.

I added an interfaces="enp0s8"; to the dhcpd.conf; but that didn't help.

Reconfiguring /etc/dhcp/dhcpd.conf resulted in the PC connected to the switch not receiving the dns suffix nor IP on it's ethernet port. It also disabled the DNS (BIND9) and intranet lookup.

I restored the old config tried with and without the interfaces at the top.

When running dhcpd or sudo dhcpd I noticed it said it had no access to /var/lib/dhcp/dhcpd.leases

When using chown root:root on it and running dhcpd again, it passes without that error, yet as soon as I restart the server, the user of it changes back to dhcpd. I'll have to continue working on this from home and take a clone of the VM with me. I'm not sure what to do with it for now.

best regards
BillG
Volunteer
Posts: 5102
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: VM as DHCP server for your network

Post by BillG »

That is not really anything that we can help you with on this forum. That is an ubuntu/isc problem, and would be just the same on a physical network and physical machines.
Bill
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: VM as DHCP server for your network

Post by scottgus1 »

Keep in mind that the VM is just like another PC. If you have successfully connected the VM to the physical LAN with the Virtualbox Bridged network type, then the VM is just like another PC on the LAN.

If you can ping (and you may need to temporarily set static IP addresses to ping if you're trying to experiment with DHCP later) over the Virtualbox network, then the network is working. And then, as BilllG says, further problems are from configuration settings in the OS's, not in Virtualbox.
datatraveler
Posts: 3
Joined: 15. Jul 2021, 12:52

Re: VM as DHCP server for your network

Post by datatraveler »

BillG and scottgus1;

Thanks for helping me in narrowing down the issue. I have the VM with me at home and I'm waiting for a few pieces of hardware to emulate the on-site environment as best I can. I'm only vaguely familiar with Ubuntu and ISC is a totally new tool for me; but I can look into it in more detail now.

Best regards!
Post Reply