dnsmasq can't bind listen-address

677 views Asked by At

I tried to setup hostapd and dnsmasq to braodcast a WiFi from a Raspberry Pi 3. I only want to broadcast the WiFi so devices can connect to a http-server running on the Raspberry, no ethernet bridge is required.

I installed hostapd and dnsmasq and configured them as followed:

dhcpcd.conf

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# Most distributions have NTP support.
#option ntp_servers

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private

#denyinterfaces wlan0

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.5/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.5
#static domain_name_servers=192.168.0.5

interface wlan0
allow-hotplug wlan0
#iface wlan0 inet static 
static ip_address=192.168.0.5/24
nohook wpa_supplicant
#netmask 255.255.255.0
#network 192.168.0.0
#broadcast 192.168.0.255
# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

As you can see I already tried different options using denyinterfaces and other things I found in different tutorials, but none did work.

hostapd.conf

interface=wlan0
driver=nl80211
ssid=****
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=****
rsn_pairwise=CCMP

dnsmasq.conf

interface=wlan0
listen-address=192.168.0.5
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.0.25,192.168.0.150,255.255.255.0,240h

Now I got two problems:

  1. hostapd does not run on startup although I did define the daemon_conf and it is working when I run hostapd /path/to/config
  2. My main problem, dnsmasq is not running. When I try to start the service, it crashes with an error cannot bind listen-address.

service dnsmasq status

● dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server
   Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled; vendor preset: 
   Active: failed (Result: exit-code) since Tue 2022-03-29 12:58:34 CEST; 17min 
  Process: 483 ExecStartPre=/usr/sbin/dnsmasq --test (code=exited, status=0/SUCC
  Process: 491 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=2

Mär 29 12:58:33 raspberrypitop systemd[1]: Starting dnsmasq - A lightweight DHCP
Mär 29 12:58:33 raspberrypitop dnsmasq[483]: dnsmasq: Syntaxprüfung OK.
Mär 29 12:58:34 raspberrypitop dnsmasq[491]: dnsmasq: Konnte Empfangs-Socket für
Mär 29 12:58:34 raspberrypitop dnsmasq[491]: Konnte Empfangs-Socket für 192.168.
Mär 29 12:58:34 raspberrypitop dnsmasq[491]: Start fehlgeschlagen
Mär 29 12:58:34 raspberrypitop systemd[1]: dnsmasq.service: Control process exit
Mär 29 12:58:34 raspberrypitop systemd[1]: dnsmasq.service: Failed with result '
Mär 29 12:58:34 raspberrypitop systemd[1]: Failed to start dnsmasq - A lightweig
lines 1-14/14 (END)

I guess I messed up the configuration somehow, but since this is something new for me and there are many different tutorials for several different kinds of OSs and OS versions, it's very hard to understand, what is going wrong.

1

There are 1 answers

0
AracKnight On

Ok, figured it out myself. In my case hostapd not starting automatically was actually causing the second issue, since it prevented the wlan0 interface from coming up. I had to sudo systemctl unmask hostapd and reboot. dnsmasq would still not start since it tried to start before hostapd was finished setting everything up, even if told to wait for hostapd.service. So i edited the systemd/dnsmasq.service config and added

[service]
restart=always
retry=2

So it tries to restart every 2sec until hostapd has done it's job and so it all is working.