httpd and nfs start before an IP is available (DHCP)
Hi guys,
I'm having a strange issue: my home server is behind my router, which runs DHCP. The server runs some trivial services like httpd (several vhosts, php and all that jazz), nfsd, some virtual desktops, minidlna etc. What happens is that when I boot and try to access a webpage, hosted on my server, I get "Access denied". It disappears if I systemctl restart httpd, until reboot.
Network used to be managed by NetworkManager, but I changed it to systemd-networkd for simplicity. The result is the same.
Digging in the logs, I noticed that systemd reaches targets nss-lookup and network (httpd.service `After` line), but the network interface doesn't have an IP assigned yet - that happens much later. I modified the unit file for httpd.service and changed start After=network.target to After=network-online.target, httpd starts just fine.
I was wondering how come the default httpd unit doesn't wait for a sensible network configuration (not just valid, but sensible, e.g. if there's dhcp involved, wait for a configuration)? Is it that no one runs httpd in a DHCP-controlled environment, or is my DHCP acting up? Should I just make the IP of that box static?
Another one: what does nss-lookup.target actually mean (httpd.service runs After it)? I guess it only waits for systemd-resolved.service, which in turn doesn't care if DHCP is in place and doesn't wait for the DHCP communication.
nfs-server acts exactly the same, the rest seem fine, I can ssh, vnc and stream DLNA after reboot.
Thanks in advance for any comments, I can post some logs if needed...
About this post
- Posted
- Archived
- Score
- 25 · 100% up
- Kind
- Text
- ID
- a9htcb
11 comments
Is
systemd-networkd-wait-online.serviceenabled?https://wiki.archlinux.org/index.php/systemd-networkd#Mount_services_at_boot_fail
yes, I actually changed the After= clause to network-online.target and httpd works just fine.
I'd guess it's because the default and majority case is listening on 0.0.0.0 and pretty much any exception would assume a static IP.
My best guess is that webservers don't typically use DHCP to get an IP address. Servers are usually given a static IP so dhcp doesn't need to work for the service to remain available.
Naw, generally you have some sort of LDAP setup with hostnames and IPs paired to mac addresses. The individual servers use DHCP, and the DHCP/DNS server will assign them their IP. This is how you get centralized management and authentication.
AAMF nginx service file waits for network-online.target, so long with the important server static IP thing...
Maybe. What happens if your DHCP Server goes down?