Skip to content

Commit bebb8a3

Browse files
committed
2023-06-15 Pi-hole - master branch - PR 1 of 2
Applies changes recommended by `yamllint`. Adds `FTLCONF_MAXDBDAYS` to the template with the existing default of 365 days, and adds words to the documentation explaining its use. Adds `PIHOLE_DNS_` with the existing defaults of 8.8.8.8 and 8.8.4.4, and adds words and screenshot to the documentation explaining its use. Explains issue with Docker Desktop for macOS raised in #709 where all client activity is logged against the default gateway on the internal bridged network. Tidies-up problematic code-fence language specs. Shortens some subheadings so they fit on a single line in the Wiki TOC. Fixes #709 Signed-off-by: Phill Kelley <[email protected]>
1 parent 96f4297 commit bebb8a3

File tree

3 files changed

+89
-33
lines changed

3 files changed

+89
-33
lines changed

.templates/pihole/service.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ pihole:
22
container_name: pihole
33
image: pihole/pihole:latest
44
ports:
5-
- "8089:80/tcp"
6-
- "53:53/tcp"
7-
- "53:53/udp"
8-
- "67:67/udp"
5+
- "8089:80/tcp"
6+
- "53:53/tcp"
7+
- "53:53/udp"
8+
- "67:67/udp"
99
environment:
10-
- TZ=${TZ:-Etc/UTC}
11-
- WEBPASSWORD=
10+
- TZ=${TZ:-Etc/UTC}
11+
- WEBPASSWORD=
1212
# see https://sensorsiot.github.io/IOTstack/Containers/Pi-hole/#adminPassword
13-
- INTERFACE=eth0
13+
- INTERFACE=eth0
14+
- FTLCONF_MAXDBDAYS=365
15+
- PIHOLE_DNS_=8.8.8.8;8.8.4.4
1416
# see https://github.com/pi-hole/docker-pi-hole#environment-variables
1517
volumes:
16-
- ./volumes/pihole/etc-pihole:/etc/pihole
17-
- ./volumes/pihole/etc-dnsmasq.d:/etc/dnsmasq.d
18+
- ./volumes/pihole/etc-pihole:/etc/pihole
19+
- ./volumes/pihole/etc-dnsmasq.d:/etc/dnsmasq.d
1820
dns:
19-
- 127.0.0.1
20-
- 1.1.1.1
21+
- 127.0.0.1
22+
- 1.1.1.1
2123
cap_add:
22-
- NET_ADMIN
24+
- NET_ADMIN
2325
restart: unless-stopped
2426

docs/Containers/Pi-hole.md

100644100755
Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Each time the Pi-hole container is launched, it checks for the presence or absen
8181

8282
Some Pi-hole documentation on the web recommends using the following command to change Pi-hole's admin password:
8383

84-
```console
84+
``` console
8585
$ docker exec pihole pihole -a -p «yourPasswordHere»
8686
```
8787

@@ -101,9 +101,56 @@ then "mySecondPassword" will become the admin password **until** the next time t
101101

102102
Given this behaviour, we recommend that you ignore the `pihole -a -p` command.
103103

104-
### Other variables { #otherVars }
104+
### Logging { #loggingVar }
105+
106+
You can control the amount of information Pi-hole retains about your DNS queries using the "Privacy Settings" tab of the "Settings" group. The default is "Show & record everything".
107+
108+
If you choose any option except "Anonymous mode", then Pi-hole divides the logging store into two parts:
109+
110+
* Entries which are more recent than 24 hours; and
111+
* Entries which are older than 24 hours.
112+
113+
In the "System" tab of the "Settings" group is a <kbd>Flush logs (last 24 hours)</kbd> button. Clicking that button erases all log entries which are more recent than 24 hours. The button does **not** erase entries which are older than 24 hours.
114+
115+
Retention of log entries older than 24 hours is controlled by the following environment variable:
116+
117+
``` yaml
118+
- FTLCONF_MAXDBDAYS=365
119+
```
120+
121+
The default (which applies if the variable is omitted) is to retain log entries for 365 days.
105122

106-
Most of Pi-hole's environment variables are self-explanatory but some can benefit from elaboration.
123+
Depending on your DNS activity, the database where the log entries are stored can become quite large. Setting this variable to a shorter period will help you control the amount of storage Pi-hole consumes on disk and in your backups.
124+
125+
Tip:
126+
127+
* Adding this variable to an existing service definition, or changing the number of days to be less than the previous setting will **not** reduce the size of the logging database. Although Pi-hole will implement the change, the SQLite database where the logs are written retains the released storage for subsequent re-use. If you want to reclaim that space, run the following command:
128+
129+
``` console
130+
$ sqlite3 ~/IOTstack/volumes/pihole/etc-pihole/pihole-FTL.db "vacuum;"
131+
```
132+
133+
The command should not need `sudo` because `pi` is the owner by default. There is no need to terminate Pi-hole before running this command (SQLite handles any contention).
134+
135+
### Recursive resolvers { #upstreamDNS }
136+
137+
You can control which public DNS servers are used by PiHole when it needs to refer queries to the Internet. You do this by enabling or disabling checkboxes in the "Upstream DNS Servers" panel of the "DNS" tab in the "Settings" group.
138+
139+
The default is to use the two Google IPv4 DNS servers which correspond with 8.8.8.8 and 8.8.4.4, respectively.
140+
141+
An alternative to toggling checkboxes in the Pi-hole GUI is to use an environment variable:
142+
143+
``` yaml
144+
- PIHOLE_DNS_=8.8.8.8;8.8.4.4
145+
```
146+
147+
> The variable *does* end with an underscore!
148+
149+
This variable takes a semi-colon-separated list of DNS servers. You can discover the IP address associated with a checkbox by hovering your mouse pointer over the checkbox and waiting for a tool-tip to appear:
150+
151+
![](./images/pihole-server-ip-discovery.png)
152+
153+
### Advanced variables { #advancedVars }
107154

108155
??? info "(advanced) reverse DNS query handling"
109156

@@ -221,13 +268,13 @@ devices, provided they too have static IPs.
221268
be reserved for mDNS use only.
222269
{ #homeArpa }
223270

224-
## Configure the Raspberry Pi to use Pi-hole { #rpiDNS }
271+
## Configure your Pi to use Pi-hole { #rpiDNS }
225272

226273
The Raspberry Pi itself does **not** have to use the Pi-hole container for its own DNS services. Some chicken-and-egg situations can exist if, for example, the Pi-hole container is down when another process (eg `apt` or `docker-compose`) needs to do something that depends on DNS services being available.
227274

228275
Nevertheless, if you configure Pi-hole to be local DNS resolver, then you will probably want to configure your Raspberry Pi to use the Pi-hole container in the first instance, and then fall back to a public DNS server if the container is down. As a beginner, this is probably what you want regardless. Do this by running the commands:
229276

230-
```console
277+
``` console
231278
$ echo "name_servers=127.0.0.1" | sudo tee -a /etc/resolvconf.conf
232279
$ echo "name_servers_append=8.8.8.8" | sudo tee -a /etc/resolvconf.conf
233280
$ echo "resolv_conf_local_only=NO" | sudo tee -a /etc/resolvconf.conf
@@ -253,7 +300,7 @@ container isn't running.
253300

254301
You need slightly different syntax if you want to add multiple fallback servers. For example, suppose your fallback hosts are a local server (eg 192.168.1.2) running BIND9 and 8.8.8.8. The command would be:
255302

256-
```console
303+
``` console
257304
$ echo 'name_servers_append="192.168.1.2 8.8.8.8"' | sudo tee -a /etc/resolvconf.conf
258305
```
259306

@@ -273,15 +320,15 @@ container isn't running.
273320

274321
* If you wish to prevent the Raspberry Pi from including the address(es) of DNS servers learned from DHCP, you can instruct the DHCP client running on the Raspberry Pi to ignore the information coming from the DHCP server:
275322

276-
```console
323+
``` console
277324
$ echo 'nooption domain_name_servers' | sudo tee -a /etc/dhcpcd.conf
278325
$ sudo service dhcpcd reload
279326
$ sudo resolvconf -u
280327
```
281328

282329
* If you have followed the steps in [Adding local domain names](#localNames) to define names for your local hosts, you can inform the Raspberry Pi of that fact like this:
283330

284-
```console
331+
``` console
285332
$ echo 'search_domains=home.arpa' | sudo tee -a /etc/resolvconf.conf
286333
$ sudo resolvconf -u
287334
```
@@ -305,19 +352,19 @@ container isn't running.
305352
It's possible to make DNS queries directly cross-container, and even
306353
supported in some [rare use-cases](WireGuard.md#customContInit).
307354

308-
## Configure Pi-hole as your local DNS resolver
355+
## Using Pi-hole as your local DNS
309356

310-
To use the Pi-hole in your LAN, you need to assign the RPi a fixed IP-address and configure this IP as your DNS server.
357+
To use the Pi-hole in your LAN, you need to assign the Raspberry Pi a fixed IP-address and configure this IP as your DNS server.
311358

312-
### 1. Assign the RPi a fixed IP address { #rpiFixedIP }
359+
### Fixed IP address for Pi-hole { #rpiFixedIP }
313360

314361
If you want clients on your network to use Pi-hole for their DNS, the Raspberry Pi running Pi-hole **must** have a fixed IP address. It does not have to be a *static* IP address (in the sense of being hard-coded into the Raspberry Pi). The Raspberry Pi can still obtain its IP address from DHCP at boot time, providing your DHCP server (usually your home router) always returns the same IP address. This is usually referred to as a *static binding* and associates the Raspberry Pi's MAC address with a fixed IP address.
315362

316363
Keep in mind that many Raspberry Pis have both Ethernet and WiFi interfaces. It is generally prudent to establish static bindings for *both* network interfaces in your DHCP server.
317364

318365
You can use the following command to discover the MAC addresses for your Raspberry Pi's Ethernet and WiFi interfaces:
319366

320-
```console
367+
``` console
321368
$ for I in eth0 wlan0 ; do ip link show $I ; done
322369
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
323370
link/ether dc:a6:32:4c:89:f9 brd ff:ff:ff:ff:ff:ff
@@ -332,8 +379,7 @@ In the above:
332379

333380
If a physical interface does not exist, the command returns "Device does not exist" for that interface. If you prefer, you can also substitute the `ifconfig` command for `ip link show`. It's just a little more wordy.
334381

335-
336-
### 2. Configuring other machines to use the Raspberry Pi running Pi-hole { #rpiConfig }
382+
### Configure clients to use Pi-hole { #rpiConfig }
337383

338384
In order for Pi-hole to block ads or resolve anything, clients need to be told to use it as their DNS server. You can either:
339385

@@ -378,7 +424,7 @@ Make these assumptions:
378424

379425
The result of the configuration appears in `/etc/resolv.conf`:
380426

381-
```console
427+
``` console
382428
$ cat /etc/resolv.conf
383429
# Generated by resolvconf
384430
nameserver 127.0.0.1
@@ -394,25 +440,23 @@ Interpretation:
394440

395441
The fact that the Raspberry Pi is effectively represented twice (once as 127.0.0.1, and again as 192.168.1.10) does not matter. If the Pi-hole container stops running, the Raspberry Pi will bypass 192.168.1.10 and fail over to 8.8.8.8, failing back to 127.0.0.1 when the Pi-hole container starts again.
396442

397-
398-
399443
Install dig:
400444

401-
```console
445+
``` console
402446
$ sudo apt install dnsutils
403447
```
404448

405449
Test that Pi-hole is correctly configured (should respond 192.168.1.10):
406450

407-
```console
451+
``` console
408452
$ dig raspberrypi.home.arpa @192.168.1.10
409453
```
410454

411455
To test on another machine if your network's DNS configuration is correct, and
412456
an ESP will resolve its DNS queries correctly, restart the other machine to
413457
ensure DNS changes are updated and then use:
414458

415-
```console
459+
``` console
416460
$ dig raspberrypi.home.arpa
417461
```
418462

@@ -450,7 +494,7 @@ The recommended approach is:
450494
3. Logout of the Web GUI.
451495
4. Run the following commands:
452496

453-
```console
497+
``` console
454498
$ cd ~/IOTstack
455499
$ docker-compose rm --force --stop -v pihole
456500
$ sudo rm -rf ./volumes/pihole
@@ -459,3 +503,13 @@ The recommended approach is:
459503

460504
5. Login to Pi-hole's web GUI and navigate to Settings » Teleporter.
461505
6. Use the checkboxes to select the settings you wish to restore, and click the <kbd>Browse</kbd> and <kbd>Restore</kbd> buttons.
506+
507+
## Docker Desktop { #dockerDesktop }
508+
509+
If you run Pi-hole using Docker Desktop for macOS, all client activity will be logged against the IP address of the default gateway on the internal bridged network.
510+
511+
It appears that Docker Desktop for macOS interposes an additional level of Network Address Translation (NAT) between clients and the Pi-hole service. This does not affect Pi-hole's ability to block ads. It just makes the GUI reports a little less useful.
512+
513+
It is not known whether this is peculiar to Docker Desktop for macOS or also affects other variants of Docker Desktop.
514+
515+
This problem does not affect Pi-hole running in a container on a Raspberry Pi.
465 KB
Loading

0 commit comments

Comments
 (0)