DNS forwarder on Qnap NAS

A few days ago I installed dnsmasq on my QNAP NAS. I use this DNS-forwarder to resolve my LAN-device’s names. Here is a little instruction:

First install ipkg, if you haven’t already (see http://wiki.qnap.com/wiki/Optware_IPKG).

Access your NAS with ssh as “admin”. If you haven’t already activated ssh, see http://wiki.qnap.com/wiki/How_to_SSH_into_your_QNAP_device.

Bring your ipkg installation up to date with this command: /opt/bin/ipkg update

Install the DNS-forwarder dnsmasq: /opt/bin/ipkg install dnsmasq

Edit with vi or your favorite text-editor the file /opt/etc/dnsmasq.conf and add the following line:

addn-hosts=/opt/etc/dnsmasq-hosts.conf

I added also a dedicated user for dnsmasq called “dnsmasq” and modified the following lines in dnsmasq.conf:

# If you want dnsmasq to change uid and gid to something other
# than the default, edit the following lines.
user=dnsmasq
group=everyone

Create and edit the file: /opt/etc/dnsmasq-hosts.conf

In this file, you define all your hosts with their names.

Example:

192.168.0.1     firewall.mydomain.int
192.168.0.2     switch1.mydomain.int
192.168.0.5     server1.mydomain.int

After modifying and saving this file, restart the dnsmasq service:

/opt/etc/init.d/S56dnsmasq restart

All done! Now you have to set the first DNS-Server address on your computer, to the IP-Address of your NAS.

The NAS will now answer all DNS-Queries. IP-Addresses which are not in the config file will be forwarded to the DNS-Servers configured on the NAS to resolve names outside your network.

9 thoughts on “DNS forwarder on Qnap NAS

  1. Thanks for sharing but I get:
    dnsmasq: cannot open or create lease file /var/lib/misc/dnsmasq.leases: No such file or directory

    After I create the file manually and restart:

    dnsmasq: unknown user or group: nobody

    Guess a few steps more are needed….

    (QNAP 469L)

    1. Hi zebrafilmtiaan,

      You’re right. I created a new user called “dnsmasq” and then changed the user and group in the dnsmasq.conf.
      I will update the tut asap.

  2. Hello – thanks! this solved a problem in my house whereby it would take my mac’s 20+ seconds to map a SMB network drive to my QNAP. I suspected it was a reverse resolution thing, and it was! DNS sorted it right out (now mapping in 2 seconds). Thanks!

    But one question… whats the best way to keep this ‘dnsmasq’ service persistent across reboots of the QNAP? I just rebooted and the dns server wasn’t listening anymore on udp53. (if it matters, im running firmware 4.0.7)

    cheers
    Keiran….

      1. thanks Stef! that worked a treat. Below is a paste in of my instructions that may end up helping someone else too:

        —————————————–
        MAKE THE SERVICE PERSISTENT ACROSS REBOOTS
        (from http://wiki.qnap.com/w/index.php?title=Running_Your_Own_Application_at_Startup&setlang=en)
        – create the shell script (and the location for it):
        [admin@knas ~]# mkdir /share/MD0_DATA/.qpkg/dnsmasq/
        [admin@knas ~]# touch /share/MD0_DATA/.qpkg/dnsmasq/dnsmasq.sh
        [admin@knas ~]# chmod +x /share/MD0_DATA/.qpkg/dnsmasq/dnsmasq.sh
        – edit the above newly created .sh script:
        #!/bin/sh
        #simple shell script that launches ‘dnsmasq’
        #FYI- this is launched from config in /etc/config/qpkg.conf
        /opt/sbin/dnsmasq
        -add a new section to the /etc/config/qpkg.conf file (‘Shell’ line is the important one, links to .sh script):
        [DNSMASQ]
        Name = dnsmasq
        Version = 0.1
        Author = kpharris
        Date = 2014-06-02
        Shell = /share/MD0_DATA/.qpkg/dnsmasq/dnsmasq.sh
        Install_Path = /share/MD0_DATA/.qpkg/dnsmasq
        QPKG_File = dnsmasq.qpkg
        Enable = TRUE
        -reboot the nas! (verify all good after by running a DNS query of course)
        —————————————–

        SIDE NOTE:
        your base instructions above need to be altered slightly. You say to put your local LAN hosts in this file “/opt/etc/dnsmasq-hosts.conf” which is fine, but at least in the version of dnsmasq i have (v2.62) it doesnt automatically link to that file (verified with the -d /debug switch when i launched /opt/sbin/dnsmasq from the command line – where it shows it only loaded 3 hosts, all of which came from the /etc/hosts file. To get it to act on that file, you need to edit the config file (/opt/etc/dnsmasq.conf) to set the below:
        # or if you want it to read another file, as well as /etc/hosts, use this.
        addn-hosts=/opt/etc/dnsmasq-hosts.conf
        After this is done, a reload of the service confirms now all my LAN hosts have also been loaded into the DNS server config. Hope this helps…
        cheers
        Keiran.

        1. Hi Keiran. Thanks for your suggestions. I wrote already, that you have to alter the config file. Have fun with your QNAP!

  3. Hi, this has been working great up until the latest firmware update. It looks as though the /opt/etc directory has been moved to /etc

    Can you recommend a fix.

    1. Hi Danny

      I don’t have the latest firmware, because I have an older TS409. So I can’t test it. Is the service not starting and you get an error? What is the error? Try start the service manually and see what’s happening. If you do a “man dnsmasq” you see, that you can give the Path with parameter -C to your dnsmasq.conf manually. In the dnsmasq.conf should still be the path to your hosts-file: addn-hosts=/opt/etc/dnsmasq-hosts.conf Is this file still there? If not, you have to change the path. Good luck 🙂

Leave a Reply