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

Using Consul DNS Interface

The DNS interface of Consul will help you to achieve service discovery without any personal-touch integration with the...
29/12/2020

Google DNS Tutorial

On 3 December 2009, Google announced its free alternative Domain Name System (DNS) service, Google Public DNS, which can...
28/12/2020

Install BIND 9 on Ubuntu and Configure It for Usage

The full form of BIND is Berkeley Internet Name Domain is a DNS server software. A DNS server resolves domain names such...
29/12/2020
Bài Viết

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

mua Proxy riêng ở đâu, và nó đem lại lợi ích gì cho người sử dụng
22/11/2022

Hướng dẫn sử dụng Proxy Helper Fakeip khi thuê proxy
21/11/2022

PROXY NUÔI TÀI KHOẢN FACEBOOK – KINH NGHIỆM FAKE IP – THUÊ PROXY GIÁ RẺ
14/11/2022

Mua Proxy Nuôi Zalo Giá Rẻ Tại Onet.com.vn
14/11/2022

BẢNG GIÁ MUA PROXY VIỆT NAM và PROXY US Onet.com.vn
14/11/2022