3 Virtual Machines
1 DHCP server, 1 Web server, 1 client
727723EUIT223
SHOBAN CHIDDARTH
IT D
SKCET
This guide was written for
Host-only ethernet adapter is a networking adapter in virtual box that allows the VMs, and the host to communicate with each other through a subnet that will not have a connection to the outside internet by default. We should create another adapter for our use case and use it on all the Virtual Machines we are going to create for this scenario.
Open Virtualbox Manager -> Tools -> 3 lines -> Network -> Host Only Networks
Now click on the create button.
Click yes for the Windows Administrator prompt and a new Host-Only Ethernet adapter will be created.
You can change the IP subnet if you want but make sure the host is the first IP of the subnet.
Here we have 192.168.199.1/24. Do not enable the DHCP server since we will create a VM for it.
We want our VMs to access the internet to download software for DHCP server and web server so we will be bridging our real network interface to share the internet connection to this host only ethernet adapter.
Open Network and Sharing Center in Control Panel, and click on “Change Adapter Settings”
Find the name of the virtual box host only ethernet adapter you created just now.
In my case it is Ethernet 5. Now right click on your real network interface you use to connect to the internet (in my case it is Wifi 5) and click on Properties and go to the Sharing tab.
Select the “Allow other network…” checkbox and then select the virtualbox host only ethernet adapter (ethernet 5) in the dropdown.
Click on Ok and you will get this prompt
This means the host IP has been changed. Click yes and then go to virtual box manager, the host only network management part we were earlier, and select the newly created network. Make sure the IP address for the host is the same as in the popup window we got right above.
Create a VM like you would normally, I have used a debian 13 VM.
The first VM we need is a dhcp server, because we disabled the default DHCP server of virtualbox, we need a VM acting as the DHCP server to assign IP address to other clients. Before booting this up, click on the settings on the top center and click on Networking.
Make sure the network adapter is set to host only and select the newly created interface in the drop down, and make sure all other adapters are disabled.
Now we will be cloning this VM 2 times, one for the webserver and one for the client. Just right click on the name and click clone. Edit the name and make sure to select “Generate new MAC Address” in this dropdown.
Do it another time for the client and make sure the network adapter settings are same for both of them, compared to the dhcp server.
Boot up the DHCP server. Open up network settings and assign a static IP
Set the
IP: 192.168.137.2
Subnet: 255.255.255.0
Gateway: 192.168.137.1 (the host’s IP we saw earlier)
Click on apply. Now we have a static IP for the DHCP server.
Run the command sudo apt install isc-dhcp-server. You will get some errors, it is expected.
This happens because there are no entries in the dhcp pool. So edit the file /etc/dhcp/dhcpd.conf and add these lines at the end.
subnet 192.168.137.0 netmask 255.255.255.0 {
range 192.168.137.10 192.168.137.254;
option routers 192.168.137.1;
option domain-name-servers 1.1.1.1;
}
We have created the subnet 192.168.137.0/24, made IPs 10-255 available in the dhcp pool, added the default gateway as router and optionally included a dns server.
Now we have to specify which interface the isc-dhcp-server should operate on.
Run sudo ifconfig. Locate the network interface with the static IP you set and copy its name. In my case it is enp0s3.
Now edit the file /etc/default/isc-dhcp-server and set the INTERFACESv4 value to the name you copied.
It should look like this:
Now save the file.
Now run the command
sudo systemctl restart isc-dhcp-server followed by
sudo systemctl enable isc-dhcp-server
If you get no errors, it means the DHCP server is enabled and running, and will continue to run even if the VM is rebooted.
Leave this VM as is and start boot the web server VM.
Follow the steps used to set a static IP address to the DHCP server but instead select DHCP as an IP configuration mode in the final step, the webserver will automatically get an ip address (It will be the default setting). In my case, the webserver (automatically assigned) IP is 192.168.137.50.
Now install an apache webserver on this as usual and enable it.
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
sudo nano /var/www/html/index.html (optional)
Now open localhost in a web browser inside the VM (or curl http://localhost:80) to check if you are able to see the html file at /var/www/html/index.html.
It works on my virtual machine. You should also be able to see this website from your host, via the IP assigned to your VM.
We are almost done.
Without turning off the DHCP server and the web server, boot up the client normally and set the IP address to DHCP (it will be the default).
My client’s IP is 192.168.137.10. But we do not need this information. Now open a web browser in the client and visit http://192.168.137.50 (the IP of the webserver).
It works. Everything works as intended.
On the dhcp server, run the command cat /var/lib/dhcp/dhcpd.leases. This will show current and previous dhcp leases. (you will also be able to view the website from the dhcp server).
Try opening the webserver’s IP in browsers of host and other VM’s, try running curl command as well.
(Includes opening website on host, opening website on client VM, opening localhost on web server VM, showing /var/www/html/index.html file in host VM, showing dhcp leases file on DHCP server VM.