Pi-hole in a dynamic ip router?

So if you would like to setup everything for home network in a one ‘box’ pi-hole, wireguard/openvpn, access point and so-on. Is it possible if you have dynamic ip address from your isp provider. Can you configure Pi-hole to work with it somehow?

In my case. I have ethernet cable with DHCP lease from ISP.

I have tried to learn about theultimatehomeserver stuff and Pi-hole and so on. But I have not found a solution to this. I would like to avoid containers. But that’s just me. I have run Pi-Hole in Raspberry inside my network. but I would like to but everything in a one machine and have also to run firewall, access point and so that I can get rid of my cheapo ISP (Huawei) access point.

Ps. I asked some questions regarding Wireguard setup on another thread and it kinda seems that it would make things easier with the other software if I could run everything at router.

Majority of people have their network behind their own router, and don’t connect their devices to ISP cable modem directly.

Their own router is then the only thing connected to ISP cable gateway.

With respect to what IP you get from your ISP, it shouldn’t affect pihole, but may affect how you access any services hosted at home while you’re somewhere else.

generally, ISPs will either do:

a) publicly routable ipv4 on gateway, home lan 192.168.x.y/24, and DMZ / port forwarding
b) cgnat ipv4 - no port forwarding
c) modem mode/passthrough (your router gets public routable ipv4 from the ISP and your modem/gateway just passes everything through).

Neither option affects pihole specifically - they affect how you access/reach everything hosted on your lan while not at home.

Can you elaborate how you’ve setup pihole and where are you stumbling, what have you tested so far?


Drop pi-hole, use blocky (GitHub - 0xERR0R/blocky: Fast and lightweight DNS proxy as ad-blocker for local network with many features) or adguard-home (AdGuard Home | Network-wide software for any OS: Windows, macOS, Linux) and you’ll have pretty much the same functionality.

Unfortunately not that many distros provides packages for either project yet but there are also binaries provided by upstream.

I was trying to keep question short and unfortunately left important detail out.

I’m struggling with the gateway setup as its also given by the ISP DHCP lease. Pihole wants to know both gateway and IP at setup stage.

I think that I can setup Pihole IP to wlan interface IP from where I run my access point (hostapd). But the gateway?

Thanks for the tip. I been mostly happy with Pihole with old setup. But now that I’m trying to imrove setup I’m sort of lost.

Why I suggested counterparts as it’s not really “portable”/package friendly.
You can add block/whitelists to blocky just as you do with pi-hole etc.

You might be able to replace the ISP Huawei access point; you want to call your ISP provider and ask if you can return the devices you have now with a modem, and then you can pick any router and access point you want. However, as I mentioned in the other post you made, I don’t think replacing the ISP-provided devices will make goals any easier to accomplish; it will just give you different options.

I found the above sentence very confusing. Are you trying to say you have an ethernet cable throughout your home and are leasing your DHCP server from your ISP?

Sorry, not my native language :slight_smile: I live in apartment building where ISP provides fiber line to buildings electrical room/closet where it is converted to ethernet and run to individiual apartments. One line to each apartment. This line can be used with customer own devices and it gives simple ipv4 DHCP lease. I have used own Zyxel access point with no issues previously.

My goal is to simplify setup so that I would have only one device handling internet access. Now I have two Huawei and Raspberry. If either of them brakes then I have no internet. I would like to have just one device. So that it’s easy to replace in case of problems. If I setup Raspberry (later on something powerful) then in case it stops working it is easy to replace with basic access point / router that has same wlan SSID:s and such to get basic network functionality. It easy to explain to others who live here; “Take out one box and put in another box and connect wires”. And then you have basic connectivity albeit missing pihole, pivpn and all the other goodness.

This is what I have. But It’s just standard access point router and customer can use their own device as gateway. This is what I’m intending to do.

Basically I connect Raspberry ethernet to public (dynamic) ipv4. And now what is confusing is how to setup Pihole in this case. If I have dhcp lease I also have dynamic route. And I have no idea how to configure pi hole with it.

I’ll try to elaborate. Here is my goal:

Pi-hole setup1, interface to wlan:
Kuvakaappaus - 2022-07-25 11-57-38

Pi-hole setup2, IP address and gateway. I would change IP address to but what should I put to gateway?
Kuvakaappaus - 2022-07-25 12-00-06

ok, Sami_m, I now understand how your network connects to the internet.

@sami_m I will give you a link that should give you your public IP address. Don’t share this IP address with anyone. This IP address is the gateway address. https://whatismyipaddress.com/ If you have any problems, let us know @risk, and I can probably figure them out.

But what happens next time I get new DHCP address from ISP? I don’t want to reconfigure pi-hole everytime my external address changes. Is there more dynamic solution available?

That website I linked should give you your public ip4 and ip6 address. Those addresses should never change unless your ISP is using CGNAT, which is a strong possibility considering the shortage of IP addresses and the fact you are living in an apartment building. It is easy to find out if your ISP is using CGNAT; I will give you another link with instructions on finding out. How Sami_m finds out if his ISP is CGNAT using a Windows 10 Machine.

I just used google with the search term setup pi-hole dynamic public IP address, and a bunch of websites came up which explained how to setup pi-hole when your ISP uses an active IP address.

So I got this figured out :slight_smile: Thanks for all your pointers and tips and sorry for taking your time. I should have tried to look under the hood before asking.

I started to think that why does Pi-Hole actually need that gateway specified. It should not be needed as its already set by OS itself. So I started to look into source code (bash script) of the installer with my pretty boor bash understanding. And tried to figure out where the gateway was actually needed. Luckily install script does not seem overly complicated. Variable IPv4gw is used in installer as IP4 gateway and its only used in writing /etc/dhcpcd.conf file. So I ran the setup and set bogus number as gateway and edited /etc/dhcpcd.conf manually to correct state where gateway comes from dhcp lease. It seems to work but I need to do more testing.

Installer source: https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh

1 Like

@sami_m I am glad you finally got everything figured out. So happy to help. It didn’t take me long to help you. Any time you have a question, ask; if I don’t know the answer, I know someone who does.

1 Like