It’s just yulistic!

Configuring dnsmasq only for DHCP server in Ubuntu PC

· by yulistic · Read in about 2 min · (349 Words)
dnsmasq DHCP server Ubuntu Linux


To configure my own DHCP server with dnsmasq on my Ubuntu PC. A commercial router is running together.
(Actually, I wanted to setup a PXE boot server with dnsmasq.)


  • A local LAN with the router that can disable its DHCP server functionality.
  • Ubuntu 16.04 machine, dnsmasq installed.


  1. Install dnsmasq.

    sudo apt install dnsmasq
  2. Configure dnsmasq by writing the default configuration file(/etc/dnsmasq.conf) or a new file in the path /etc/dnsmasq.d/(For example, /etc/dnsmasq.d/dhcp.conf). The default configuration file includes a neat and detailed description of each configuration parameter.

    # Set the interface on which dnsmasq operates.
    # If not set, all the interfaces is used.
    # To disable dnsmasq's DNS server functionality.
    # To enable dnsmasq's DHCP server functionality.
    # Set static IPs of other PCs and the Router.
    dhcp-host=90:9f:44:d8:16:fc,iptime,,infinite     # Router
    dhcp-host=31:25:99:36:c2:bb,server-right,,infinite   # PC1   
    dhcp-host=ac:97:0e:f2:6f:ab,yul-x230,,infinite  # PC2
    # Set gateway as Router. Following two lines are identical.
    # Set DNS server as Router.
    # Logging.
    log-facility=/var/log/dnsmasq.log   # logfile path.
    log-queries # log queries.
    log-dhcp    # log dhcp related messages.
  3. (Re)start dnsmasq service. You can check status of dnsmasq with systemctl command.

    sudo service dnsmasq restart
    sudo systemctl status dnsmasq.service
  4. Also you need to set the dnsmasq server ip. My network interface name was enp5s0. Set it as yours. Also, the server address was set to in the following example.

    # interfaces(5) file used by ifup(8) and ifdown(8)
    auto lo
    iface lo inet loopback
    auto enp5s0
    iface enp5s0 inet static
  5. Restart networking service. If it does not work, just reboot the machine.

    sudo service networking restart
  6. You need to disable DHCP server functionality of your router. Restart the dnsmasq service after disabling it.

Other tips

  1. You can register dnsmasq as startup service. (Make it run whenever the machine is rebooted.)

    update-rc.d dnsmasq defaults
  2. Checking the list of current clients that received IPs from DHCP service.

    sudo cat /var/lib/misc/dnsmasq.leases
  3. To read logs when the log file is not set in the configuration file.

    sudo journalctl -u dnsmasq.service
  4. To test the configuration.

    dnsmasq --test