How to Install dnsmasq on Ubuntu Server Latest
In this tutorial, we will be installing dnsmasq on Ubuntu Server Latest. dnsmasq is a lightweight, easy-to-configure DNS server that can also provide DHCP and TFTP services. It is designed to be run on small networks and is particularly useful for home and office environments.
Step 1: Update and Upgrade System
Firstly, it is recommended to update and upgrade the system before proceeding.
sudo apt update
sudo apt upgrade
Step 2: Install dnsmasq
Next, we will install dnsmasq using the apt package manager.
sudo apt install dnsmasq
Step 3: Configure dnsmasq
Once installed, dnsmasq's default configuration file can be found at /etc/dnsmasq.conf. A sample configuration file can be found at /usr/share/doc/dnsmasq/examples/dnsmasq.conf.example.
We can modify the configuration file according to our needs. But before making any changes, it is recommended to make a copy of the original configuration file for backup purposes.
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
We can now edit the configuration file to suit our needs. To edit the configuration file, run the following command:
sudo nano /etc/dnsmasq.conf
Here are some configurations that you might want to add:
Set a DNS Server
To set a DNS server, we can add the following line to the configuration file:
server=8.8.8.8
Configure DHCP Service
To configure DHCP service, we can add the following lines:
interface=eth0
dhcp-range=192.168.1.100,192.168.1.150,12h
dhcp-option=3,192.168.1.1
dhcp-option=6,8.8.8.8
The interface directive specifies the network interface on which to provide DHCP service. In this example, it's eth0.
The dhcp-range directive specifies the range of IP addresses to be assigned by the DHCP server. In this example, it's 192.168.1.100 to 192.168.1.150.
The dhcp-option directive specifies DHCP options to be provided to clients. In this example, dhcp-option=3,192.168.1.1 sets the default gateway, and dhcp-option=6,8.8.8.8 sets the DNS server.
Step 4: Restart dnsmasq Service
After making the changes to the configuration file, we need to restart the dnsmasq service for the changes to take effect.
sudo systemctl restart dnsmasq
Step 5: Verify dnsmasq Service
We can verify that dnsmasq is running and functioning properly by running the following command:
sudo systemctl status dnsmasq
This should display the status of the dnsmasq service and confirm that it is active.
Conclusion
dnsmasq is a simple and lightweight DNS server that can also provide DHCP and TFTP services. It's easy to configure and perfect for small networks. In this tutorial, we've shown you how to install, configure, and use dnsmasq on Ubuntu Server Latest.