How to set up a DHCP server on Ubuntu?

by georgiana.senger , in category: Networking & Wireless , 2 years ago

How to set up a DHCP server on Ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by samara , 2 years ago

@georgiana.senger 

To set up a DHCP server on Ubuntu, you can follow these steps:

  1. Open a terminal window on your Ubuntu machine.
  2. Install the DHCP server software by running the following command:
1
2
sudo apt-get update
sudo apt-get install isc-dhcp-server


  1. Configure the DHCP server by editing the /etc/dhcp/dhcpd.conf file. You can use any text editor you prefer to open the file, but we will use nano in this example:
1
sudo nano /etc/dhcp/dhcpd.conf


  1. In the dhcpd.conf file, you need to specify the network parameters that you want to assign to clients. Here's an example configuration:
1
2
3
4
5
6
subnet 192.168.1.0 netmask 255.255.255.0 {
   range 192.168.1.100 192.168.1.200;
   option routers 192.168.1.1;
   option domain-name-servers 8.8.8.8, 8.8.4.4;
   option broadcast-address 192.168.1.255;
}


This configuration specifies that the DHCP server will assign IP addresses in the range 192.168.1.100-192.168.1.200 to clients, and the default gateway (router) will be 192.168.1.1. The DNS servers are set to 8.8.8.8 and 8.8.4.4, and the broadcast address is set to 192.168.1.255.

  1. Save the dhcpd.conf file and exit the text editor.
  2. Configure the DHCP server to listen on a specific network interface. To do this, edit the /etc/default/isc-dhcp-server file:
1
sudo nano /etc/default/isc-dhcp-server


  1. Uncomment the line that specifies the network interface, and change it to the appropriate interface name for your system. For example:
1
INTERFACESv4="eth0"


  1. Save the isc-dhcp-server file and exit the text editor.
  2. Start the DHCP server by running the following command:
1
sudo systemctl start isc-dhcp-server


  1. Enable the DHCP server to start automatically at boot time:
1
sudo systemctl enable isc-dhcp-server


That's it! You now have a DHCP server set up on your Ubuntu machine. You can test it by connecting a client computer to the network and verifying that it receives an IP address from the server.

by aglae_feil , 5 months ago

@georgiana.senger 

Additional Step: It's recommended to restart the DHCP server after making any changes to the configuration file. You can do this by running the following command:

1
sudo systemctl restart isc-dhcp-server