id: f1ec36a8d77f4484833fdc4f831d2ca1
parent_id: 
item_type: 1
item_id: 61a492386fc040539b45e138599ffc27
item_updated_time: 1764345498548
title_diff: "[{\"diffs\":[[1,\"DNS and DHCP with Dnsmasq - Linux.com\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":37}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>DNS and DHCP with Dnsmasq - Linux.com</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"28004\\\"></a>\\\r\\\n<h1>DNS and DHCP with Dnsmasq - Linux.com</h1>\\\r\\\n\\\r\\\n<div><span>\\\n  <div style=\\\"--en-clipped-content:article; --en-clipped-source-url:https://www.linux.com/topic/networking/dns-and-dhcp-dnsmasq/; --en-clipped-source-title:DNS and DHCP with Dnsmasq - Linux.com;\\\">\\\n<div><br/></div><div style=\\\"min-height: 3005px; font-size: 16px; display: block; min-width: 100%; position: relative;\\\"> <div style=\\\"box-sizing:border-box;font-family:sans-serif;text-size-adjust:100%;\\\"><div style=\\\"box-sizing:border-box;font-family:Verdana, BlinkMacSystemFont, -apple-system, &quot;Segoe UI&quot;, Roboto, Oxygen, Ubuntu, Cantarell, &quot;Open Sans&quot;, &quot;Helvetica Neue&quot;, sans-serif;font-size:14px;line-height:21px;\\\"><div style=\\\"box-sizing:border-box;overflow:hidden;\\\"><div style=\\\"box-sizing:border-box;background-color:rgb(255, 255, 255);\\\"><div style=\\\"box-sizing:border-box;\\\"><div style=\\\"box-sizing:border-box;\\\"><div style=\\\"box-sizing:border-box;\\\"><div style=\\\"box-sizing:border-box;\\\"><div style=\\\"box-sizing:border-box;background-color:rgb(255, 255, 255);\\\"><div style=\\\"box-sizing:border-box;font-size:15px;line-height:1.74;color:rgb(34, 34, 34);\\\">\\\n            <p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\">Last week, we learned a batch of <a href=\\\"https://www.linux.com/learn/intro-to-linux/2018/2/advanced-dnsmasq-tips-and-tricks\\\" style=\\\"box-sizing:border-box;text-decoration:none;background-color:transparent;color:rgb(255, 108, 14);\\\">tips and tricks for Dnsmasq</a>. Today, we’re going more in-depth into configuring DNS and DHCP, including entering DHCP hostnames automatically into DNS, and assigning static IP addresses from DHCP.</p>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><font style=\\\"box-sizing:border-box;\\\">You will edit three configuration files on your Dnsmasq server: , , and . Just like the olden days when we had nice clean configuration files for everything, instead of messes of scripts and nested configuration files.</font><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/dnsmasq.conf</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/resolv.conf</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/hosts</code></p>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\">Use Dnsmasq’s built-in syntax checker to check for configuration file errors, and run Dnsmasq from the command-line rather than as daemon so you can quickly test configuration changes and log the results. (See last week’s tutorial to learn more about this.)</p>\\\n<h3 style=\\\"box-sizing:border-box;font-family:Roboto, sans-serif;color:rgb(17, 17, 17);font-weight:400;margin:6px 0px;font-size:22px;line-height:30px;margin-top:27px;margin-bottom:17px;\\\">Taming Network Manager and resolv.conf</h3>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><font style=\\\"box-sizing:border-box;\\\">Disable Network Manager on your Dnsmasq server, and give its network interfaces static configurations. You also need control of , which in these modern times is usually controlled by other processes, such as Network Manager. In these cases  is a symbolic link to another file such as  or . To get around this delete the symlink and then re-create the  file. Now your changes will not be overwritten.</font><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/resolv.conf</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/resolv.conf</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/run/resolvconf/resolv.conf</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/var/run/NetworkManager/resolv.conf</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/resolv.conf</code></p>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><font style=\\\"box-sizing:border-box;\\\">There are many ways to use Dnsmasq and  together. My preference is to enter only 127.0.0.1 in , and enter all upstream nameservers in . You don’t need to touch any client configurations because Dnsmasq will provide all network information to them via DHCP.</font><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/resolv.conf</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/resolv.conf</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/dnsmasq.conf</code></p>\\\n<h3 style=\\\"box-sizing:border-box;font-family:Roboto, sans-serif;color:rgb(17, 17, 17);font-weight:400;margin:6px 0px;font-size:22px;line-height:30px;margin-top:27px;margin-bottom:17px;\\\">Local DHCP</h3>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\">This example configuration includes some typical global options, and then defines a single DHCP address range. Replace the italicized values with your own values.</p>\\\n<pre style=\\\"box-sizing:border-box;background-color:rgb(241, 241, 241);padding:4px 10px;border:none;border-radius:0px;margin-top:24px;overflow:auto;font-family:monospace, monospace;font-size:1em;\\\"># global options\\\ndomain-needed\\\nbogus-priv\\\nno-resolv\\\nfilterwin2k\\\nexpand-hosts\\\ndomain=<i style=\\\"box-sizing:border-box;\\\">mydomain.net</i>\\\nlocal=<i style=\\\"box-sizing:border-box;\\\">/mydomain.net/</i>\\\nlisten-address=127.0.0.1\\\nlisten-address=<i style=\\\"box-sizing:border-box;\\\">192.168.10.4</i>\\\n\\\n# DHCP range\\\ndhcp-range=<i style=\\\"box-sizing:border-box;\\\">192.168.10.10,192.168.10.50,12h</i>\\\ndhcp-lease-max=<i style=\\\"box-sizing:border-box;\\\">25</i>\\\n</pre>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><strong style=\\\"box-sizing:border-box;font-weight:bold;\\\">dhcp-range=192.168.10.10,192.168.10.50,12h</strong> defines a range of 40 available address leases, with a lease time of 12 hours. This range must not include your Dnsmasq server. You may define the lease time in seconds, minutes, or hours. The default is one hour and the minimum possible is two minutes. If you want infinite lease times then don’t specify a lease time.</p>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><strong style=\\\"box-sizing:border-box;font-weight:bold;\\\">dhcp-lease-max=25</strong> defines how many leases can be active at one time. You can have large address pool available and then limit the number of active leases to prevent denial of service problems from hosts going nuts and demanding a lot of DHCP leases.</p>\\\n<h3 style=\\\"box-sizing:border-box;font-family:Roboto, sans-serif;color:rgb(17, 17, 17);font-weight:400;margin:6px 0px;font-size:22px;line-height:30px;margin-top:27px;margin-bottom:17px;\\\">DHCP Zones and Options</h3>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><font style=\\\"box-sizing:border-box;\\\">You can define DHCP zones for different subnets, like this example that has an  and a  zone, and then give each zone different options. This example shows how to define the zones:</font><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">eth</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">wifi</code></p>\\\n<pre style=\\\"box-sizing:border-box;background-color:rgb(241, 241, 241);padding:4px 10px;border:none;border-radius:0px;margin-top:24px;overflow:auto;font-family:monospace, monospace;font-size:1em;\\\">dhcp-range=eth,192.168.10.10,192.168.10.50,12h\\\ndhcp-range=wifi,192.168.20.10,192.168.20.50,24h\\\n</pre>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\">The default route advertised to all clients is the address of your Dnsmasq server. You can configure DHCP to assign each zone a different default route:</p>\\\n<pre style=\\\"box-sizing:border-box;background-color:rgb(241, 241, 241);padding:4px 10px;border:none;border-radius:0px;margin-top:24px;overflow:auto;font-family:monospace, monospace;font-size:1em;\\\">dhcp-option=eth,3,192.168.10.0\\\ndhcp-option=wifi,3,192.168.20.0\\\n</pre>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><font style=\\\"box-sizing:border-box;\\\">How do you know that 3 is the default route option? Run  to see all the IPv4 options.  lists the IPv6 options. (See  for more information on options.) You may also use the option names instead of the numbers, like this example for your NTP server:</font><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">dnsmasq --help dhcp</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">dnsmasq --help dhcp6</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">man 5 dhcp-options</code></p>\\\n<pre style=\\\"box-sizing:border-box;background-color:rgb(241, 241, 241);padding:4px 10px;border:none;border-radius:0px;margin-top:24px;overflow:auto;font-family:monospace, monospace;font-size:1em;\\\">dhcp-option=eth,option:ntp-server,192.168.10.5\\\n</pre>\\\n<h3 style=\\\"box-sizing:border-box;font-family:Roboto, sans-serif;color:rgb(17, 17, 17);font-weight:400;margin:6px 0px;font-size:22px;line-height:30px;margin-top:27px;margin-bottom:17px;\\\">Upstream Name Servers</h3>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\">Controlling which upstream name servers your network uses is one of the nicer benefits of running your own name server, instead of being stuck with whatever your ISP wants you to use. This example uses the Google public name servers. You don’t have to use Google; a quick Web search will find a lot of public DNS servers.</p>\\\n<pre style=\\\"box-sizing:border-box;background-color:rgb(241, 241, 241);padding:4px 10px;border:none;border-radius:0px;margin-top:24px;overflow:auto;font-family:monospace, monospace;font-size:1em;\\\">server=8.8.4.4\\\nserver=8.8.8.8\\\n</pre>\\\n<h3 style=\\\"box-sizing:border-box;font-family:Roboto, sans-serif;color:rgb(17, 17, 17);font-weight:400;margin:6px 0px;font-size:22px;line-height:30px;margin-top:27px;margin-bottom:17px;\\\">DNS Hosts</h3>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><font style=\\\"box-sizing:border-box;\\\">Adding DNS hosts to Dnsmasq is almost as easy as falling over. All you do is add them to , like this, using your own addresses and hostnames:</font><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/hosts</code></p>\\\n<pre style=\\\"box-sizing:border-box;background-color:rgb(241, 241, 241);padding:4px 10px;border:none;border-radius:0px;margin-top:24px;overflow:auto;font-family:monospace, monospace;font-size:1em;\\\">127.0.0.1       localhost\\\n192.168.10.2    webserver\\\n192.168.10.3    fileserver \\\n192.168.10.4    dnsmasq\\\n192.168.10.5    timeserver\\\n</pre>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><font style=\\\"box-sizing:border-box;\\\">Dnsmasq reads , and these hosts are available to your LAN either by hostname or by their fully-qualified domain names. The  option in  expands the hostnames to the  value, for example webserver.mydomain.net</font><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/hosts</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">expand-hosts</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/dnsmasq.conf</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">domain=</code></p>\\\n<h3 style=\\\"box-sizing:border-box;font-family:Roboto, sans-serif;color:rgb(17, 17, 17);font-weight:400;margin:6px 0px;font-size:22px;line-height:30px;margin-top:27px;margin-bottom:17px;\\\">Set Static Addresses from DHCP</h3>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><font style=\\\"box-sizing:border-box;\\\">This is my favorite thing. You may assign static IP addresses to your LAN hosts by MAC address, or by hostname. The address must fall in a range you have already configured with :</font><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">dhcp-range=</code></p>\\\n<pre style=\\\"box-sizing:border-box;background-color:rgb(241, 241, 241);padding:4px 10px;border:none;border-radius:0px;margin-top:24px;overflow:auto;font-family:monospace, monospace;font-size:1em;\\\">dhcp-host=<i style=\\\"box-sizing:border-box;\\\">d0:50:99:82:e7:2b,192.168.10.46</i>\\\ndhcp-host=<i style=\\\"box-sizing:border-box;\\\">turnip,192.168.10.45</i>\\\n</pre>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><font style=\\\"box-sizing:border-box;\\\">On most Linux distributions it is the default for dhclient to send the hostname. You can confirm this in , with the  option. Do not have any duplicate entries in .</font><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">dhclient.conf</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">send host-name</code><code style=\\\"box-sizing:border-box;position:relative;top:-1px;border:none;background-color:rgb(241, 241, 241);padding:2px 6px;font-family:monospace, monospace;font-size:1em;\\\">/etc/hosts</code></p>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\">Here we are again at the end already. Check out these articles for more Dnsmasq features and howtos:</p>\\\n<ul style=\\\"box-sizing:border-box;padding:0px;margin-bottom:26px;\\\">\\\n<li style=\\\"box-sizing:border-box;margin-left:21px;margin-bottom:10px;line-height:inherit;\\\"><a href=\\\"https://www.linux.com/learn/intro-to-linux/2018/2/advanced-dnsmasq-tips-and-tricks\\\" style=\\\"box-sizing:border-box;text-decoration:none;background-color:transparent;color:rgb(255, 108, 14);\\\">Advanced Dnsmasq Tips and Tricks</a></li>\\\n<li style=\\\"box-sizing:border-box;margin-left:21px;margin-bottom:10px;line-height:inherit;\\\"><a href=\\\"https://www.linux.com/learn/intro-to-linux/2017/7/dns-spoofing-dnsmasq\\\" style=\\\"box-sizing:border-box;text-decoration:none;background-color:transparent;color:rgb(255, 108, 14);\\\">DNS Spoofing with Dnsmasq</a></li>\\\n<li style=\\\"box-sizing:border-box;margin-left:21px;margin-bottom:10px;line-height:inherit;\\\"><a href=\\\"https://www.linux.com/learn/dnsmasq-easy-lan-name-services\\\" style=\\\"box-sizing:border-box;text-decoration:none;background-color:transparent;color:rgb(255, 108, 14);\\\">Dnsmasq For Easy LAN Name Services</a></li>\\\n<li style=\\\"box-sizing:border-box;margin-left:21px;line-height:inherit;margin-bottom:0px;\\\"><a href=\\\"http://www.thekelleys.org.uk/dnsmasq/doc.html\\\" style=\\\"box-sizing:border-box;text-decoration:none;background-color:transparent;color:rgb(255, 108, 14);\\\">Dnsmasq home</a></li>\\\n</ul>\\\n<p style=\\\"box-sizing:border-box;margin-top:0px;margin-bottom:26px;overflow-wrap:break-word;\\\"><em style=\\\"box-sizing:border-box;\\\">Learn more about Linux through the free <a href=\\\"https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux\\\" style=\\\"box-sizing:border-box;text-decoration:none;background-color:transparent;color:rgb(255, 108, 14);\\\">“Introduction to Linux” </a>course from The Linux Foundation and edX.</em></p>\\\n        </div></div></div></div></div></div></div></div></div></div></div>\\\n</div>\\\n</span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":18231}]"
metadata_diff: {"new":{"id":"61a492386fc040539b45e138599ffc27","parent_id":"061de1401cfc4cfaadf6e74e015970e9","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764345716672,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T16:12:36.217Z
created_time: 2025-11-28T16:12:36.217Z
type_: 13