[solved] dnsmasq cannot start dhcp server on centos 7

Issues related to configuring your network
Post Reply
amm123
Posts: 3
Joined: 2017/10/24 22:56:51

[solved] dnsmasq cannot start dhcp server on centos 7

Post by amm123 » 2017/10/24 23:02:28

Hello,


I am trying to setup a dnsmasq on my centos 7 system. every time dnsmasq come up it say in the log that it cannot bind dhcp server socket.

Code: Select all

Oct 24 14:47:16 centos1 dnsmasq[1200]: started, version 2.76 cachesize 150
Oct 24 14:47:16 centos1 dnsmasq[1200]: compile time options: IPv6 GNU-getopt DBus no-i18n IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth no-DNSSEC loop-detect inotify
Oct 24 14:47:16 centos1 dnsmasq-dhcp[1200]: DHCP, IP range 192.168.2.100 -- 192.168.2.199, lease time 2d
Oct 24 14:47:16 centos1 dnsmasq-tftp[1200]: TFTP root is /var/lib/tftpboot
Oct 24 14:47:16 centos1 dnsmasq[1200]: using nameserver 8.8.4.4#53
Oct 24 14:47:16 centos1 dnsmasq[1200]: reading /etc/resolv.conf
Oct 24 14:47:16 centos1 dnsmasq[1200]: using nameserver 8.8.4.4#53
Oct 24 14:47:16 centos1 dnsmasq[1200]: using nameserver 192.168.2.1#53
Oct 24 14:47:16 centos1 dnsmasq[1200]: read /etc/hosts - 2 addresses
Oct 24 14:47:17 centos1 dnsmasq[1200]: reading /etc/resolv.conf
Oct 24 14:47:17 centos1 dnsmasq[1200]: using nameserver 8.8.4.4#53
Oct 24 14:47:17 centos1 dnsmasq[1200]: using nameserver 192.168.2.1#53
[b]**Oct 24 14:47:20 centos1 dnsmasq[1387]: failed to bind DHCP server socket: Address already in use**[/b]

I have checked the port with netstats and all of the port seems okay to me (they all attached to dnsmasq):

Code: Select all

[root@centos1 log]# netstat -anlp | grep -w LISTEN
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd
tcp        0      0 0.0.0.0:53              0.0.0.0:*               LISTEN      1200/dnsmasq
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1206/sshd
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1203/cupsd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1481/master
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd
tcp6       0      0 :::21                   :::*                    LISTEN      1213/vsftpd
tcp6       0      0 :::53                   :::*                    LISTEN      1200/dnsmasq
tcp6       0      0 :::22                   :::*                    LISTEN      1206/sshd
tcp6       0      0 ::1:631                 :::*                    LISTEN      1203/cupsd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1481/master
[root@centos1 log]# netstat -anup
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
udp        0      0 0.0.0.0:36235           0.0.0.0:*                           982/dhclient
udp        0      0 0.0.0.0:4011            0.0.0.0:*                           1200/dnsmasq
udp        0      0 0.0.0.0:53              0.0.0.0:*                           1200/dnsmasq
udp        0      0 0.0.0.0:60476           0.0.0.0:*                           643/avahi-daemon: r
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1200/dnsmasq
udp        0      0 0.0.0.0:68              0.0.0.0:*                           982/dhclient
udp        0      0 0.0.0.0:69              0.0.0.0:*                           1200/dnsmasq
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           643/avahi-daemon: r
udp        0      0 127.0.0.1:323           0.0.0.0:*                           659/chronyd
udp6       0      0 :::53                   :::*                                1200/dnsmasq
udp6       0      0 :::69                   :::*                                1200/dnsmasq
udp6       0      0 :::49922                :::*                                982/dhclient
udp6       0      0 ::1:323                 :::*                                659/chronyd

also here is my /etc/dnsmasq.conf
interface=enp0s3,lo
#bind-interfaces
domain=centos.home
# DHCP range-leases
dhcp-range= 192.168.2.100,192.168.2.199,255.255.255.0,48h
# PXE
dhcp-boot=pxelinux.0,pxeserver,192.168.2.199
# Gateway
dhcp-option=3,192.168.2.1
# DNS
dhcp-option=6,192.168.2.1,8.8.8.8
server=8.8.4.4
# Broadcast Address
dhcp-option=28,10.0.0.255
dhcp-host=08:00:27:c3:a2:df,192.168.2.199
# NTP Server
#dhcp-option=42,0.0.0.0
pxe-prompt="Press F8 for menu.", 60
pxe-service=x86PC, "Install CentOS 7 from network server 192.168.2.199", pxelinux
enable-tftp
tftp-root=/var/lib/tftpboot

what I am missing? :roll:

thanks.
Last edited by amm123 on 2017/10/28 02:36:50, edited 1 time in total.

Whoever
Posts: 1357
Joined: 2013/09/06 03:12:10

Re: dnsmasq cannot start dhcp server on centos 7

Post by Whoever » 2017/10/25 03:54:53

You might get more help on the CentOS 7 forums.

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: dnsmasq cannot start dhcp server on centos 7

Post by TrevorH » 2017/10/25 10:46:08

Yes, wrong forum section - moved to the correct one.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

amm123
Posts: 3
Joined: 2017/10/24 22:56:51

Re: dnsmasq cannot start dhcp server on centos 7

Post by amm123 » 2017/10/25 16:51:19

today I have seen two different error, I just did a reboot no changes on the config files were applied.

the first one is:

Code: Select all

Oct 25 11:36:26 centos1 libvirtd: 2017-10-25 16:36:26.487+0000: 1288: error : virCommandWait:2572 : internal error: Child process (VIR_BRIDGE_NAME=virbr0 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper) unexpected exit status 2:
Oct 25 11:36:26 centos1 libvirtd: dnsmasq: failed to bind DHCP server socket: Address already in use
regarding this one I feel it has to do with the fact that my host is running on a virtual machine using virtualBox

the second one:

Code: Select all

Oct 25 11:41:48 centos1 dnsmasq[10937]: cannot open or create lease file /var/lib/dnsmasq/dnsmasq.leases: Permission denied
if someone need more information, just let me know what you need. I have to fix this asap.

thanks again.

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: dnsmasq cannot start dhcp server on centos 7

Post by jlehtone » 2017/10/25 19:19:57

Libvirtd, yes, does start by default, and does start a dnsmasq instance to cater its "Default network". That instance, however, is limited to that "virtual subnet".

Having both libvirtd and VirtualBox?


The NetworkManager can be configured to start a dnsmasq (as caching nameserver, I presume), but that is not a default.


I did notice interface=enp0s3,lo
man page:
Dnsmasq automatically adds the loopback (local) interface to the list of interfaces to use when the --interface option is used.
although that probably is not relevant? Or is it?

Websearch with the initial error message brings up stuff like:
https://forums.fedoraforum.org/showthread.php?t=304269


Side note: netstat is deprecated. ss is the current tool.
ss -tulp

For example:

Code: Select all

# ss -4tulpn | grep \"d
udp    UNCONN     0      0      192.168.122.1:53                    *:*                   users:(("dnsmasq",pid=1301,fd=5))
udp    UNCONN     0      0      *  %virbr0:67                    *:*                   users:(("dnsmasq",pid=1301,fd=3))
udp    UNCONN     0      0         *:68                    *:*                   users:(("dhclient",pid=3188,fd=6))
udp    UNCONN     0      0         *:21750                 *:*                   users:(("dhclient",pid=3188,fd=20))
tcp    LISTEN     0      5      192.168.122.1:53                    *:*                   users:(("dnsmasq",pid=1301,fd=6))
The dnsmasq is by libvirtd, the dhclient fetches IP for the host from external DHCP server.

You can check

Code: Select all

systemctl status dnsmasq
journalctl -u dnsmasq
Stop "your" dnsmasq. See what is still running/listening.

amm123
Posts: 3
Joined: 2017/10/24 22:56:51

Re: dnsmasq cannot start dhcp server on centos 7

Post by amm123 » 2017/10/27 04:39:51

Thanks jlehtone,for your response.

to be honest I don't know what libvirtd is. I just have windows laptop with vbox which has a centos image.

I did stop dnsmasq and checked all the port, but all the port that dnsmasq use were gone. anyway I think this idea put me on the right track.
so I tried to check the port status and I found that the fire wall was blocking all of dnsmasq connection :x and actually that was it. I just disabled the firewall on those port and it started working fine finally.

for the record here is what I did:
I check the port that I need from the netstat command above and open all port on the firewall

Code: Select all

firewall-cmd --add-service=ftp --permanent  	
firewall-cmd --add-service=dns --permanent  	
firewall-cmd --add-service=dhcp --permanent 
firewall-cmd --add-port=69/udp --permanent  
firewall-cmd --add-port=4011/udp --permanent
firewall-cmd --reload
Thanks jlehtone for trying to help. :D

Post Reply