Resolving “dnsmasq: failed to create listening socket: Address already in use” Error on RHEL-based Systems


2 views

When dnsmasq fails to start with the "Address already in use" error, it indicates a port conflict where another service is already bound to the ports dnsmasq needs (typically 53 for DNS and 67 for DHCP). In Scientific Linux 6.3 (RHEL-based systems), common culprits include:

# Check for services using port 53 (DNS)
sudo netstat -tulnp | grep ':53'

# Check for services using port 67 (DHCP)
sudo netstat -tulnp | grep ':67'

The netstat output reveals xinetd is handling TFTP (port 69) while other services might be occupying DNS/DHCP ports:

# Common conflicting services:
- named (bind)
- dhcpd
- systemd-resolved (on newer systems)
- xinetd managed services

Option 1: Stop the Conflicting Service

# For named (bind):
sudo service named stop
sudo chkconfig named off

# For dhcpd:
sudo service dhcpd stop
sudo chkconfig dhcpd off

# For xinetd (if managing DNS/DHCP):
sudo service xinetd stop
sudo chkconfig xinetd off

Option 2: Configure dnsmasq to Use Alternative Ports

Add these lines to /etc/dnsmasq.conf:

# Use non-standard ports
port=5353
dhcp-alternate-port=6768,6868

Option 3: Clean Up Stale Processes

# Find and kill old dnsmasq instances
ps aux | grep dnsmasq
sudo kill -9 [pid]

# Check for zombie sockets
sudo lsof -i :53
sudo lsof -i :67

After implementing changes:

sudo service dnsmasq restart
sudo netstat -tulnp | grep dnsmasq

Expected output should show dnsmasq listening on configured ports:

udp        0      0 0.0.0.0:53           0.0.0.0:*            1234/dnsmasq
udp        0      0 0.0.0.0:67           0.0.0.0:*            1234/dnsmasq

For RHEL-based systems using chkconfig:

sudo chkconfig dnsmasq on
sudo service dnsmasq start

For modern systems with systemd:

sudo systemctl enable dnsmasq
sudo systemctl start dnsmasq

The error message indicates dnsmasq is unable to bind to its required ports because they're already occupied. Let's analyze the specific ports involved:

# Check currently used ports
sudo netstat -tulnp | grep -E '53|67|69'

From your netstat output, we can see xinetd is already using port 69 (TFTP):

udp        0      0 0.0.0.0:69                  0.0.0.0:*                               5110/xinetd

This conflicts with dnsmasq's tftp functionality. Additionally, check for DNS (port 53) and DHCP (port 67) conflicts.

Here are possible solutions:

# Option 1: Stop conflicting services
sudo service xinetd stop
sudo chkconfig xinetd off

# Option 2: Configure dnsmasq to use different ports (in dnsmasq.conf)
port=5353  # Alternative DNS port
dhcp-alternate-port=6768,6868  # Alternative DHCP ports

Here's a modified configuration that avoids common port conflicts:

# /etc/dnsmasq.conf
interface=eth1
no-dhcp-interface=eth0
domain=hpclab
expand-hosts
dhcp-range=10.0.2.51,10.0.2.100,static
dhcp-option=42,0.0.0.0
dhcp-boot=pxelinux.0
enable-tftp
tftp-root=/var/lib/tftpboot
dhcp-host=08:00:27:69:73:7A,ws04,10.0.2.51

# Avoid port conflicts
port=5353
dhcp-alternate-port=6768

After making changes:

# Restart dnsmasq
sudo service dnsmasq restart

# Verify it's running
sudo netstat -tulnp | grep dnsmasq
sudo tail -f /var/log/dnsmasq.log

If using custom ports, update firewall rules:

# For Scientific Linux 6.3
sudo iptables -I INPUT -p udp --dport 5353 -j ACCEPT
sudo iptables -I INPUT -p udp --dport 6768 -j ACCEPT
sudo service iptables save