DNSMasq Ubuntu Tutorial

28/12/2020
DNS

DNSmasq is a lightweight tool to provide both DNS service and DHCP service for small-scale networks.

DNSmasq’s local DNS cache helps response time during internet browsing. Because the domain names get stored locally on the first visit to a site, the browser doesn’t have to go to a domain name server (DNS). It improves the browsing speed.

The dynamic host configuration protocol (DHCP) service provides a computer the ability to assign network addresses to other computers in the network. DNSmasq’s DHCP service can provide both static and dynamic DHCP leases.

When DNSmasq receives a query, it looks for the entry in the local cache. If the answer is not found, then it forwards it to a real DNS server. It also monitors /etc/hosts. It gives you the ability to control traffic using /etc/hosts file. If you want to retract access to a site called www.restricthissite.com, you can enter “0.0.0.0 www.restrictthissite.com” into your /etc/hosts file. You can use this strategy to locally block unwanted sites.

The “dnsmasq” package can interfere with Network Manager which can provide DHCP service through the use of “dnsmasq-base” package. So, for Network Manager users, the recommendation is to install “dnsmasq-base” without “dnsmasq” package.


Installing DNSmasq

The “dnsmasq” is an Ubuntu standard package. So, you can install it using the following commands

$ sudo apt-get install dnsmasq

All the configuration information for DNSmasq resides in the following file:

/etc/dnsmasq.conf


Setting Up Local DNS Cache

The job of a DNS server is to translate human-readable domain names to IP addresses. When a browser requests a site like www.google.com, this domain name needs to be translated into an IP address like 172.217.5.196. DNS servers have the domain-name-to-IP-address tables. When you set up a local DNS cache, your browser requests don’t have to go to these remote DNS servers to get the IP addresses every time. The DNS cache stores the domain-name-to-IP-address entry. It can shave off hundreds of milliseconds from your browsers query time. The result is faster responses.

In order to activate DNS cache, open the following file in an editor like gedit or vim in administration mode:

/etc/dnsmasq.conf

And change the following line:

  #listen-address=    To    listen-address=127.0.0.1  

Next open the following file in an editor:

/etc/dhcp3/dhclient.conf

Change the following line:

  #prepend domain-name-servers 127.0.0.1;     To    prepend domain-name-servers 127.0.0.1;  

The prepend option is telling the computer to check locally (127.0.0.1) for the DNS server. So, the request for resolving domain names will first go to the dnsmasq.

Next, open the following file in an editor:

/etc/resolv.conf

The file should look like this:

  # Generated by dhcpcd from eth0.dhcp  # /etc/resolv.conf.head can replace this line  nameserver 192.168.65.1  # /etc/resolv.conf.tail can replace this line  

Add the “nameserver 127.0.0.1” to the resolve.conf file as the first active line:

  # Generated by dhcpcd from eth0.dhcp  # /etc/resolv.conf.head can replace this line  nameserver 127.0.0.1  nameserver 192.168.65.1  # /etc/resolv.conf.tail can replace this line  

Restart the DNSmasq using the following command:

$ sudo /etc/init.d/dnsmasq restart

Now you have a DNS cache set up on your computer. The domain name and IP address of any new site

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to use Nslookup in Debian

Nslookup or name server lookup is a tool used by network administrators to find the hostname, IP address or other DNS records...
29/12/2020

How to Configure dnsmasq on Ubuntu Server 18.04 LTS

dnsmasq is a very lightweight local DNS server. dnsmasq can also be configured as a DNS cache server and DHCP server. dnsmasq...
29/12/2020

OpenDNS vs GoogleDNS

OpenDNS vs Google DNS Services like OpenDNS and GoogleDNS can speed up your browsing experience while keeping you secure...
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua proxy v4 chạy socks5 để chơi game an toàn, tốc độ cao ở đâu?
18/05/2024

Thuê mua proxy Telegram trọn gói, tốc độ cao, giá siêu hời
18/05/2024

Thuê mua proxy Viettel ở đâu uy tín, chất lượng và giá tốt? 
14/05/2024

Dịch vụ thuê mua proxy US UK uy tín, chất lượng số #1
13/05/2024

Thuê mua proxy Việt Nam: Báo giá & các thông tin MỚI NHẤT
13/05/2024