DHCP Server

This activity configures a DHCP service in r1 and r2 which will handle IP configuration requests from net1 and net2 subnets respectively.

When completed, hosts within net1 and net2 subnets (web, ws1, ws2) will have their network settings configured dynamically via DHCP.

Deliverable

dhcp server

Setup

Ensure web, ws1 and ws2 are configured to obtain their IPv4 configuration dynamically; i.e. remove their statically assigned IPv4 addresses and set their configuration method to be automatic.

You will need to use the nmtui tool to achieve this.



Configuration steps

In general, there are three steps involved in provisioning a service on Linux:

  • Edit configuration file (typically located under the /etc/ directory)
  • Validate configuration file - check for any syntax errors
  • Enable and start the service - often by leveraging the systemd framework

Edit configuration file

The dhcpd service listens to requests based on the subnets declarations inside the /etc/dhcp/dhcpd.conf file. In both r1 and r2, find this file and open it using your preferred text editor, and add configuration options to allocate addresses as described in the diagram.

An example configuration is given below (this is only an example; your configuration must use the IP subnets specified in the diagram):

Example dhcpd.conf file

# /etc/dhcp/dhcpd.conf

# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp-server/dhcpd.conf.example
#   see dhcpd.conf(5) man page
# Global options
# option domain-name "2620.acit";
option domain-name-servers 8.8.8.8, 10.20.30.254;

subnet 192.168.15.0 netmask 255.255.255.128 {
	# routers option defines the default gateway for clients
	option routers 192.168.15.126;

	# range specifies the start and end of address range
        # this will provision a range of 40 addresses
	range 192.168.15.10 192.168.15.50;	
}

# the host declaration is a container for the configuration
# of a specific host. The name is arbitrary but generally
# the same as the hostname.

host host1 {
	# the hardware statement is used to match the MAC address
	# of a particular host 
	hardware ethernet 02:00:00:00:00:03;

	# fixed address is used to consistently assign an IP address
	# to the host specified by the MAC address given above.
	fixed-address 192.168.15.1;
}

host host2 {
	hardware ethernet 02:00:00:00:00:04;
		
	fixed-address 192.168.15.2;
}    

Enable and start the service

  1. Check syntax errors:
sudo dhcpd -t
  1. Start the service:
sudo systemctl start dhcpd.service
  1. Enable the service to always start at boot:
sudo systemctl enable dhcpd.service

Add routes on your Windows workstation

To be able to log into your net1 and net2 hosts from your host, you need to add routes.

Run the following command in Powershell as administrator to add a route to net1:

New-NetRoute -DestinationPrefix "172.26.20.0/27" -InterfaceIndex $index -NextHop 10.26.20.100

where $index is the interface index of your Host-Only Ethernet Adapter #2 (hint: run Get-NetAdapter to find out the index value)

For convenience, you may also update your ./ssh/config file with login credentials for web and ws1.

macOS users

If you are on a mac, you may need to do a bit of internet search to find out how to add routes permanently on your system.
This blog post might provide answers (I can't guarantee that it works on all mac versions)

Troubleshooting

  • Before starting the service, ensure there are not syntax errors by running: sudo dhcpd -t.
  • Ensure the subnet declarations in your configuration files match those in your topology.
  • Check service status: systemctl status dhcpd.service
  • To check logs messages while the service is running: journalctl -u dhcpd