Использование dnsmasq для адресации машин по именам и разрешения внешних имен хостов

25507
BrDaHa

У меня проблемы с настройкой dnsmasq. Все, что я хочу, это разрешить определенные имена хостов по определенным IP-адресам для любой машины в моей сети. Точнее говоря, я пытаюсь разрешить всем устройствам в моей сети доступ к некоторым машинам в моей сети, используя только указанное имя хоста. Я думаю, что, должно быть, мне не хватает чего-то важного, потому что, несмотря на то, что я однажды включил его, после перезагрузки DNS-сервера он перестал пересылать запросы на серверы за пределами локальной сети.

Вот мои настройки: (все IP-адреса имеют только последнюю цифру адреса IPv4)

  • Apple Airport Extreme настроен в режимах DHCP и NAT (на этом маршрутизаторе не может быть только NAT, поэтому для получения NAT я установил диапазон DHCP 253-254 и зарезервировал некоторые поддельные mac-адреса для этих IP-адресов). В моей сети это IP-адрес 1

  • Raspberry PI работает распбиан и dnsmasq. Это имеет IP-адрес 4 и имеет имя хоста "пи"

  • Машина под названием «башня» в 3

Dnsmasq настроен, чтобы быть сервером DNS и DHCP. Все машины, которые подключаются к сети, получают IP-адрес в правильном диапазоне, который я указал в dnsmasq, и Raspberry Pi (IP 4) автоматически назначается в качестве DNS-сервера. Dnsmasq также настроен на пересылку любых запросов, которые он не может найти, на другие общедоступные DNS-серверы. Вот полные мои DNS-серверы с полными отредактированными IP-адресами:

/etc/dnsmasq.conf:

# Dnsmasq.conf for raspberry pi  # Full examples found here:  # http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq.conf.example   # Set up your local domain here  domain=hyrule.home  # Example: The option local=/localnet/ ensures that any domain name query which ends in .localnet will be answered if possible from /etc/hosts or DHCP, but never sent to an upstream server # don't forward requests (andrewoberstar.com/blog/2012/12/30/raspberry-pi-as-server-dns-and-dhcp) local=/hyrule.home/  #resolv-file=/etc/resolv.dnsmasq  resolv-file=/etc/resolv.conf  #min-port=4096   ## DNS SERVERS #openNic california server=173.230.156.28  #openNic Washington server=23.226.230.72  #google public DNS server=8.8.8.8 server=8.8.4.4  # Max cache size dnsmasq can give us cache-size=10000  # Use the hosts file on this machine expand-hosts  # ethernet - ip address mappings from /etc/ethers file read-ethers  # Below are settings for dhcp.  dhcp-range=XXX.XXX.X.10,XXX.XXX.X.200,12h dhcp-option=3,XXX.XXX.X.1 dhcp-authoritative log-queries 

/etc/resolv.conf:

domain hyrule.home  #search hyrule.home #nameserver 8.8.8.8 

/ и т.д. / хосты

127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters  127.0.1.1 raspberrypi XXX.XXX.X.3 tower XXX.XXX.X.4 pi 

И файл / etc / ethers содержит mac-адреса интерфейсов ethernet соответствующих машин.

Я вижу, что dnsmasq регистрирует запросы, и все выглядит нормально, все запросы выглядят как

Nov 2 17:29:21 raspberrypi dnsmasq[2067]: query[AAAA] time.apple.com.hsd1.ca.comcast.net from 10.0.1.1 Nov 2 17:29:21 raspberrypi dnsmasq[2067]: forwarded time.apple.com.hsd1.ca.comcast.net to 173.230.156.28 Nov 2 17:29:21 raspberrypi dnsmasq[2067]: forwarded time.apple.com.hsd1.ca.comcast.net to 23.226.230.72 Nov 2 17:29:21 raspberrypi dnsmasq[2067]: forwarded time.apple.com.hsd1.ca.comcast.net to 8.8.8.8 Nov 2 17:29:21 raspberrypi dnsmasq[2067]: forwarded time.apple.com.hsd1.ca.comcast.net to 8.8.4.4 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: query[A] north-america.pool.ntp.org from 10.0.1.59 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded north-america.pool.ntp.org to 8.8.4.4 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded north-america.pool.ntp.org to 8.8.8.8 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded north-america.pool.ntp.org to 23.226.230.72 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded north-america.pool.ntp.org to 173.230.156.28 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: query[TXT] push.apple.com from 10.0.1.3 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded push.apple.com to 8.8.8.8 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded push.apple.com to 23.226.230.72 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded push.apple.com to 173.230.156.28 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded push.apple.com to 8.8.4.4 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: query[AAAA] time.apple.com.hyrule.home from 10.0.1.14 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: config time.apple.com.hyrule.home is NXDOMAIN-IPv6 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: query[A] time.apple.com.hyrule.home from 10.0.1.14 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: config time.apple.com.hyrule.home is NXDOMAIN-IPv4 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: query[AAAA] time.apple.com from 10.0.1.14 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded time.apple.com to 8.8.4.4 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded time.apple.com to 8.8.8.8 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded time.apple.com to 23.226.230.72 Nov 2 17:29:24 raspberrypi dnsmasq[2067]: forwarded time.apple.com to 173.230.156.28 

РЕДАКТИРОВАТЬ: Я решил просто сбросить пи в Rasbian по умолчанию, потому что я много экспериментировал на нем, поэтому я хотел удалить любые другие переменные. Я пошел вперед и загрузил минибьян и установил dnsmasq. Я отредактировал свой resolv.conf так, чтобы он выглядел так (спасибо @Chuck Kollars за указание, что этот файл действительно делал):

domain hyrule.home search hyrule.home nameserver XXX.XXX.X.4 

и только установите мой dnsmasq.conf для запроса к этим серверам имен (по умолчанию читая мой файл hosts):

server=/localnet/192.168.0.1 <--- still have the feeling this isn't right ## DNS SERVERS #openNic california server=173.230.156.28  #openNic Washington server=23.226.230.72 

В моем файле hosts у меня также были псевдонимы, настроенные как предложенный @Chuck Kollars, с форматом

<ipv4> <subdomain> <fqdn> 

В этот момент у меня все еще были проблемы, и я заметил, что всякий раз, когда я пинговал что-то вроде «башни», dnsmasq пытался разрешить «tower.hsdn.comcast.com» или что-то в этом роде, перенаправляя его на внешние серверы имен потому что это не решило внутренне. Часть comcast выглядела знакомой, поэтому в моей утилите аэропорта (5.6.1) на вкладке Интернет в разделе TCP / IP этот же адрес был заполнен в поле «Имя домена» (ghosted, как будто он был унаследован), поэтому я изменил его также быть hyrule.home, и все работало, как ожидалось!

Я все еще не понимаю, почему это имя домена должно быть в маршрутизаторе, и почему оно не учитывается в файле resolv.conf ...

2
Я унаследовал в том смысле, что, поскольку у меня есть собственный внутренний IP-адрес DNS, я указал это в конфигурации маршрутизатора, и, следовательно, любая машина в моей сети получает тот же адрес DNS-сервера. BrDaHa 9 лет назад 0

1 ответ на вопрос

3
Chuck Kollars

Although I can't quite figure out all the details of why your system misbehaves, I do have the following suggestions of things you could profitably look at:

1) Dnsmasq uses /etc/resolv.conf only for queries that originated on that same machine - queries from all other machines go directly into Dnsmasq. So /etc/resolv.conf typically contains a pointer to nameserver 127.0.0.1 in order to get requests originating from apps on that machine into Dnsmasq. In fact, /etc/resolv.conf may even be overwritten when Dnsmasq starts. Be very wary about putting operational instructions in /etc/resolv.conf; in particular I don't think "domain hyrule.home" is doing what you think it's doing for some of your hosts.

2) Another way to handle local shortnames (the way I do it), is to explicitly put both the shortname and the longname of each local machine into /etc/hosts (rather than relying on any software mechanism), something like this:

XXX.XXX.X.1 router router.hynet.home XXX.XXX.X.3 tower tower.hynet.home XXX.XXX.X.4 pi pi.hynet.home 

3) I'm not too sure what the definition equating "raspberrypi" to "localhost" is for. I'd be afraid of such an equivalence sometimes generating the wrong response to the wrong system at the wrong time, resulting in some queries going in the round file rather than where they were supposed to. My system works with no such definition.

4) For clarity in your various logs, you may want a definition of "localnet" too (analogous to your definition for "ip6-localnet"). You would expect this to go in /etc/networks ...and in fact that may work. But Dnsmasq itself only looks at /etc/hosts, so you may have to instead put the definition into /etc/hosts even though it's for a network, something like this:

XXX.XXX.X.0 localnet hynet.home 
Спасибо, Чак Колларс, я думаю, что я не столько настраивал dnsmasq, сколько как я настраивал домен на своем роутере. BrDaHa 8 лет назад 0

Похожие вопросы