CINXE.COM

dnsmasq - Debian Wiki

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="shortcut icon" href="/htdocs/favicon.ico"> <script type="text/javascript" src="/htdocs/bugstatus.js"></script> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <meta name="robots" content="noindex,nofollow"> <title>dnsmasq - Debian Wiki</title> <script type="text/javascript" src="/htdocs/common/js/common.js"></script> <script type="text/javascript"> <!-- var search_hint = "Search"; //--> </script> <link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="/htdocs/debwiki/css/common.css"> <link rel="stylesheet" type="text/css" charset="utf-8" media="screen" href="/htdocs/debwiki/css/screen.css"> <link rel="stylesheet" type="text/css" charset="utf-8" media="print" href="/htdocs/debwiki/css/print.css"> <link rel="stylesheet" type="text/css" charset="utf-8" media="projection" href="/htdocs/debwiki/css/projection.css"> <link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="/htdocs/debian-wiki-1.0.css"> <!-- css only for MS IE6/IE7 browsers --> <!--[if lt IE 8]> <link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="/htdocs/debwiki/css/msie.css"> <![endif]--> <link rel="alternate" title="Debian Wiki: dnsmasq" href="/dnsmasq?diffs=1&amp;show_att=1&amp;action=rss_rc&amp;unique=0&amp;page=dnsmasq&amp;ddiffs=1" type="application/rss+xml"> <link rel="Start" href="/FrontPage"> <link rel="Alternate" title="Wiki Markup" href="/dnsmasq?action=raw"> <link rel="Alternate" media="print" title="Print View" href="/dnsmasq?action=print"> <link rel="Search" href="/FindPage"> <link rel="Index" href="/TitleIndex"> <link rel="Glossary" href="/WordIndex"> <link rel="Help" href="/HelpOnFormatting"> </head> <body lang="en" dir="ltr"> <div id="logo"><a href="https://www.debian.org" title="Debian Homepage"><img src="https://www.debian.org/Pics/openlogo-50.png" alt="Debian" width="50" height="61"></a></div> <div id="header"> <div id="wikisection"> <p class="section"><a href="/FrontPage" title="Debian Wiki Homepage">Wiki</a></p> <div id="username"><a href="/dnsmasq?action=login" id="login" rel="nofollow">Login</a></div> </div> <div id="navbar"> <ul id="navibar"> <li class="wikilink"><a href="/FrontPage">FrontPage</a></li><li class="wikilink"><a href="/RecentChanges">RecentChanges</a></li><li class="wikilink"><a href="/FindPage">FindPage</a></li><li class="wikilink"><a href="/HelpContents">HelpContents</a></li><li class="current"><a href="/dnsmasq">dnsmasq</a></li> </ul> </div> <form id="searchform" method="get" action="/dnsmasq"> <div> <input type="hidden" name="action" value="fullsearch"> <input type="hidden" name="context" value="180"> <label for="searchinput">Search:</label> <input id="searchinput" type="text" name="value" value="" size="20" onfocus="searchFocus(this)" onblur="searchBlur(this)" onkeyup="searchChange(this)" onchange="searchChange(this)" alt="Search"> <input id="titlesearch" name="titlesearch" type="submit" value="Titles" alt="Search Titles"> <input id="fullsearch" name="fullsearch" type="submit" value="Text" alt="Search Full Text"> </div> </form> <script type="text/javascript"> <!--// Initialize search form var f = document.getElementById('searchform'); f.getElementsByTagName('label')[0].style.display = 'none'; var e = document.getElementById('searchinput'); searchChange(e); searchBlur(e); //--> </script> <div id="logo"><a href="https://www.debian.org" title="Debian Homepage"><img src="https://www.debian.org/Pics/openlogo-50.png" alt="Debian" width="50" height="61"></a></div> <div id="breadcrumbs"><a href="/FrontPage" title="Debian Wiki Homepage">Wiki</a><span class="sep">/</span> </div> <ul class="editbar"><li><a href="/dnsmasq?action=login" id="login-1" rel="nofollow">Login</a></li><li class="toggleCommentsButton" style="display:none;"><a href="#" class="nbcomment" onClick="toggleComments();return false;">Comments</a></li><li><a class="nbinfo" href="/dnsmasq?action=info" rel="nofollow">Info</a></li><li><a class="nbattachments" href="/dnsmasq?action=AttachFile" rel="nofollow">Attachments</a></li><li> <form class="actionsmenu" method="GET" action="/dnsmasq"> <div> <label>More Actions:</label> <select name="action" onchange="if ((this.selectedIndex != 0) && (this.options[this.selectedIndex].disabled == false)) { this.form.submit(); } this.selectedIndex = 0;"> <option value="raw">Raw Text</option> <option value="print">Print View</option> <option value="RenderAsDocbook">Render as Docbook</option> <option value="show" disabled class="disabled">Delete Cache</option> <option value="show" disabled class="disabled">------------------------</option> <option value="SpellCheck">Check Spelling</option> <option value="LikePages">Like Pages</option> <option value="LocalSiteMap">Local Site Map</option> <option value="show" disabled class="disabled">------------------------</option> <option value="RenamePage" disabled class="disabled">Rename Page</option> <option value="DeletePage" disabled class="disabled">Delete Page</option> <option value="show" disabled class="disabled">------------------------</option> <option value="show" disabled class="disabled">Subscribe User</option> <option value="show" disabled class="disabled">------------------------</option> <option value="show" disabled class="disabled">Remove Spam</option> <option value="show" disabled class="disabled">Revert to this revision</option> <option value="PackagePages">Package Pages</option> <option value="show" disabled class="disabled">------------------------</option> <option value="Load">Load</option> <option value="Save">Save</option> <option value="SlideShow">SlideShow</option> </select> <input type="submit" value="Do"> </div> <script type="text/javascript"> <!--// Init menu actionsMenuInit('More Actions:'); //--> </script> </form> </li></ul> <h1 id="locationline"> <ul id="pagelocation"> <li><a href="/dnsmasq">dnsmasq</a></li> </ul> </h1> </div> <div id="page" lang="en" dir="ltr"> <div dir="ltr" id="content" lang="en"><span class="anchor" id="top"></span> <span class="anchor" id="line-1"></span><span class="anchor" id="line-2"></span><span class="anchor" id="line-3"></span><p class="line867"><small><a href="/DebianWiki/EditorGuide#translation">Translation(s)</a>: none</small> <span class="anchor" id="line-4"></span><hr /><p class="line874"> <span class="anchor" id="line-5"></span><span class="anchor" id="line-6"></span><p class="line867"><div class="table-of-contents"><p class="table-of-contents-heading">Contents<ol><li> <a href="#Basic_DNS_Setup">Basic DNS Setup</a></li><li> <a href="#Choosing_Your_Interfaces">Choosing Your Interfaces</a></li><li> <a href="#Basic_DHCP_Setup">Basic DHCP Setup</a></li><li> <a href="#Local_Caching">Local Caching</a></li><li> <a href="#Local_Caching_using_NetworkManager">Local Caching using NetworkManager</a></li><li> <a href="#dnsmasq_with_dnscrypt-proxy">dnsmasq with dnscrypt-proxy</a></li><li> <a href="#See_Also">See Also</a></li></ol></li></ol></div><p class="line874"> <span class="anchor" id="line-7"></span><span class="anchor" id="line-8"></span><ul><li style="list-style-type:none"><p class="line862">Dnsmasq is a lightweight, easy to configure, DNS forwarder and DHCP server. It is designed to provide DNS and optionally, DHCP, to a small network. It can serve the names of local machines which are not in the global DNS. The DHCP server integrates with the DNS server and allows machines with DHCP-allocated addresses to appear in the DNS with names configured either in each host or in a central configuration file. Dnsmasq supports static and dynamic DHCP leases and BOOTP/TFTP for network booting of diskless machines <small>(source: from the <a class="interwiki" href="https://packages.debian.org/dnsmasq" title="DebianPkg">package description</a>)</small>. <span class="anchor" id="line-9"></span><span class="anchor" id="line-10"></span></li></ul><p class="line867"> <h2 id="Basic_DNS_Setup">Basic DNS Setup</h2> <span class="anchor" id="line-11"></span><p class="line862">First things first, let's install the package: <span class="anchor" id="line-12"></span><span class="anchor" id="line-13"></span><span class="anchor" id="line-14"></span><pre><span class="anchor" id="line-1-1"></span>apt-get update <span class="anchor" id="line-2-1"></span>apt-get install dnsmasq</pre><span class="anchor" id="line-15"></span><span class="anchor" id="line-16"></span><p class="line862">If your goal was to set up a simple DNS server, you just succeeded. To test it, use your favorite DNS lookup tool pointed at localhost: <span class="anchor" id="line-17"></span><span class="anchor" id="line-18"></span><pre><span class="anchor" id="line-1-2"></span>dig debian.org @localhost</pre><p class="line862"> <em>or</em> <span class="anchor" id="line-19"></span><span class="anchor" id="line-20"></span><pre><span class="anchor" id="line-1-3"></span>nslookup debian.org localhost</pre><span class="anchor" id="line-21"></span><span class="anchor" id="line-22"></span><p class="line862">By default, DNS is configured to forward all requests to your system's default DNS settings. In case you didn't know, these are stored in the <tt>/etc/resolv.conf</tt> file. See <a class="http" href="http://www.debian.org/doc/manuals/debian-reference/ch05">Debian Reference</a> or the <a class="interwiki" href="https://manpages.debian.org/man/5/resolv.conf" title="DebianMan">resolv.conf(5)</a> man page for more details. <span class="anchor" id="line-23"></span><span class="anchor" id="line-24"></span><p class="line862">Now, if you want to add some names for your DNS server to resolve for your clients, simply add them to your <tt>/etc/hosts</tt> file. <span class="anchor" id="line-25"></span><span class="anchor" id="line-26"></span><p class="line867"> <h2 id="Choosing_Your_Interfaces">Choosing Your Interfaces</h2> <span class="anchor" id="line-27"></span><p class="line862">One you will probably want to do is tell dnsmasq which ethernet interface it can and cannot listen on, as we really don't want it listening on the internet. Around line 69 of the <tt>/etc/dnsmasq.conf</tt> file, you will see: <span class="anchor" id="line-28"></span><span class="anchor" id="line-29"></span><pre><span class="anchor" id="line-1-4"></span>#interface=</pre><span class="anchor" id="line-30"></span><span class="anchor" id="line-31"></span><p class="line862">Uncomment the line and specify which ethernet interface(s) you want it server IPs to. For example, if I want it to listen on eth1 (my DMZ) and eth2 (my local network), then it should look like: <span class="anchor" id="line-32"></span><span class="anchor" id="line-33"></span><span class="anchor" id="line-34"></span><pre><span class="anchor" id="line-1-5"></span>interface=eth1 <span class="anchor" id="line-2-2"></span>interface=eth2</pre><span class="anchor" id="line-35"></span><span class="anchor" id="line-36"></span><p class="line874">If I didn't edit this line, it would also listen on eth0, my internet connection. I personally wouldn't recommend this, as it gives those evil guys a few doors to try to break into. <span class="anchor" id="line-37"></span><span class="anchor" id="line-38"></span><p class="line867"> <h2 id="Basic_DHCP_Setup">Basic DHCP Setup</h2> <span class="anchor" id="line-39"></span><p class="line874">By default, DHCP is turned off. This is a good thing, as you could bring down whatever network you are connected to if you are not careful. <span class="anchor" id="line-40"></span><span class="anchor" id="line-41"></span><p class="line862">To enable it, there is at least one line will need to edit in the <tt>/etc/dnsmasq.conf</tt> file. Around line 143, you will see: <span class="anchor" id="line-42"></span><span class="anchor" id="line-43"></span><pre><span class="anchor" id="line-1-6"></span>#dhcp-range=192.168.0.50,192.168.0.150,12h</pre><span class="anchor" id="line-44"></span><span class="anchor" id="line-45"></span><p class="line874">To enable the DHCP server, you will need to give it a range of IP addresses to hand out. In the example above, this server would hand out 101 address starting at 192.168.0.50 and ending at 192.168.0.150. The last number is how long the DHCP leases are good for. In this example, they would be good for twelve hours. <span class="anchor" id="line-46"></span><span class="anchor" id="line-47"></span><p class="line862">Since I have two different networks that need DHCP, I'm going to change that line to: <span class="anchor" id="line-48"></span><span class="anchor" id="line-49"></span><span class="anchor" id="line-50"></span><pre><span class="anchor" id="line-1-7"></span>dhcp-range=eth1,192.168.100.100,192.168.100.199,4h <span class="anchor" id="line-2-3"></span>dhcp-range=eth2,192.168.200.100,192.168.200.199,4h</pre><span class="anchor" id="line-51"></span><span class="anchor" id="line-52"></span><p class="line862">Notice the &quot;eth1&quot; and &quot;eth2&quot; labels in the lines above? They aren't necessary, but definitely help once you start playing with more advanced configurations. It also helps me remember which range is which. Now restart your dnsmasq server, connect up a few clients, and see if they autoconfigure themselves: <span class="anchor" id="line-53"></span><span class="anchor" id="line-54"></span><pre><span class="anchor" id="line-1-8"></span>/etc/init.d/dnsmasq restart</pre><span class="anchor" id="line-55"></span><span class="anchor" id="line-56"></span><p class="line867"> <h2 id="Local_Caching">Local Caching</h2> <span class="anchor" id="line-57"></span><p class="line862">Using dnsmasq to cache DNS queries for the local machine is a bit tricky (unless you're using <a href="/NetworkManager">NetworkManager</a>, see below), since all DNS queries from the local machine need to go to dnsmasq, while at the same time, dnsmasq must be configured to forward all those queries to upstream DNS servers. <span class="anchor" id="line-58"></span><span class="anchor" id="line-59"></span><ul><li style="list-style-type:none"><p class="line891"><img alt="&lt;!&gt;" height="16" src="/htdocs/debwiki/img/attention.png" title="&lt;!&gt;" width="16" /> Do not use this configuration if you use different network (e.g If you use a laptop!) <span class="anchor" id="line-60"></span><span class="anchor" id="line-61"></span></li></ul><p class="line862">The <a class="interwiki" href="https://manpages.debian.org/man/8/dnsmasq" title="DebianMan">dnsmasq(8)</a> man page suggests the following: <span class="anchor" id="line-62"></span><span class="anchor" id="line-63"></span><ul><li style="list-style-type:none">In order to configure dnsmasq to act as cache for the host on which it is running, put &quot;nameserver 127.0.0.1&quot; in /etc/resolv.conf to force local processes to send queries to dnsmasq. Then either specify the upstream servers directly to dnsmasq using --server options or put their addresses real in another file, say /etc/resolv.dnsmasq and run dnsmasq with the -r /etc/resolv.dnsmasq option. This second technique allows for dynamic update of the server addresses by PPP or DHCP. <span class="anchor" id="line-64"></span><span class="anchor" id="line-65"></span></li></ul><p class="line874">There is, however, a simpler method; simply ensure that the machine's list of nameservers contains the line <span class="anchor" id="line-66"></span><span class="anchor" id="line-67"></span><p class="line867"><tt>nameserver&nbsp;127.0.0.1</tt> <span class="anchor" id="line-68"></span><span class="anchor" id="line-69"></span><p class="line862">as the <em>first</em> line, followed by the upstream nameservers. dnsmasq is smart enough to ignore this line and forward all queries appropriately, while all other applications will send all their queries to dnsmasq. <span class="anchor" id="line-70"></span><span class="anchor" id="line-71"></span><p class="line862">Exactly how to do this depends on the method(s) of network configuration in use. If you're manually hardcoding the nameservers (either in <tt>/etc/resolv.conf</tt> or elsewhere, such as a stanza in <tt>/etc/network/interfaces</tt> or in the Wicd GUI), then just add a reference to <tt>127.0.0.1</tt> as the first entry in the list. If you're using DHCP, then instruct your client to prepend <tt>127.0.0.1</tt> to the DHCP servers it receives. E.g., with dhclient, include the line <span class="anchor" id="line-72"></span><span class="anchor" id="line-73"></span><p class="line867"><span class="anchor" id="line-74"></span><span class="anchor" id="line-75"></span><pre><span class="anchor" id="line-1-9"></span>prepend domain-name-servers 127.0.0.1;</pre><span class="anchor" id="line-76"></span><span class="anchor" id="line-77"></span><p class="line862">in the dhclient configuration file (<tt>/etc/dhcp3/dhclient.conf</tt>). [On my Sid system, the default configuration file shipped with the package contains that line, but commented out.] <span class="anchor" id="line-78"></span><span class="anchor" id="line-79"></span><p class="line874">Note that if you plan to use dnsmasq for the local system only, you should lock it down by adding the line <span class="anchor" id="line-80"></span><span class="anchor" id="line-81"></span><p class="line867"><span class="anchor" id="line-82"></span><span class="anchor" id="line-83"></span><pre><span class="anchor" id="line-1-10"></span>listen-address=127.0.0.1</pre><span class="anchor" id="line-84"></span><span class="anchor" id="line-85"></span><p class="line862">to the dnsmasq configuration file (<tt>/etc/dnsmasq.conf</tt>). <span class="anchor" id="line-86"></span><span class="anchor" id="line-87"></span><p class="line867"><span class="anchor" id="line-88"></span><p class="line867"><span class="anchor" id="line-89"></span><span class="anchor" id="line-90"></span><p class="line867"> <h2 id="Local_Caching_using_NetworkManager">Local Caching using NetworkManager</h2> <span class="anchor" id="line-91"></span><span class="anchor" id="line-92"></span><p class="line862">Set this in <tt>/etc/NetworkManager/NetworkManager.conf</tt>: <span class="anchor" id="line-93"></span><span class="anchor" id="line-94"></span><span class="anchor" id="line-95"></span><span class="anchor" id="line-96"></span><pre><span class="anchor" id="line-1-11"></span>[main] <span class="anchor" id="line-2-4"></span>dns=dnsmasq</pre><span class="anchor" id="line-97"></span><p class="line874">and restart network-manager service. <span class="anchor" id="line-98"></span><span class="anchor" id="line-99"></span><p class="line867"> <h2 id="dnsmasq_with_dnscrypt-proxy">dnsmasq with dnscrypt-proxy</h2> <span class="anchor" id="line-100"></span><span class="anchor" id="line-101"></span><p class="line874">dnsmasq combined with dnscrypt-proxy provide caching, encryption and server-side authentication. Useful to protect a laptop from potentially hostile networks. <span class="anchor" id="line-102"></span><span class="anchor" id="line-103"></span><p class="line867"><span class="anchor" id="line-104"></span><span class="anchor" id="line-105"></span><span class="anchor" id="line-106"></span><span class="anchor" id="line-107"></span><span class="anchor" id="line-108"></span><span class="anchor" id="line-109"></span><span class="anchor" id="line-110"></span><span class="anchor" id="line-111"></span><span class="anchor" id="line-112"></span><span class="anchor" id="line-113"></span><span class="anchor" id="line-114"></span><span class="anchor" id="line-115"></span><span class="anchor" id="line-116"></span><span class="anchor" id="line-117"></span><span class="anchor" id="line-118"></span><span class="anchor" id="line-119"></span><span class="anchor" id="line-120"></span><span class="anchor" id="line-121"></span><span class="anchor" id="line-122"></span><span class="anchor" id="line-123"></span><span class="anchor" id="line-124"></span><span class="anchor" id="line-125"></span><pre><span class="anchor" id="line-1-12"></span>apt-get install dnsmasq dnscrypt-proxy <span class="anchor" id="line-2-5"></span> <span class="anchor" id="line-3-1"></span>## Configure /etc/resolv.conf to use dnsmasq <span class="anchor" id="line-4-1"></span>nameserver 127.0.0.1 <span class="anchor" id="line-5-1"></span> <span class="anchor" id="line-6-1"></span>## Configure /etc/dnsmasq.conf <span class="anchor" id="line-7-1"></span># ignore resolv.conf <span class="anchor" id="line-8-1"></span>no-resolv <span class="anchor" id="line-9-1"></span># Listen only on localhost <span class="anchor" id="line-10-1"></span>listen-address=127.0.0.1 <span class="anchor" id="line-11-1"></span># dnscrypt is on port 40 <span class="anchor" id="line-12-1"></span>server=127.0.0.1#40 <span class="anchor" id="line-13-1"></span> <span class="anchor" id="line-14-1"></span>## Configure /etc/systemd/system/sockets.target.wants/dnscrypt-proxy.socket with the following 5 lines if you are using systemd <span class="anchor" id="line-15-1"></span>[Socket] <span class="anchor" id="line-16-1"></span>ListenStream= <span class="anchor" id="line-17-1"></span>ListenDatagram= <span class="anchor" id="line-18-1"></span>ListenStream=127.0.0.1:40 <span class="anchor" id="line-19-1"></span>ListenDatagram=127.0.0.1:40 <span class="anchor" id="line-20-1"></span> <span class="anchor" id="line-21-1"></span>## restart both daemons</pre><span class="anchor" id="line-126"></span><span class="anchor" id="line-127"></span><span class="anchor" id="line-128"></span><p class="line867"> <h2 id="See_Also">See Also</h2> <span class="anchor" id="line-129"></span><ul><li><p class="line891"><a class="http" href="http://www.debian.org/doc/manuals/debian-reference/ch05">http://www.debian.org/doc/manuals/debian-reference/ch05</a> - Debian Reference: Chapter 5. Network setup <span class="anchor" id="line-130"></span></li><li><p class="line891"><a class="http" href="http://www.thekelleys.org.uk/dnsmasq/doc.html">http://www.thekelleys.org.uk/dnsmasq/doc.html</a> - dnsmasq home page <span class="anchor" id="line-131"></span><span class="anchor" id="line-132"></span></li></ul><p class="line867"><hr /><p class="line874"> <span class="anchor" id="line-133"></span><a href="/CategoryNetwork"><strong class="highlight">CategoryNetwork</strong></a> | <a href="/CategorySoftware">CategorySoftware</a> | <a href="/CategorySystemAdministration">CategorySystemAdministration</a> <span class="anchor" id="line-134"></span><span class="anchor" id="bottom"></span></div><div id="pagebottom"></div> </div> <div id="footer"> <p id="pageinfo" class="info" lang="en" dir="ltr">dnsmasq (<a class="nbinfo" href="/dnsmasq?action=info" rel="nofollow">last modified 2024-04-19 17:16:07</a>)</p> <ul id="credits"> <li>Debian <a href="https://www.debian.org/legal/privacy">privacy policy</a>, Wiki <a href="/Teams/DebianWiki">team</a>, <a href="https://bugs.debian.org/wiki.debian.org">bugs</a> and <a href="https://salsa.debian.org/debian/wiki.debian.org">config</a>.</li><li>Powered by <a href="https://moinmo.in/" title="This site uses the MoinMoin Wiki software.">MoinMoin</a> and <a href="https://moinmo.in/Python" title="MoinMoin is written in Python.">Python</a>, with hosting provided by <a href="https://www.man-da.de/">Metropolitan Area Network Darmstadt</a>.</li> </ul> </div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10