# [systemd] Force network to wait for DHCP

## wichtounet

Hi, 

I'm using systemd-networkd to configure my interfaces: 

```
[Match]

Name=enp3s0

[Network]

DHCP=v4
```

It works quite well except that at boot, some services are not waiting for DHCP to finish. For instances my NFS-mounted directories and nginx fail because there is no network at the time they boot. 

Is there a way to force systemd-networkd to wait for DHCP or another target to wait for in the other service files ?

Thanks

----------

## charles17

No idea if it would help solving your problem, as I am not too familiar with systemd.

For dhcpcd with OpenRC I've created an article on https://wiki.gentoo.org/wiki/Network_management_using_DHCPCD and I think a similar solution should be possible also for systemd.

If so, you might possibly be able to go completely without systemd-networkd?

----------

## wichtounet

 *charles17 wrote:*   

> No idea if it would help solving your problem, as I am not too familiar with systemd.
> 
> For dhcpcd with OpenRC I've created an article on https://wiki.gentoo.org/wiki/Network_management_using_DHCPCD and I think a similar solution should be possible also for systemd.
> 
> If so, you might possibly be able to go completely without systemd-networkd?

 

Thanks, but that doesn't really help. I would like to avoid using another DHCP client. The network works, but it just doesn't wait for DHCP. 

I've seen now that services should wait for 

{After,Wants}=network-online.target

but what about NFS mount for instance ?

----------

## UberLord

systemd has a something-wait-online service you can use.

----------

## wichtounet

 *UberLord wrote:*   

> systemd has a something-wait-online service you can use.

 

Yes, I saw that. 

I tried to override sshd.service with a sshd.service.d folder and add Wants/After=network-online.target, but the result is the same, it doesn't wait for dhcp to obtain an address. network is marked as online directly when network-online starts  :Sad: 

----------

## wichtounet

I found a solution  :Smile: 

There is systemd-networkd-wait-online service that can be enabled and that will cause network-online to wait. Without that, network-online.target seems to be useless. 

Moreover, there seems to be a problem in systemd-215, cause I had to upgrade to systemd-216 for this to work. Now, I have overriden all the necessary service files and targets and everything works  :Smile: 

----------

