DNSMasq Ubuntu Tutorial


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 “ 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:


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 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:


And change the following line:

  #listen-address=    To    listen-address=  

Next open the following file in an editor:


Change the following line:

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

The prepend option is telling the computer to check locally ( 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:


The file should look like this:

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

Add the “nameserver” 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  nameserver  # /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...

Google DNS Tutorial

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

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...
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

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


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