https://wiki.archlinux.org/api.php?action=feedcontributions&user=Xanthi00&feedformat=atomArchWiki - User contributions [en]2024-03-28T15:15:31ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Dnsmasq&diff=223654Dnsmasq2012-09-17T11:25:00Z<p>Xanthi00: /* NetworkManager */</p>
<hr />
<div>[[Category:Domain Name System]]<br />
[[it:Dnsmasq]]<br />
[[ru:Dnsmasq]]<br />
[[zh-CN:Dnsmasq]]<br />
{{Lowercase_title}}<br />
<br />
dnsmasq provides services as a DNS cacher and a DHCP server. As a Domain Name Server (DNS), it can cache DNS queries to improve connection speed to previously visited sites. As a DHCP server, {{Pkg|dnsmasq}} can be used to provide internal IP addresses and routes to computers on a LAN. Either or both of these services can be implemented. dnsmasq is considered to be lightweight and easy to configure; it is designed for personal computer use or for use on a network with less than 50 computers.<br />
<br />
== Installing ==<br />
<br />
[[pacman|Install]] {{Pkg|dnsmasq}} from the [[Official Repositories|official repositories]].<br />
<br />
== DNS Cache Setup ==<br />
<br />
To set up dnsmasq as a DNS caching daemon on a single computer edit {{ic|/etc/dnsmasq.conf}} and uncomment the localhost listening address:<br />
<br />
listen-address=127.0.0.1<br />
<br />
To use this computer to act as a default DNS specify the fixed IP address of the network:<br />
<br />
listen-address=<192.168.1.1> # Example IP<br />
<br />
=== DNS Addresses File ===<br />
<br />
After configuring dnsmasq the DHCP client will need to prepend the localhost address to the known DNS addresses in {{ic|/etc/resolv.conf}}. This causes all queries to be sent to dnsmasq before trying to resolve them with an external DNS. After the DHCP client is configured the network will need to be restarted for changes to take effect.<br />
<br />
==== dhcpcd ====<br />
<br />
{{Pkg|dhcpcd}} has the ability to prepend or append nameservers to {{ic|/etc/resolv.conf}} by creating (or editing) the {{ic|/etc/resolv.conf.head}} and {{ic|/etc/resolv.conf.tail}} files respectively:<br />
<br />
echo "nameserver 127.0.0.1" > /etc/resolv.conf.head<br />
<br />
==== dhclient ====<br />
<br />
For dhclient, uncomment in {{ic|/etc/dhclient.conf}}:<br />
<br />
prepend domain-name-servers 127.0.0.1;<br />
<br />
==== NetworkManager ====<br />
<br />
NetworkManager has the ability to start {{ic|dnsmasq}} from it's configuration file. Add the {{ic|1=dns=dnsmasq}} option to {{ic|NetworkManager.conf}} in the {{ic|[main]}} section and remove dnsmasq from loading at boot:<br />
<br />
{{hc|/etc/NetworkManager/NetworkManager.conf|<nowiki><br />
[main]<br />
plugins=keyfile<br />
dns=dnsmasq<br />
</nowiki>}}<br />
<br />
===== Other methods =====<br />
<br />
If using the dnsmasq daemon, then it is necessary to add the localhost address to {{ic|resolv.conf}} (which NetworkManager will be overriding).<br />
<br />
Since the upgrade of [[NetworkManager]] to 0.7, Arch Linux now calls {{Pkg|dhcpcd}} directly instead of the common default with {{Pkg|dhclient}}. Because of the arguments set with {{Pkg|dhcpcd}}, it no longer sources the {{ic|/etc/resolv.conf.head}}, and {{ic|/etc/resolv.conf.tail}} settings for insertion of name servers. Several options are available.<br />
<br />
The first option would be to add a script to the NetworkManager dispatcher to prepend localhost to {{ic|resolv.conf}}:<br />
<br />
{{hc|/etc/NetworkManager/dispatcher.d/localhost-prepend|<nowiki><br />
#!/bin/bash <br />
# Prepend localhost to resolv.conf for dnsmasq<br />
<br />
if [[ ! $(grep 127.0.0.1 /etc/resolv.conf) ]]; then<br />
sed -i '1s|^|nameserver 127.0.0.1\n|' /etc/resolv.conf<br />
fi</nowiki>}}<br />
<br />
and make it executable:<br />
<br />
# chmod +x /etc/NetworkManager/dispatcher.d/localhost-prepend<br />
<br />
The second option be to go into NetworkManagers' settings (usually by right-clicking the applet) and entering settings manually. Setting up will depending on the type of front-end used; the process usually involves right-clicking on the applet, editing (or creating) a profile, and then choosing DHCP type as 'Automatic (specify addresses).' The DNS addresses will need to be entered and are usually in this form: {{ic|127.0.0.1, DNS-server-one, ...}}.<br />
<br />
Lastly, NetworkManager with dhclient can be used ({{AUR|networkmanager-dhclient}}).<br />
<br />
===== Custom Configuration =====<br />
<br />
As of NetworkManager 0.9.6, custom configurations can be created for dnsmasq by creating configuration files in {{ic|/etc/NetworkManager/dnsmasq.d/}}<br />
<br />
== DHCP Server Setup ==<br />
<br />
By default dnsmasq has the DHCP functionality turned off, if you want to use it you must turn it on in ({{ic|/etc/dnsmasq.conf}}). Here are the important settings:<br />
<br />
{{bc|<nowiki><br />
# Only listen to routers' LAN NIC. Doing so opens up tcp/udp port 53 to<br />
# localhost and udp port 67 to world:<br />
interface=<LAN-NIC><br />
<br />
# dnsmasq will open tcp/udp port 53 and udp port 67 to world to help with<br />
# dynamic interfaces (assigning dynamic ips). Dnsmasq will discard world<br />
# requests to them, but the paranoid might like to close them and let the <br />
# kernel handle them:<br />
bind-interfaces<br />
<br />
# Dynamic range of IPs to make available to LAN pc<br />
dhcp-range=192.168.111.50,192.168.111.100,12h<br />
<br />
# If you’d like to have dnsmasq assign static IPs, bind the LAN computer's<br />
# NIC MAC address:<br />
dhcp-host=aa:bb:cc:dd:ee:ff,192.168.111.50<br />
</nowiki>}}<br />
<br />
== Start the Daemon ==<br />
<br />
To have dnsmasq to load upon startup, add it to the daemons array in {{ic|/etc/rc.conf}}:<br />
<br />
DAEMONS=(... dnsmasq network ...)<br />
<br />
To stand dnsmasq immediately:<br />
<br />
$ rc.d start dnsmasq<br />
<br />
To see if dnsmasq started properly, check the log; dnsmasq sends its messages to {{ic|/var/log/messages.log}}. The network will also need to be restarted so the the DHCP client can create a new {{ic|/etc/resolv.conf}}.<br />
<br />
== Test ==<br />
=== DNS Caching ===<br />
<br />
To do a lookup speed test choose a website that has not been visited since dnsmasq has been started ({{ic|dig}} is part of the {{Pkg|dnsutils}} package):<br />
<br />
$ dig archlinux.org | grep "Query time"<br />
<br />
Running the command again will use the cached DNS IP and result in a faster lookup time if dnsmasq is setup correctly.<br />
<br />
=== DHCP Server ===<br />
<br />
From a computer that is connected to the one with dnsmasq on it, configure it to use DHCP for automatic IP address assignment, then attempt to log into the network normally.<br />
<br />
== Tips ==<br />
<br />
=== Prevent OpenDNS Redirecting Google Queries ===<br />
<br />
To prevent OpenDNS from redirecting all Google queries to their own search server, add to {{ic|/etc/dnsmasq.conf}}:<br />
<br />
server=/www.google.com/<ISP DNS IP><br />
<br />
=== View leases ===<br />
cat /var/lib/misc/dnsmasq.leases</div>Xanthi00