Search results

Search This Blog

Experiment - 71 :- Configuring a DHCP Server

 

Experiment: Configuring a DHCP Server

Objective:

To set up a DHCP server that automatically assigns IP addresses to clients on a local network.

Requirements:

  • A Linux machine (Ubuntu preferred) to act as the DHCP server.
  • A client machine (can be another physical or virtual machine) to test DHCP functionality.
  • Administrative access to both machines.

Procedure:

Step 1: Install the DHCP Server

  1. Update the Package List: Open a terminal on the server machine and run:

    bash
    1sudo apt-get update
  2. Install the ISC DHCP Server: Install the DHCP server package using the following command:

    bash
    1sudo apt-get install isc-dhcp-server

Step 2: Configure the DHCP Server

  1. Edit the DHCP Configuration File: Open the DHCP configuration file in a text editor:

    bash
    1sudo nano /etc/dhcp/dhcpd.conf
  2. Configure the DHCP Settings: Add the following configuration to the file. Adjust the subnet, range, and other parameters according to your network setup:

    bash
    1# DHCP Configuration file 2 3# Specify the subnet and netmask 4subnet 192.168.1.0 netmask 255.255.255.0 { 5 range 192.168.1.10 192.168.1.50; # Range of IP addresses to be assigned 6 option routers 192.168.1.1; # Default gateway 7 option subnet-mask 255.255.255.0; # Subnet mask 8 option domain-name "example.com"; # Domain name 9 option domain-name-servers 192.168.1.1; # DNS server 10}
  3. Save and Exit: Save the changes and exit the text editor (in nano, press CTRL + X, then Y, and Enter).

Step 3: Specify the Network Interface

  1. Edit the DHCP Server Defaults: Open the DHCP server defaults file:

    bash
    1sudo nano /etc/default/isc-dhcp-server
  2. Specify the Interface: Find the line that starts with INTERFACES and specify the network interface that the DHCP server should listen on. For example:

    bash
    1INTERFACES="eth0"

    Replace eth0 with the appropriate interface name (you can find it using ip a).

  3. Save and Exit: Save the changes and exit the text editor.

Step 4: Start the DHCP Server

  1. Restart the DHCP Service: Start or restart the DHCP server to apply the changes:

    bash
    1sudo systemctl restart isc-dhcp-server
  2. Check the Status: Verify that the DHCP server is running without errors:

    bash
    1sudo systemctl status isc-dhcp-server

Step 5: Test the DHCP Server

  1. Configure the Client Machine: On the client machine, ensure that the network interface is set to obtain an IP address automatically (via DHCP). This can usually be done in the network settings.

  2. Release and Renew the IP Address: On the client machine, open a terminal and run the following commands:

    bash
    1# For Linux 2sudo dhclient -r # Release current IP 3sudo dhclient # Request a new IP 4 5# For Windows 6ipconfig /release 7ipconfig /renew
  3. Check the Assigned IP Address: After running the commands, check the assigned IP address on the client machine:

    bash
    1# For Linux 2ip a 3 4# For Windows 5ipconfig

    You should see an IP address assigned from the range specified in the DHCP server configuration (e.g., 192.168.1.10 to 192.168.1.50).

Step 6: Monitor DHCP Leases

  1. Check the DHCP Leases File: You can view the leases granted by the DHCP server by checking the leases file:
    bash
    1cat /var/lib/dhcp/dhcpd.leases

Conclusion

You have successfully configured a DHCP server on a Linux machine. The server automatically assigns IP addresses to clients on the network. This setup is essential for managing

Post a Comment

If you have any doubts, please let me know

Previous Post Next Post