Dnsmasq is a lightweight, easy to configure, DNS forwarder and DHCP server. It is designed to provide DNS and optionally, DHCP, to a small network. It can serve the names of local machines which are not in the global DNS.
Source: https://wiki.debian.org/dnsmasq
Basic DNS Setup
First things first, let’s install the package:
apt-get update apt-get install dnsmasq
If your goal was to set up a simple DNS server, you just succeeded. To test it, use your favorite DNS lookup tool pointed at localhost:
dig debian.org @localhost ; <<>> DiG 9.16.33-Debian <<>> debian.org @localhost ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23056 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;debian.org. IN A ;; ANSWER SECTION: debian.org. 300 IN A 149.20.4.15 debian.org. 300 IN A 130.89.148.77 debian.org. 300 IN A 128.31.0.62 ;; Query time: 44 msec ;; SERVER: ::1#53(::1) ;; WHEN: Thu Sep 29 16:26:24 CDT 2022 ;; MSG SIZE rcvd: 87
or
nslookup debian.org localhost Server: localhost Address: ::1#53 Non-authoritative answer: Name: debian.org Address: 128.31.0.62 Name: debian.org Address: 130.89.148.77 Name: debian.org Address: 149.20.4.15 Name: debian.org Address: 2001:67c:2564:a119::77 Name: debian.org Address: 2603:400a:ffff:bb8::801f:3e Name: debian.org Address: 2001:4f8:1:c::15
By default, DNS is configured to forward all requests to your system’s default DNS settings. In case you didn’t know, these are stored in the /etc/resolv.conf
To add names, simply add them to your /etc/hosts file.
nano /etc/hosts 192.168.0.155 ipgw.io
dig ipgw.io @localhost ; <<>> DiG 9.16.33-Debian <<>> ipgw.io @localhost ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53022 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;ipgw.io. IN A ;; ANSWER SECTION: ipgw.io. 0 IN A 192.168.0.155 ;; Query time: 0 msec ;; SERVER: ::1#53(::1) ;; WHEN: Thu Sep 29 16:31:02 CDT 2022 ;; MSG SIZE rcvd: 52
Choosing Your Interfaces
One you will probably want to do is tell dnsmasq which ethernet interface it can and cannot listen on, as we really don’t want it listening on the internet. Around line 69 of the /etc/dnsmasq.conf file, you will see:
#interface=
By default, DHCP is turned off.
Now change your dns on the IPv4 to your dnsmasq address server and your DNS server like Cloudflare.