Full fix:
Set FQDN in "/etc/hostname" (as this is recommended and sometimes required for some software):
sudo nano /etc/hostname
In "/etc/hosts" alter the line with "127.0.1.1" into a FQDN too:
sudo nano /etc/hosts
Ad 'localise-queries' option to have dnsmasq respond depending on interface:
echo 'localise-queries' | sudo tee /etc/dnsmasq.d/localise-queries.conf
Reboot:
sudo reboot
On Pi-Hole, check new hostname with:
hostname; hostname -s; hostname -f
On Pi-Hole, check via ping if "/etc/hosts" is setup correctly by checking the returned IP address which should be "127.0.1.1":
ping <FQDN>
On Pi-Hole web GUI, check if displayed hostname under settings is correct and if not, run below one to update:
pihole -g
Test from client with:
nslookup <SHORT_HOSTNAME>
Or:
host <SHORT_NAME>
As example:
$ cat /etc/hostname
noads.dehakkelaar.nl
$ hostname; hostname -s; hostname -f
noads.dehakkelaar.nl
noads
noads.dehakkelaar.nl
$ cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 noads.dehakkelaar.nl
$ ping noads.dehakkelaar.nl
PING noads.dehakkelaar.nl (127.0.1.1) 56(84) bytes of data.
$ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 127.0.0.1
$ cat /etc/dnsmasq.d/localise-queries.conf
localise-queries
$ host noads
noads.dehakkelaar.nl has address 10.0.0.8
Pew, ready now or did I left something out ?
Added below as this seems to confuse alot of people:
$ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 127.0.0.1
It says for DNS resolution, use the localhost Pi-Hole dnsmasq daemon who is listening on all interfaces including the 127.0.0.1 loopback interface IP address.
Pi-Hole is not using this file, only local processes that invoke DNS, because Pi-Hole got its own upstream DNS servers configured for resolution.
Referring to MrD's post (Teleporter: Add '/etc/pihole/local.list' - #3 by MrD )
pihole -g
should be enough to update /etc/pihole/local.list.
Not sure if running the "-g" option will update all hostname instances for Pi-Hole besides the "/etc/pihole/local.list" file.
Had a quick look at the code but got lost in functions.
For now I would stick with the "-r" option or maybe a dev or someone else knows ?
Ping @MrD
For the hosts issue:
pi-hole:development
← deHakkelaar:patch-1
opened 06:53AM - 30 Apr 17 UTC
Avoid dnsmasq being populated with loopback IP addresses from the "/etc/hosts" f… ile that are of no use for resolving host to host:
"no-hosts"
Discource:
https://discourse.pi-hole.net/t/pi-hole-server-lose-awareness-of-it-self/2715/26
**By submitting this pull request, I confirm the following (please check boxes, eg [X]) _Failure to fill the template will close your PR_:**
***Please submit all pull requests against the `development` branch. Failure to do so will delay or deny your request***
- [x] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
- [X] I have checked that [another pull request](https://github.com/pi-hole/pi-hole/pulls) for this purpose does not exist.
- [X] I have considered, and confirmed that this submission will be valuable to others.
- [X] I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
- [X] I give this submission freely, and claim no ownership to its content.
**How familiar are you with the codebase?:**
_{2}_
---
_{Avoid dnsmasq being populated with loopback IP addresses in the "/etc/hosts" file that are of no use for resolving host to host}_
_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._
My first ever pull on git
Looks like the "-g" option is all it needs but not sure:
$ sudo grep noads -R /etc/
/etc/pihole/local.list: 10.0.0.8 noads.dehakkelaar.nl
/etc/hostname: noads.dehakkelaar.nl
/etc/hosts: 127.0.1.1 noads.dehakkelaar.nl
@GR3mGH0n ,
The guys found this little gem:
pi-hole:development
← pi-hole:tweak/localise-queries
opened 11:53AM - 30 Apr 17 UTC
**By submitting this pull request, I confirm the following (please check boxes, … eg [X]) _Failure to fill the template will close your PR_:**
***Please submit all pull requests against the `development` branch. Failure to do so will delay or deny your request***
- [X] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
- [X] I have checked that [another pull request](https://github.com/pi-hole/pi-hole/pulls) for this purpose does not exist.
- [X] I have considered, and confirmed that this submission will be valuable to others.
- [X] I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
- [X] I give this submission freely, and claim no ownership to its content.
**How familiar are you with the codebase?:** 10
---
This PR is building on top of the discussion in #1407
We add the flag `localise-queries` to `01-pihole.conf`
From the `man` page:
> --localise-queries
> Return answers to DNS queries from /etc/hosts which depend on the interface over which the query was received. If a name in /etc/hosts has more than one address associated with it, and at least one of those addresses is on the same subnet as the interface to which the query was sent, then return only the address(es) on that subnet. This allows for a server to have multiple addresses in /etc/hosts corresponding to each of its interfaces, and hosts will get the correct address based on which network they are attached to. Currently this facility is limited to IPv4.
This option is available since (at least) `dnsmasq v2.60`.
The result **without** this flag on two different machines (the first one is running `dnsmasq` locally):
```
pi@raspberrypi ~ $ dig +noall +answer raspberrypi
raspberrypi. 300 IN A 192.168.2.10
raspberrypi. 300 IN A 127.0.1.1
me@desktop ~ $ dig +noall +answer raspberrypi
raspberrypi. 300 IN A 127.0.1.1
raspberrypi. 300 IN A 192.168.2.10
```
And **with** this flag:
```
pi@raspberrypi ~ $ dig +noall +answer raspberrypi
raspberrypi. 300 IN A 127.0.1.1
me@desktop ~ $ dig +noall +answer raspberrypi
raspberrypi. 300 IN A 192.168.2.10
```
_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._
This to allow users to still add entries in the "/etc/hosts" file that will be read by dnsmasq to share with the clients.
Though the hosts file is not intended for that, allot of us (ab)use it like that anyway just for the ease.
Proper way is to configure dnsmask to load your own list of hosts and IP addresses to be loaded as DNS records.
I already implemented the "localise-queries" directive and without breaking loopback, everything looks dandy.
If you want to help out testing:
sudo rm /etc/dnsmasq.d/no-hosts-file.conf
echo 'localise-queries' | sudo tee /etc/dnsmasq.d/99-localise-queries.conf
sudo service dnsmasq restart
I already read both requests this afternoon and be pleased about the canny solution. I reprocuced the changes on my system and I can confirm: Everything operates flawless so far.
@MrD ,
Discourse derailing a bit but I saw your response.
Thats sweet bc that means you wont have to go through the lengthy procedure of reconfigure.
FYI, I updated:
$ pihole -v
::: Pi-hole version is v3.0 (Latest version is v3.0)
::: Web-Admin version is v3.0 (Latest version is v3.0)
And seem to have lost my entry:
$ sudo grep 'localise-queries' -R /etc
$ host noads.dehakkelaar.nl
noads.dehakkelaar.nl has address 127.0.1.1
noads.dehakkelaar.nl has address 10.0.0.8
So you'll need to add it again until tested and implemented:
echo 'localise-queries' | sudo tee /etc/dnsmasq.d/localise-queries.conf
sudo service dnsmasq restart
pi@noads:~ $ host noads.dehakkelaar.nl
noads.dehakkelaar.nl has address 127.0.1.1
xbian@arcade ~ $ host noads.dehakkelaar.nl
noads.dehakkelaar.nl has address 10.0.0.8
My file is still there. I named it:
99-localise-queries.conf
Yeah I think I read before that happening if you dont number them high.
Adjusted solution ... Thx!