Skip to content

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...

25 points11 comments
Open on Reddit
About this post
Posted
Archived
Score
25 · 100% up
Kind
Text
ID
a9htcb

Author

7
posts
38
comments
1
media
View profile

11 comments

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.

2 points

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.

1 points

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.

5 points

AAMF nginx service file waits for network-online.target, so long with the important server static IP thing...

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.