Configure dnsmasq DNS and DHCP server with resolvconf.

Dnsmasq is a light weight dns and dhcp server for small home networks, the dnsmasq configuration file is /etc/dnsmasq.conf open the file and read the hints for configuration for your need.
First check and remove or disable other dns and dhcp servers if any in the pc:

#update-rc.d -f bind9 remove
Open the file /etc/dnsmasq.conf and here are some example lines to edit:
resolv-file=/etc/resolv.conf
# Add local-only domains here,
local=/example.com/
local=/ecample.net/
listen-address=127.0.0.1
log-dhcp
If the pc is working as dns and dhcp server for the other clients in the network add the dhcp range:
dhcp-range=192.168.1.2,192.168.1.150,12h
The resolv.conf file contain the local and upstream nameservers, the dns resolver server read the resolv.conf file and forwarding the internet queries to these servers, the reading order of name server is from up to bottom, if the first nameserver failed will query the next one, this file updates the nameserver in every network connection.
If want to update the resolv.conf by your own nameservers, install the resolvconf package and add the nameservers to the /etc/resolvconf/resolv.conf.d/original:
nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4
Add the local host names to the /etc/hosts separated by the spaces, to resolv by the dns server query:
127.0.0.1 localhost
192.168.1.10 example example.net example.com
If the host has static ip (not changing with each new network connection) simply add the ip address to the /etc/hosts as above, but if the ip changes, the ip address of /etc/hosts should be updated for new ip address manually, to do it automatically with each new network connection, create a file updateHosts.sh and put in the in /etc/NetworkManager/dispatcher.d directory:
#!/bin/bash
# Replace the wlp2s0 with your network device name, this script updating the third line with this entry.
ip="$(ip addr ls wlp2s0 | grep '\' | cut -d' ' -f6 | cut -d'/' -f1)"
echo $ip | sed -i '3s/.*/'$ip' example example.com example.net/' > /etc/hosts
This script gets the wlp2s0 ip address and updates the third line of /etc/hosts, with the hosts entry above.


<< Previous Next >>