Posted by Peter

Dnsmasq is a simple server providing the DNS and DHCP services for a local area network (LAN) and as its creator say - it will be working very well on home networks and small business environments, up to roughly 1000 workstations. More information about it in the author’s website: http://www.thekelleys.org.uk/dnsmasq/doc.html

  1. But why?

    Good question. As a rule, if you already have a local network at home, then your are probably used to moving around it either by using computer’s IP addresses using the local environment of Windows and the names of workstations in the work group. The latter is quite comfortable, but will work only in networks with Windows operating systems, maybe also with different Unix’s or Linux’s, but this in turn requires the configuration of the Samba server, which is beyond the scope of this text. Now let’s think how beautiful it would have been if, instead of IP addresses, each computer was recognized by its unique name, just like web pages. This would also include network printers, routers and other devices. This is what dnsmasq can do for us. It will allow us to find any of network devices receiving IP addresses automatically via DHCP or statically added to server configuration.Instead of seeking to enter the network share:

    1
    
      \\192.168.0.4\share
    

    Type:

    1
    
      \\our.server.domain\share
    

    Easier to remember, right? Now, if the address of a machine identified as “our.server” changes, we do not even need to know present IP address, because dnsmasq will guide us to him flawlessly.

    Now that we know what we might use it for… let’s get started! :)

  2. Installation

    Installation depends on the environment in which we work, I will focus on Linux, and specifically on the two most popular distributions: Fedora (as well as Red Hat, Centos) and Debian (Ubuntu and other Debian like). For installation you will need root privileges. You can either log on as root, or add before each following command: sudo

    For example: sudo yum update

  • Fedora

    use command:

    1
    2
    
        yum update
        yum install dnsmasq
    
  • Debian use command:

    1
    2
    
      aptitude update && aptitude safe-upgrade
      aptitude install dnsmasq
    
  1. The configuration file is called dnsmasq.conf and is located in /etc directory. In addition, dnsmasq uses /etc /hosts as a source of information about the hosts with statically assigned IP addresses, that is those not assigned by the DHCP and /etc /resolv.conf - thus receives information about DNS servers, which it will use. It is very well documented in the configuration file comments, so I’ll skip the detailed instructions, but I will focus on several options that are needed to start with.
1
2
3
4
5
6
7
8
*   **domain-needed** - means that dnsmasq will forward only dns queries that have a domain name in the address
*   **bogus-priv** - means that dnsmasq will forward only dns queries that are in routable IP ranges
*   **interface =** _{eth0, eth1, ...}_ - if you have more than one network interface, you can make dnsmasq listen only on one of them
*   **except-interface** = _{eth0, eth1, ...}_ as well as earlier but dnsmasq should listen on all interfaces except the specified
*   **expand-hosts** - tells dnsmasq to add your domain to the host's name and works in conjunction with variable **domain**
*   **domain** - your domain name
*   **dhcp-range = 192.168.0.30,192.168.0.40,24 h** - used to activate the DHCP server and setting the scope of the assigned addresses to 192.168.0.30-40 and time of lease (rent) for 24 hours. If we have two subnets (VLANs or two network cards), we can define the variables twice, provided that dnsmasq is configured to listen on both interfaces
*   **dhcp-host = 00:11:22:33:44:55,192.168.0.36** - definition of the host, which on each connection should have the same IP address. Host authentication is done using the hardware address of network adapter MAC. In our case, the host with MAC address 00:11:22:33:44:55 will always receive the address of 192.168.0.36
  1. Setting these values ​​will allow us to start using dnsmasq on our network and enjoy host names instead of IP addresses.

  2. Additional Information

  • entries in /etc/hosts look as follows: IP_address hostname

    For example: 192.168.0.21 Server

  • entries in /etc/resolv.conf look like:

    nameserver IP_address For example: nameserver 194.204.152.34

  • in case of dnsdomainname errors while restarting dnsmasq service you should check the file /etc/hosts.

    The entry for 127.0.0.1 localhost should contain additionally yourserver.yourdomain entry, for example: 127.0.0.1 localhost server.domain.com After that you may need the restart of the system or network services.

  • in the case of Fedora, and other Red Hat like: in /etc/sysconfig/network should be an entry:

    HOSTNAME = yourserever.yourdomain.com

  • if hosts with IP addresses statically defined could also use dnsmasq DNS server, you must replace their existing DNS servers to the IP address of our server that is running dnsmasq.