Enable pi-hole along with hotspot in Ubuntu

I installed Pi-hole successfully but I'm enabling hotspot, so I got this error:

FTL failed to start due to failed to create listening socket for port 53: Address already in use (by dnsmasq)

When I kill dnsmasq, Pi-hole works fine, but I'm not now able to enable hotspot, I get:

dnsmasq[22153]: failed to create listening socket for port 53: Address already in use

I uninstalled dnsmasq-base and Pi-hole is working fine, but when I try to enable hotspot, I get this error:

NetworkManager[116210]: <warn> [1734879323.7233] device (wlp0s20f3): ip:shared4: could not start dnsmasq: Could not find "dnsmasq" binary

Is there a way to use Pi-hole and hotspot at the same time in Ubuntu? Can I configure hotspot to use Pi-hole instead of dnsmasq?

Not sure if it might work but you could try symlinking as pihole-FTL should work as a dnsmasq drop in/replacement.

$ apt-file list dnsmasq-base
[..]
dnsmasq-base: /usr/sbin/dnsmasq
$ which pihole-FTL
/usr/bin/pihole-FTL

Symlink to be made is:

sudo ln -s /usr/bin/pihole-FTL /usr/sbin/dnsmasq

Test:

$ readlink -f /usr/sbin/dnsmasq
/usr/bin/pihole-FTL
$ /usr/sbin/dnsmasq -vv
****************************** FTL **********************************
Version:         v5.25.2
Branch:          master
Commit:          8943e260 (2024-05-08 20:59:50 +0100)
Architecture:    armv6hf (compiled on CI)
Compiler:        arm-linux-gnueabihf-gcc (GCC) 10.3.0

****************************** dnsmasq ******************************
Version:         pi-hole-v2.90+1
Features:        IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth cryptohash DNSSEC loop-detect inotify dumpfile

****************************** SQLite3 ******************************
Version:         3.42.0
Features:        ATOMIC_INTRINSICS=1 COMPILER=gcc-10.3.0 DEFAULT_AUTOVACUUM DEFAULT_CACHE_SIZE=-16384 DEFAULT_FILE_FORMAT=4 DEFAULT_FOREIGN_KEYS DEFAULT_JOURNAL_SIZE_LIMIT=-1 DEFAULT_MEMSTATUS=0 DEFAULT_MMAP_SIZE=0 DEFAULT_PAGE_SIZE=4096 DEFAULT_PCACHE_INITSZ=20 DEFAULT_RECURSIVE_TRIGGERS DEFAULT_SECTOR_SIZE=4096 DEFAULT_SYNCHRONOUS=2 DEFAULT_WAL_AUTOCHECKPOINT=1000 DEFAULT_WAL_SYNCHRONOUS=2 DEFAULT_WORKER_THREADS=0 DQS=0 ENABLE_DBPAGE_VTAB MALLOC_SOFT_LIMIT=1024 MAX_ATTACHED=10 MAX_COLUMN=2000 MAX_COMPOUND_SELECT=500 MAX_DEFAULT_PAGE_SIZE=8192 MAX_EXPR_DEPTH=1000 MAX_FUNCTION_ARG=127 MAX_LENGTH=1000000000 MAX_LIKE_PATTERN_LENGTH=50000 MAX_MMAP_SIZE=0x7fff0000 MAX_PAGE_COUNT=1073741823 MAX_PAGE_SIZE=65536 MAX_SQL_LENGTH=1000000000 MAX_TRIGGER_DEPTH=1000 MAX_VARIABLE_NUMBER=32766 MAX_VDBE_OP=250000000 MAX_WORKER_THREADS=8 MUTEX_PTHREADS OMIT_DEPRECATED OMIT_DESERIALIZE OMIT_LOAD_EXTENSION OMIT_PROGRESS_CALLBACK SYSTEM_MALLOC TEMP_STORE=1 THREADSAFE=1

******************************** LUA ********************************
Version:         5.4
Libraries:       inspect.lua (8.46 KB)

***************************** LIBNETTLE *****************************
Version:         3.4
GMP:             Full

If not working you can delete the symlink with below:

sudo rm /usr/sbin/dnsmasq

I just realised that the dnsmasq instance called upon by NM would conflict with the pihole-FTL.service instance over port 53.
You could try disabling the pihole-FTL.service reboot persistent with below and hope NM will startup dnsmasq / pihole-FTL as expected:

sudo systemctl disable --now pihole-FTL.service

To enable again if not working as expected:

sudo systemctl enable --now pihole-FTL.service

Or else it gets quite complicated to have the two coexist bc of the port 53 conflict (EDIT: I guess).

EDIT: Below ones might be useful:

pstree -pt

sudo ss -nltup

EDIT2: Do you have below folder?

/etc/NetworkManager/dnsmasq-shared.d/

I believe thats the spot where dnsmasq config files can be dropped.
Or maybe there is one or more already?

Yes, I have this folder and dnsmasq.d folder as well, but they are empty.

[quote="deHakkelaar, post:3, topic:74690"]
/etc/NetworkManager/dnsmasq-shared.d/
[/quote]

Does above folder have content?
And whats in those files if any?

What absolute path is that?

/etc/NetworkManager/dnsmasq.d

Did you get the symlinked pihole-FTL to run via NM?
If so, what does below output?

ps -o cmd -C dnsmasq -C pihole-FTL

Unfortunately, the symbolic link approach didn't work. I got

NetworkManager[661]: <warn> [1735002298.9753] dnsmasq-manager: dnsmasq exited with error: Configuration problem (1)

Hmm never heard of dnsmasq-manager.
Not sure whats going on here.
Was worth a try :wink:

1 Like

Check below man page which has a few dnsmasq references:

$ man NetworkManager.conf
[..]
           dnsmasq: NetworkManager will run dnsmasq as a local
           caching nameserver, using "Conditional Forwarding" if you
           are connected to a VPN, and then update resolv.conf to
           point to the local nameserver. It is possible to pass
           custom options to the dnsmasq instance by adding them to
           files in the "/etc/NetworkManager/dnsmasq.d/" directory.

And maybe if you get the hotspot up with Pi-hole disabled, you can figure out with which arguments the dnsmasq binary is called upon with below?

EDIT: Oh change that into below so we know the user as well:

ps -o uid,user,gid,group,pid,cmd -C dnsmasq -C pihole-FTL

Oh blast, I realised above attempt maybe left some loging why it failed.
Check if so in below logs:

/var/log/pihole/FTL.log

/var/log/pihole/pihole.log

This has been asked before, see e.g.
Wifi hotspot not suppling ip & kills FTLDNS.

NetworkManager is able to start dnsmasq processes as required.
NM configures them via configuration files from /etc/NetworkManager/dnsmasq-shared.d (for its hotspot service) and /etc/NetworkManager/dnsmasq.d/ (for its DNS service).

So for NM's dnsmasq DHCP service and pihole-FTL's DNS service to coexist, you 'd have to make sure that neither one uses the ports of the other.

If you want Pi-hole to handle DNS, try adding port=0 to NM's dnsmasq config files to disable NM's DNS functionality and only leave DHCP.

1 Like

I added /etc/NetworkManager/dnsmasq.d/custom.conf that has only port=0 and then restarted the NetworkManager, but I got this:
NetworkManager[264904]: dnsmasq: failed to create listening socket for 10.42.0.1: Address already in use

I had a go at it on a tinker VM of mine (no Wifi).

I parked the pihole-FTL.service so NM can boot up an instance instead:

$ sudo systemctl disable --now pihole-FTL.service
Removed "/etc/systemd/system/multi-user.target.wants/pihole-FTL.service".

Configured NM to boot up a dnsmasq instance like so:

$ sudo nano /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile
dns=dnsmasq

[ifupdown]
managed=false
$ sudo systemctl restart NetworkManager.service
$
$ pstree -pts $(pidof -s dnsmasq)
systemd(1)---NetworkManager(1006422)---dnsmasq(1006434)

So I could figure out the user and arguments to hack:

$ ps -o uid,user,gid,group,pid,cmd -C dnsmasq -C pihole-FTL
  UID USER       GID GROUP        PID CMD
65534 nobody      30 dip      1006434 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/run/NetworkManager/dnsmasq.pid --listen-address=127.0.0.1 --cache-size=400 --clear-on-reload --conf-file=/dev/null --proxy-dnssec --enable-dbus=org.freedesktop.NetworkManager.dnsmasq --conf-dir=/etc/NetworkManager/dnsmasq.d

Reverted back to without running dnsmasq.
Removed below folder bc I want it to be a symlink to where Pi-hole stores its dnsmasq directives:

$ sudo rmdir /etc/NetworkManager/dnsmasq.d
$
$ sudo ln -s /etc/dnsmasq.d/ /etc/NetworkManager/
$

Added another listener bc of the --bind-interfaces argument:

$ sudo nano /etc/dnsmasq.d/99-my-settings.conf
listen-address=10.0.0.8

Got the dnsmasq binary out of the way:

$ sudo mv /usr/sbin/dnsmasq{,.org}
$

Replaced it for a symlink:

$ sudo ln -s /usr/bin/pihole-FTL /usr/sbin/dnsmasq
$

And re-enabled dnsmasq again in NM.
But it seems to be tripping over a lacking Dbus dependency (above --enable-dbus= argument):

$ sudo journalctl --full --follow --no-hostname --unit NetworkManager.service
[..]
Jan 01 21:48:05 NetworkManager[11001]: <info>  [1735764485.4118] dnsmasq: starting /usr/sbin/dnsmasq
Jan 01 21:48:05 NetworkManager[11365]: dnsmasq: DBus not available: set HAVE_DBUS in src/config.h
Jan 01 21:48:05 dnsmasq[11365]: DBus not available: set HAVE_DBUS in src/config.h
Jan 01 21:48:05 dnsmasq[11365]: FAILED to start up
$ sudo tail -F /var/log/pihole/FTL.log
[..]
[2025-01-01 21:48:05.436 11365M] listening on 10.0.0.8 port 53
[2025-01-01 21:48:05.436 11365M] listening on eth0(#2): 10.0.0.8 port 53
[2025-01-01 21:48:05.437 11365M] listening on 127.0.0.1 port 53
[2025-01-01 21:48:05.437 11365M] listening on lo(#1): 127.0.0.1 port 53
[2025-01-01 21:48:05.439 11365M] FATAL ERROR in dnsmasq core: DBus not available: set HAVE_DBUS in src/config.h
[2025-01-01 21:48:05.446 11365M] ########## FTL terminated after 27ms  (code 1)! ##########

I suspect bc of lacking Dbus support, systemd tries to start up dnsmasq every minute or so and failing ... according to the journal.
The dbus-daemon is running on the VM's I used:

$ pstree
systemd─┬─ModemManager───2*[{ModemManager}]
        ├─NetworkManager───3*[{NetworkManager}]
        ├─2*[agetty]
        ├─cron
        ├─dbus-daemon

Beta v6 seems also to lack the Dbus dependency but at least it starts ... sort of:

$ sudo journalctl --full --follow --no-hostname --unit NetworkManager.service
[..]
Jan 01 22:36:35 ph6c NetworkManager[1021150]: dnsmasq: DBus not available: set HAVE_DBUS in src/config.h
Jan 01 22:36:35 ph6c dnsmasq[1021150]: DBus not available: set HAVE_DBUS in src/config.h
Jan 01 22:36:35 ph6c dnsmasq[1021150]: FAILED to start up
Jan 01 22:36:35 ph6c NetworkManager[1021150]: FTL started!
Jan 01 22:36:35 ph6c NetworkManager[1021136]: <info>  [1735767395.7419] dnsmasq: starting /usr/sbin/dnsmasq
Jan 01 22:36:35 ph6c NetworkManager[1021136]: <warn>  [1735767395.7950] dnsmasq: spawn: dnsmasq process 1021156 exited with error: Configuration problem (1)
Jan 01 22:36:35 ph6c NetworkManager[1021136]: <info>  [1735767395.7954] dnsmasq: starting /usr/sbin/dnsmasq
Jan 01 22:36:35 ph6c NetworkManager[1021136]: <warn>  [1735767395.8394] dnsmasq: spawn: dnsmasq process 1021159 exited with error: Configuration problem (1)
Jan 01 22:36:35 ph6c NetworkManager[1021136]: <info>  [1735767395.8397] dnsmasq: starting /usr/sbin/dnsmasq
Jan 01 22:36:35 ph6c NetworkManager[1021136]: <warn>  [1735767395.8820] dnsmasq: spawn: dnsmasq process 1021160 exited with error: Configuration problem (1)
Jan 01 22:36:35 ph6c NetworkManager[1021136]: <info>  [1735767395.8823] dnsmasq: starting /usr/sbin/dnsmasq
Jan 01 22:36:35 ph6c NetworkManager[1021136]: <warn>  [1735767395.9211] dnsmasq: spawn: dnsmasq process 1021161 exited with error: Configuration problem (1)
Jan 01 22:36:35 ph6c NetworkManager[1021136]: <warn>  [1735767395.9218] dnsmasq[c69b116ba2b44cd0]: dnsmasq dies and gets respawned too quickly. Back off. Something is very wrong
$ pstree -pts $(pidof -s dnsmasq)
systemd(1)───dnsmasq(1021158)─┬─{civetweb-master}(1021168)
                              ├─{civetweb-timer}(1021167)
                              ├─{database}(1021164)
                              ├─{housekeeper}(1021165)
                              ├─{ntp-server4}(1021162)
                              ├─{ntp-server6}(1021163)
                              └─{timer}(1021166)
$ sudo ss -nltup | grep dnsmasq
udp   UNCONN 0      0          127.0.0.1:53        0.0.0.0:*    users:(("dnsmasq",pid=1021158,fd=22))
udp   UNCONN 0      0           10.0.0.7:53        0.0.0.0:*    users:(("dnsmasq",pid=1021158,fd=20))
udp   UNCONN 0      0            0.0.0.0:123       0.0.0.0:*    users:(("dnsmasq",pid=1021158,fd=33))
udp   UNCONN 0      0               [::]:123          [::]:*    users:(("dnsmasq",pid=1021158,fd=29))
tcp   LISTEN 0      200          0.0.0.0:80        0.0.0.0:*    users:(("dnsmasq",pid=1021158,fd=34))
tcp   LISTEN 0      32          10.0.0.7:53        0.0.0.0:*    users:(("dnsmasq",pid=1021158,fd=21))
tcp   LISTEN 0      32         127.0.0.1:53        0.0.0.0:*    users:(("dnsmasq",pid=1021158,fd=23))
tcp   LISTEN 0      200          0.0.0.0:443       0.0.0.0:*    users:(("dnsmasq",pid=1021158,fd=37))
tcp   LISTEN 0      200             [::]:80           [::]:*    users:(("dnsmasq",pid=1021158,fd=36))
tcp   LISTEN 0      200             [::]:443          [::]:*    users:(("dnsmasq",pid=1021158,fd=38))
$ ntpdig -d 10.0.0.7
ntpdig: querying 10.0.0.7 (10.0.0.7)
org t1: eb2037b7.ce85b000 rec t2: eb2037b7.ce91ea78
xmt t3: eb2037b7.cede657b dst t4: eb2037b7.cee5b000
org t1: 1735768375.806727 rec t2: 1735768375.806914
xmt t3: 1735768375.808081 dst t4: 1735768375.808192
rec-org t21: 0.000186  xmt-dst t34: -0.000111
2025-01-01 22:52:55.808081 (+0100) +0.000038 +/- 0.000150 10.0.0.7 s2 no-leap
$ curl -I http://10.0.0.7/admin/
HTTP/1.1 200 OK
[..]
$ dig @127.0.0.1 pi.hole
;; communications error to 127.0.0.1#53: timed out
;; communications error to 127.0.0.1#53: timed out
;; communications error to 127.0.0.1#53: timed out

; <<>> DiG 9.18.28-1~deb12u2-Debian <<>> @127.0.0.1 pi.hole
; (1 server found)
;; global options: +cmd
;; no servers could be reached
$ nc -vzw 5 127.0.0.1 53
Connection to 127.0.0.1 53 port [tcp/*] succeeded!

Also it got disowned from NM for some reason (its running directly onder systemd now) and running as root instead of the nobody or pihole user.

Asking the devs or anyone who knows, is there an easy fix for the Dbus dependency thats used by NM to poll dnsmasq?
Is it a compile options that can be flipped on?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.