Restarting Pi when its the DHCP Server

Hi,

I have pihole runner in a container on my PI with host networking and it is the DHCP server on my network (my router doesn't allow setting DNS so I switched from it being the DHCP server to the Pi).

If I restart my Pi it basically won't do anything until I re-enable the DHCP server on the router at which point I can turn it back off. Before doing this I can see it connect to via wlan/eth0 but it won't respond to pings or ssh and obviously the rest of the network doesn't work properly at this point as it has no DNS or DHCP server.

Assuming there's some misconfiguration like its waiting for its DHCP lease even though it should be the one to give it out?

Thanks,
Perry

Hey !

I'm not sure I understand completely what you're saying, so I'll try to reformulate : Pihole (running on your pi) is the DHCP server for your network. It was previously running on your router, not anymore... unless you have to reboot your pi, so you need to enable DHCP service on your router again to have pihole working again (and you can then disable it from your router). No DNS involved in your story.

If so, it seems to me that the pi network interface serving DHCP (through pihole in a container) does not get an IP address, which would be ironic :smiley: If so, just give it a static IP address (a DHCP server shouldn't be addressed dynamically).

Tell me if you need any help checking or updating this configuration.

1 Like

Gotcha, so edit /etc/dhcpcd.conf ?

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

not sure if domain_name_servers should be itself or the upstream and whether i can omit the ip6_address or not.

I also see I could use a fallback:

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

Might be better as if I happen to put the pi on a different network (say mine is down for some reason) it should try and pick up a lease before assigning itself a static.

Thanks :slight_smile:

There's multiple ways to do it, but this one might not be the best.

See, servers in general should use a static IP address (or a reserved dynamic one) for better availability. That's even more true for a DHCP server. Sure, you could have another DHCP service running elsewhere and configured to address you pi, but it's convoluted, and you'd have to be careful not to overlap DHCP scopes.

What I suggested is stop DHCP client alltogether and set a static IP configuration on you Pi. Here is how you can do it (assuming you're running Debian) :

  • vi /etc/network/interfaces, and then set something like this :
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.15/24
gateway 192.168.1.1 

Check what interface to use with ip l and/or ip a, and set an IP address not already used on your network and not in your DHCP range (or add a reservation so it won't be taken by another device).

  • Disable and stop dhcpcd service : systemctl stop dhcpcd.service && systemctl disable dhcpcd.service, so it won't start on reboot

  • Reload networking : systemctl restart networking.service (or ifdown eth0 && ifup eth0)

The idea is : Don't use your DHCP service to address your DHCP server, as you would do for DNS : Don't set your DNS service IP address / hostname as NS server for your DNS server. You want it to be independant of these critical services you're hosting.

Edit : I think that's your issue, but I'm not sure, so perhaps start by checking your interface configuration before commiting any change.

Edit 2 : Just to be clear, setting a static IP address as fallback from DHCP client configuration would work, but I really don't think you should do it like this. It means your Pi would try to get an IP address from you DHCP server (which would not be running), fail, and then get a static one. Services on your machine (like docker) might not start properly in the meantime, and you'd have to restart them after. If for whatever reason they start, containers might crash and restart if you set them in auto restart.

Thanks for your advice, I'll play around with this :slight_smile:

Maybe I'll have the WLAN fallback just in case :thinking:

Maybe I'll have the WLAN fallback just in case :thinking:

You won't need it ! Having two interfaces addressed on the same network doesn't serve any purpose (without any form of bonding I mean). Worst case scenario, it can mess up with your routes.
You should either not use wifi, or use it to reach another network, if you plan to use your Pi as a router that is.
There are indeed other usecases, but this one (backup interface) is not one I can recommend, not like this.

Have a good one !

I wouldn't disable dhcpcd.
Just use the static configuration lines in your dhcpcd.conf.

dhcpcd will then prefer any static option values over the ones provided via other means.
This would be important if your network has IPv6 connectivity. Without dhcpcd, your host may not be able to pick up IPv6 related information like IPv6 prefixes from your router anymore.

1 Like

While ifupdown comes default OOTB with Pi-OS/Raspbian:

pi@ph5b:~ $ apt policy ifupdown
ifupdown:
  Installed: 0.8.36

And it does what it promises:

pi@ph5b:~ $ apt show ifupdown
[..]
Description: high level tools to configure network interfaces
 This package provides the tools ifup and ifdown which may be used to
 configure (or, respectively, deconfigure) network interfaces based on
 interface definitions in the file /etc/network/interfaces.

It still can be used to configure interfaces.
But preferred is to let the OOTB default network manager called dhcpcd to configure all the networking stuff:

pi@ph5b:~ $ man dhcpcd
[..]
DESCRIPTION
     dhcpcd is an implementation of the DHCP client specified in RFC
     2131.  dhcpcd gets the host information (IP address, routes, etc)
     from a DHCP server and configures the network interface of the ma‐
     chine on which it is running.  dhcpcd then runs the configuration
     script which writes DNS information to resolvconf(8), if available,
     otherwise directly to /etc/resolv.conf.
pi@ph5b:~ $ man dhcpcd.conf
[..]
     static value
             Configures a static value.  If you set ip_address then
             dhcpcd will not attempt to obtain a lease and will just use
             the value for the address with an infinite lease time.  If
             you set ip6_address, dhcpcd will continue auto-configura‐
             tion as normal.

             Here is an example which configures two static address,
             overriding the default IPv4 broadcast address, an IPv4
             router, DNS and disables IPv6 auto-configuration.  You
             could also use the inform6 command here if you wished to
             obtain more information via DHCPv6.  For IPv4, you should
             use the inform ipaddress option instead of setting a static
             address.
                   interface eth0
                   noipv6rs
                   static ip_address=192.168.0.10/24
                   static broadcast_address=192.168.0.63
                   static ip6_address=fd51:42f8:caae:d92e::ff/64
                   static routers=192.168.0.1
                   static domain_name_servers=192.168.0.1
                   fd51:42f8:caae:d92e::1

Here is mine:

pi@ph5b:~ $ tail /etc/dhcpcd.conf
[..]
interface eth0
  static ip_address=10.0.0.4/24
  static routers=10.0.0.1
  static domain_name=home.dehakkelaar.nl
  static domain_name_servers=10.0.0.1

You can apply any changes by running:

sudo service dhcpcd restart

EDIT: And check journals:

pi@ph5b:~ $ journalctl -u dhcpcd
[..]
Jun 21 23:55:08 ph5b dhcpcd[4133]: eth0: using static address 10.0.0.4/24
Jun 21 23:55:08 ph5b dhcpcd[4133]: eth0: adding route to 10.0.0.0/24
Jun 21 23:55:08 ph5b dhcpcd[4133]: eth0: adding default route via 10.0.0.1
Jun 21 23:55:08 ph5b dhcpcd[4147]: eth0: soliciting an IPv6 router
Jun 21 23:55:08 ph5b dhcpcd[4133]: forked to background, child pid 4147
Jun 21 23:55:08 ph5b systemd[1]: Started DHCP Client Daemon.
Jun 21 23:55:20 ph5b dhcpcd[4147]: eth0: no IPv6 Routers available
1 Like