diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-08-18 21:22:15 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-08-19 00:16:11 +0200 |
| commit | 42af81b283832aee07c336f9d591350a9fc089da (patch) | |
| tree | f26555e57a5ed3946d206ee04f0328ea478d118d | |
| parent | 08e7307ea0b311e081560ed6126a6c0d196215e4 (diff) | |
Fix pihole install to work on raspberry and simplify on arch
| -rw-r--r-- | roles/network/templates/resolved.conf.j2 | 7 | ||||
| -rw-r--r-- | roles/pihole/handlers/main.yml | 5 | ||||
| -rw-r--r-- | roles/pihole/tasks/main.yml | 44 | ||||
| -rw-r--r-- | roles/pihole/templates/pihole.toml.j2 | 2 |
4 files changed, 43 insertions, 15 deletions
diff --git a/roles/network/templates/resolved.conf.j2 b/roles/network/templates/resolved.conf.j2 index 600608dc..c94e9c1a 100644 --- a/roles/network/templates/resolved.conf.j2 +++ b/roles/network/templates/resolved.conf.j2 @@ -7,12 +7,15 @@ DNSOverTLS=yes # Enable multicast DNS for .local domain resolution (replaces avahi functionality) MulticastDNS=yes -# Enable LLMNR for Windows network compatibility -LLMNR=yes +# Disable LLMNR to prevent reverse DNS lookup delays +LLMNR=no Cache=yes CacheFromLocalhost=no +# Reduce timeout for faster reverse DNS fallback +ResolveUnicastSingleLabel=no + # Enable DNS stub listener on 127.0.0.53:53 DNSStubListener=yes diff --git a/roles/pihole/handlers/main.yml b/roles/pihole/handlers/main.yml index 3e69d469..dca1ef52 100644 --- a/roles/pihole/handlers/main.yml +++ b/roles/pihole/handlers/main.yml @@ -8,3 +8,8 @@ ansible.builtin.systemd_service: name: "systemd-resolved" state: "restarted" + +- name: "Restart NetworkManager" + ansible.builtin.systemd_service: + name: "NetworkManager" + state: "restarted" diff --git a/roles/pihole/tasks/main.yml b/roles/pihole/tasks/main.yml index 92f787df..84899e26 100644 --- a/roles/pihole/tasks/main.yml +++ b/roles/pihole/tasks/main.yml @@ -63,15 +63,35 @@ cmd: "pihole -g" changed_when: false -- name: "Set Pi-hole as system DNS" - ansible.builtin.lineinfile: - path: "/etc/systemd/resolved.conf" - regexp: "{{ item.regexp }}" - line: "{{ item.line }}" - backup: true - notify: "Restart systemd-resolved" - with_items: - - regexp: "^#?DNSStubListener=" - line: "DNSStubListener=no" - - regexp: "^#?DNS=" - line: "DNS=127.0.0.1" +- name: "Configure pihole as system DNS" + notify: + - "Restart NetworkManager" + - "Restart systemd-resolved" + block: + - name: "Configure NetworkManager to disable DNS management" + ansible.builtin.copy: + dest: "/etc/NetworkManager/NetworkManager.conf" + owner: "root" + group: "root" + mode: "0644" + content: | + [main] + dns=none + + - name: "Configure systemd-resolved for Pi-hole" + ansible.builtin.copy: + dest: "/etc/systemd/resolved.conf" + owner: "root" + group: "root" + mode: "0644" + content: | + [Resolve] + DNS=127.0.0.1#53 + DNSStubListener=no + + - name: "Configure system DNS" + ansible.builtin.file: + src: "/run/systemd/resolve/resolv.conf" + dest: "/etc/resolv.conf" + state: "link" + force: true diff --git a/roles/pihole/templates/pihole.toml.j2 b/roles/pihole/templates/pihole.toml.j2 index 6d730d11..78467364 100644 --- a/roles/pihole/templates/pihole.toml.j2 +++ b/roles/pihole/templates/pihole.toml.j2 @@ -36,7 +36,7 @@ interface = "{{ pihole_interface }}" # Permit all origins, accept on all interfaces. Make sure your Pi-hole is firewalled. # - "NONE" # Do not add any configuration concerning the listening mode to the dnsmasq config file. -listeningMode = "SINGLE" +listeningMode = "LOCAL" [dns.cache] size = 10000 # Cache size of the DNS server. |
