# [SOLVED] dhcpd and dnsmasq shut down when wan gets restarted

## Kresp

I'm running gentoo as a home router, and there is one annoying quirk that I'd like to get straightened out:

Wherever I manually restart my wan connection, dnsmasq and dhcpd also restart, leaving lan connections unresponsive.

```

$ sudo rc-config restart net.enp3s0

Restarting init script

 * Unmounting network filesystems ...                                                   [ ok ]

 * Stopping dnsmasq ...                                                                 [ ok ]

 * Stopping dhcpd ...                                                                   [ ok ]

 * Bringing down interface enp3s0

 *   Stopping dhcpcd on enp3s0 ...

sending signal TERM to pid 9919

waiting for pid 9919 to exit                                                            [ ok ]

RTNETLINK answers: No such file or directory

Error talking to the kernel

 * Bringing up interface enp3s0

 *   dhcp ...

 *     Running dhcpcd ...

enp3s0: waiting for carrier

enp3s0: carrier acquired

enp3s0: adding address fe80::d01c:592b:2472:8ed9

DUID

enp3s0: IAID d3:64:c9:a0

enp3s0: soliciting an IPv6 router

enp3s0: rebinding lease of x.x.x.x

enp3s0: probing for an IPv4LL address

enp3s0: DHCP lease expired

enp3s0: soliciting a DHCP lease

enp3s0: offered x.x.x.x from x.x.x.x

enp3s0: probing address x.x.x.x/18

enp3s0: using IPv4LL address 169.254.59.151

enp3s0: adding route to 169.254.0.0/16

enp3s0: adding default route

forked to background, child pid 10650                                                   [ ok ]

 *     received address 169.254.59.151/16                                               [ ok ]

 * Starting dnsmasq ...                                                  [ ok ]

 * Mounting network filesystems ...                                                     [ ok ]

 * Starting dhcpd ...                                                                   [ ok ]

```

Even more problematic is that if wan interface is not plugged anywhere - service for iface does not start back up after "waiting for carrier", leaving both dnsmasq and dhcpd (ans also netmount) down, making the box unreachable for new connections until reboot.

Is this problem with service dependencies? Removing need net from init.d scripts did not seem to help.

```

$ rc-status

Runlevel: default

 lm_sensors                                                                      [  started  ]

 sysklogd                                                                        [  started  ]

 net.lo                                                                          [  started  ]

 iptables                                                                        [  started  ]

 net.br0                                                                         [  started  ]

 net.enp3s0                                                                      [  started  ]

 dnsmasq                                                                         [  started  ]

 sshd                                                                            [  started  ]

 dhcpd                                                                           [  started  ]

 cronie                                                                          [  started  ]

 netmount                                                                        [  started  ]

 local                                                                           [  started  ]

Dynamic Runlevel: hotplugged

Dynamic Runlevel: needed/wanted

 modules-load                                                                    [  started  ]

Dynamic Runlevel: manual

```

enp3s0 is wan connection, br0 - is bridge over few NICs for lan.

```

config_enp3s0="dhcp"

# bridge_br0="enp2s0 enp2s1 enp4s0 enp5s0"

bridge_br0="enp2s0 enp2s1 enp4s0"

config_br0="192.168.100.1 netmask 255.255.255.0"

routes_br0="192.168.0.0/16 via 192.168.100.254"

```

Last edited by Kresp on Wed Aug 16, 2017 1:11 pm; edited 2 times in total

----------

## charles17

 *Kresp wrote:*   

> Is this problem with service dependencies? Removing need net from init.d scripts did not seem to help.
> 
> ```
> 
> $ rc-status
> ...

 

Are you sure you want (or need) to run both dnsmasq and dhcpd together?  

https://wiki.gentoo.org/wiki/Home_Router#DHCP_server

----------

## Kresp

 *charles17 wrote:*   

> 
> 
> Are you sure you want (or need) to run both dnsmasq and dhcpd together?  
> 
> https://wiki.gentoo.org/wiki/Home_Router#DHCP_server

 

Well, I'm trying to get rid of dnsmasq. For now it only serves as nameserver, but I'm going to replace it with bind.

The problem was present even when dnsmasq was doing both name resolution and serving DHCP, without dhcpd.

----------

## Hu

Is there anything interesting in the output of /etc/init.d/dhcpd ineed or /etc/init.d/dhcpd iuse?

----------

## Kresp

 *Hu wrote:*   

> Is there anything interesting in the output of /etc/init.d/dhcpd ineed or /etc/init.d/dhcpd iuse?

 

Yep, both dhcpd and dnsmasq need both interfaces (br0 and enp3s0):

```

$ /etc/init.d/dhcpd ineed

sysfs fsck localmount net.br0 net.enp3s0 

$ /etc/init.d/dhcpd iuse

sysklogd dnsmasq 

$ /etc/init.d/dnsmasq ineed

fsck localmount sysfs net.br0 net.enp3s0 

$ /etc/init.d/dnsmasq iuse

sysklogd 

```

I don't quite get it - net.lo, net.br0 and net.enp3s0 all should provide net service that dhcpd needs, correct?

However, it displays that it only needs two - br0 and enp3s0. But also he needs them at the same time.

```

$ ls -lah /etc/init.d/net.*

lrwxrwxrwx 1 root root  18 Apr 21 12:47 /etc/init.d/net.br0 -> /etc/init.d/net.lo

lrwxrwxrwx 1 root root  18 May  8 10:17 /etc/init.d/net.enp3s0 -> /etc/init.d/net.lo

-rwxr-xr-x 1 root root 19K Apr 13 15:32 /etc/init.d/net.lo

```

----------

## charles17

And even more confusing, netifrc is stopping dhcpd and then  *   Stopping dhcpcd on enp3s0 ... *Kresp wrote:*   

> 
> 
> ```
> 
> $ sudo rc-config restart net.enp3s0
> ...

 

Are you using dhcpd and dhcpcd both or is it a feature of netifrc?

----------

## NeddySeagoon

Kresp,

Its related to the way the network service is defined in /etc/rc.conf

Do you need all interfaces to be up to consider the network service up or just one of them?

If you need them all, then things that depend on the network service will stop or restart when any interface goes down/restarts.

See the comments in  /etc/rc.conf.

----------

## chiefbag

Restart the interface using --nodeps flag

```
/etc/init.d/net.enp3s0 restart --nodeps
```

----------

## Kresp

 *chiefbag wrote:*   

> Restart the interface using --nodeps flag
> 
> 

 

That sounds like a very helpful argument to know.

 *NeddySeagoon wrote:*   

> Kresp,
> 
> Its related to the way the network service is defined in /etc/rc.conf
> 
> Do you need all interfaces to be up to consider the network service up or just one of them?
> ...

 

Thanks, exactly what I need.

----------

