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

Flush DNS Cache on Ubuntu

The full form of DNS is Domain Name System. It is used to translate domain names to IP addresses. It seems really simple,...
29/12/2020

DnsCrypt on Ubuntu – Encrypted DNS Traffic

DNSCrypt is an authentication protocol that facilitates the communication between DNS clients and DNS resolvers.  It’s...
28/12/2020

DNSMasq Ubuntu Tutorial

DNSmasq is a lightweight tool to provide both DNS service and DHCP service for small-scale networks. DNSmasq’s local DNS...
28/12/2020
Bài Viết

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

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?
27/05/2024