I have a CentOS server with isc dhcpd and apache 2 webserver running. A couple of minutes ago I have tried to restart apache:
/etc/init.d/httpd restart
Restart has failed with:
Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Apache was complaining that the 80 port has been already taken. I've executed
netstat -ntap
to see who is listening on 80 port. And it was dhcpd. Since before restart apache and dhcpd were running simultaneously I guess what has happened was that just after apache was off, dhcp has noticed that 80 port is free and started listening it. Does anybody know in what cases dhcpd would do it and why? I've tried to reproduce that a couple of times but with no luck.
DHCP protocol uses 67 and 68 port numbers.
dhcpd
cannot out of the blue start listening onport 80 'because it is free'. And one more thing, using
t
option innetstat
you lists only TCP protocol. How come you see dhcp server which is using UDP protocol ? You have probably misreadnetstat
output.That's because after apache exits the socket may still remain open lingering in the background until associated buffers are drained of data. The time between killing and starting the apache process may be lower than the time needed to drain the buffers on the listening socket and a new process will not be able to bind to the listening address getting a new socket until the old one is really closed. About the dhcpd part, you surely misread the netstat output if we're talking about a normal centos installation and normal people using it.
While I agree completely with you that this is impossible, it does it all the time for me.
and then:
Yep, tcp port 80 is being camped on by dhcpd. so anyway now we reset to original state:
Attempts immediately after this work properly, but I can reproduce this every time as long as the server has been running for a while.
I believe that I found the cause of this issue. We utilize a PHP application which maintains the DHCP hosts config file and a change in this file will cause PHP to execute code to restart the DHCP service. When this code is executed, it spawns a process to restart the DHCP process. This spawned process inherits the Apache ports which are "queued". Once the Apache process is stopped, the DHCP process now owns port 80. You can fix this issue by either disabling ipv6 entirely on the server or re-configuring Apache to only utilize ipv4.