In this tutorial, I'll try to explain how to setup an Ubuntu 16.04 server as a DHCP server. In simple terms, your ubuntu server can provide / lease out IP-addresses to other clients(computers in your LAN).
1) Initial setup:
I am newly setting up this server, so I have to setup my IP-address, hostname, FQDN, etc. These are explained in this tutorial: Ubuntu Server-16: how to properly set hostname, domain name and FQDN
2) Install dhcp-server package: sudo apt-get install isc-dhcp-server
Figure-1: Install dhcp-server package
3) Configure DHCP server:
3a) Edit DHCP server configuration file: /etc/default/isc-dhcp-server.... and add the network interface the DHCP-service should be 'bound' to:
Assign a network interface: INTERFACES="enp0s3"
(ps:) my isc-dhcp-server file was totally blank, so i just entered the single line above. If your file has some contents, just find the line referring to INTERFACES, uncomment it and enter the name of your interface.
Below screenshot is after editing the interface:
Figure-2:configure dhcp-server interface
3b) Also edit dhcp.conf file at location: /etc/dhcp/dhcpd.conf
Modify it like as shown below with your own settings:
Enter the domain name and the domain-name-servers (refer to settings in #1: Initial Setup - above):
option definitions common to all supported networks...
option domain-name "mywebdomain.com";
option domain-name-servers ns1.mywebdomain.com, ns2.mywebdomain.com;
Note: I could also have used the actual IP-addresses of my domain-name-servers. For this tutorial, the IPs of my dns-servers are 192.168.1.7 and 192.168.1.8... refer to Figure-3(below)
3c) Make the DHCP server authoritative: (remove the # in the line that says "authoritative):
Figure-3: define dns-server hostname or IP and make server authoritative
3d) Scroll further down to the portion where you can see: "A slightly different configuration for an internal subnet":
- uncomment all the lines starting with "subnet" and ending with "}". Edit then with your own settings as below:
Figure-4: DHCP-server IP-settings
A short explanation:
- subnet & netmask are defined as 172.16.1.0 / 255.255.255.0 to match with my actual server settings
- option domain-name-servers: I used the actual IP-address of my dns-server
- option domain-name: my domain name
- option subnet-mask: subnet mask for my network
- option routers: IP-address of my router. Note this server is just a DHCP server and not a router inclusive, thus the router IP is not the same as the DHCP-server IP.
- option broadcast-address: broadcast address of my LAN
- default and max least times.
Save and exit from editor.
3e) restart DHCP service: sudo systemctl restart isc-dhcp-server
Check status of DHCP service: sudo systemctl status isc-dhcp-server
If all went well with your configuration, DHCP service should be up and running like this: (click image to enlarge)
Figure-5: DHCP-service running successfully
- DHCP-server is showing Active: active (running) in green
- No-IP-has been leased yet: (Wrote 0 leases to leases file)
4) Configure a client computer to obtain IP-addresses dynamically from the server: I am using a Windows and I just enabled DHCP.
Figure-6: Obtain IP address automatically setting on windows
IP-config/all results from command prompt:
Figure-7: ipconfig/all result on windows client PC
- observe that these settings match with those configured in section 3-d(above
Checking back on the status of our running DHCP-server, it shows 1-lease already:
command: sudo systemctl status isc-dhcp-server
Figure-8: (click to enlarge)
5) where is the leases file?
To see the active dhcp leases, check /var/lib/dhcp/dhcpd.leases
thats all folks!!
your comments are most welcome!!