# Timed DNS queries, block DNS based on time

**URL:** <https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495>\
**Category:** Feature Requests\
**Created:** [June 3, 2017, 8:07am UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495 "2017-06-03T08:07:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![davebuchanan](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@davebuchanan](https://discourse.pi-hole.net/u/davebuchanan)\
**Post date:** [June 3, 2017, 8:07am UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/1 "2017-06-03T08:07:46Z")

</div>

Hi pi-hole  
Firstly aplogies if I'm not doing this correctly  
Title timed DNS queries  
Block DNS based on time

We have broadband which is limited during the day, and unlimited at night  
We currently block apple update servers all the time  
Would be helpful to have a special list call it a grey or yellow list  
Which would block always except for certain times

I would propose having a general time setting and allowing domains to be turned on /off on the fly

I am a developer so would be happy to help implement , I have a number of pis to test on, plus a Turris omnia router.

Dave

---

<div class="post-metadata">

**Author:** ![SunderRaj](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@SunderRaj](https://discourse.pi-hole.net/u/SunderRaj)\
**Post date:** [June 6, 2017, 8:06am UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/2 "2017-06-06T08:06:36Z")

</div>

> [@davebuchanan](#):
>
> Block DNS based on time

I have not implemented this feature as such but I believe that you could use xinetd (--libwrap) and allow incoming UDP/TCP calls based on time and block others. Then, dnsmasq will be used only during the allowed time period.

---

<div class="post-metadata">

**Author:** ![MrD](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/mrd/32/980_2.png) [@MrD](https://discourse.pi-hole.net/u/MrD)\
**Post date:** [June 6, 2017, 9:07am UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/3 "2017-06-06T09:07:03Z")

</div>

Much simpler: You can install a `cron` job that adds the corresponding domains (you can specify as many as you like in one call) at time X and removes them again at time Y.

How about that?

Example:

```auto
# m h dom mon dow command
# Block server.apple.com at 8AM
  0 8 * * * pihole -b server.apple.com
# Unblock server.apple.com at 8PM
  0 20 * * * pihole -b -d server.apple.com

```

---

<div class="post-metadata">

**Author:** ![SunderRaj](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@SunderRaj](https://discourse.pi-hole.net/u/SunderRaj)\
**Post date:** [June 6, 2017, 10:58am UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/4 "2017-06-06T10:58:48Z")

</div>

> [@MrD](#):
>
> Much simpler: You can install a cron job

My - potential - solution relates to stop and prevent use of dnsmasq services after certain time completely. Hence it is not relevant to the poster's message. Based on your answer, I saw my misunderstanding.

---

<div class="post-metadata">

**Author:** ![StrangerHereMyself](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/0ea827/32.png) [@StrangerHereMyself](https://discourse.pi-hole.net/u/StrangerHereMyself)\
**Post date:** [June 9, 2017, 7:46pm UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/5 "2017-06-09T19:46:16Z")

</div>

There may be a solution depending on your router.  
Some routers (e.g. Netgear DEVG 2020) offer some rudimentary blocking of Domains + the option to block on a schedule.

You could try a cascaded setup

- Use Pihole as DHCP Server

- Setup Pihole to use your Router as upstream DNS Server

- on your Router specify upstream DNS Server (e.g. google DNS or use ISP provided)

- specify the domains you'd like to block

- setup a blocking schedule

---

<div class="post-metadata">

**Author:** ![avocette](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/avocette/32/2498_2.png) [@avocette](https://discourse.pi-hole.net/u/avocette)\
**Post date:** [October 20, 2018, 5:50am UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/6 "2018-10-20T05:50:38Z")

</div>

Hi,

I've noticed I'm more focused when some website are unavailable (reddit, youtube, etc..)

For this I use on Firefox LeechBlock : [https://addons.mozilla.org/en-US/firefox/addon/leechblock/](https://addons.mozilla.org/en-US/firefox/addon/leechblock/)

Or Mac OS app Selfcontrol : [https://selfcontrolapp.com/](https://selfcontrolapp.com/)

I thought it could be a nice new feature to Pi-Hole to integrate this process.

Having an extra independent blocklist that you can activate or deactivate manually or with a schedule.

---

<div class="post-metadata">

**Author:** ![Coro](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/coro/32/15424_2.png) [@Coro](https://discourse.pi-hole.net/u/Coro)\
**Post date:** [June 30, 2020, 2:10pm UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/7 "2020-06-30T14:10:32Z")

</div>

Note that this is trivial with group management. You can simply add a group with all the domains you want to block and keep it disabled. Now, prepare a cron job to enable/disable this group at the times you want. This can conveniently do this for an entire set of domains which stays comfortably manageable through the web page of Pi-hole.

---

<div class="post-metadata">

**Author:** ![yubiuser](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/yubiuser/32/12100_2.png) [@yubiuser](https://discourse.pi-hole.net/u/yubiuser)\
**Post date:** [June 30, 2020, 2:15pm UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/8 "2020-06-30T14:15:28Z")

</div>

> [@Coro](#):
>
> Note that this is trivial with group management.

Good advice. For those for whom this is not trivial, see here

> [@Activate group with cron](https://discourse.pi-hole.net/t/activate-group-with-cron/32660):
>
> Hello, I'm looking for a way to activate a group from 9 a.m. to 6 p.m. and have it deactivated from 6:01 p.m. to 8:59 a.m. with school at home I want to block social media during school hours. Thank you in advance for your help.

---

<div class="post-metadata">

**Author:** ![stefanu](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/f14d63/32.png) [@stefanu](https://discourse.pi-hole.net/u/stefanu)\
**Post date:** [October 21, 2020, 7:10am UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/9 "2020-10-21T07:10:12Z")

</div>

For the exact same reasons described in the solution post (block access to anything else but the school activities during a certain period), it would be nice to be able to more easily define a ruleset for such behavior.

Maybe something like this; rules may be matched sequentially; first one that matches provides the action; then global allow/block lists may apply.

```auto
# Start End Source Action Pattern
# school computers
08:00 12:00 192.168.0.100 Allow (\.|^)google\.com$
08:00 12:00 192.168.0.100 Deny *

# computer not restricted
00:00 23:59 192.168.0.199 Allow *

#general restrictions
18:00 22:00 192.168.0.0/24 Allow (\.|^)youtube\.com$
18:00 23:59 192.168.0.0/24 Allow (\.|^)netflix\.com$

00:00 23:59 192.168.0.0/24 Allow *

```

This may avoid complex setup and in avoiding complexity one avoids potential errors.

Another related feature could be redirection to a more friendly "block" page instead of seeing the DNS browser error.

---

<div class="post-metadata">

**Author:** ![Ltek](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/ltek/32/24624_2.png) [@Ltek](https://discourse.pi-hole.net/u/Ltek)\
**Post date:** [April 7, 2021, 3:22pm UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/10 "2021-04-07T15:22:02Z")

</div>

We need to have this in the native UI (without hacks).

It could be a few basic features added and we would be there. Like...

"Apply Blacklist to Group - during time frame"  
-- only allows specific sites be contacted, perfect for home school so older kids who need larger freedom to do research, etc but stop them from going to YouTube or game sites during school hours, or on dedicated 'school devices'

"Block all Group activity - during time frame"  
-- no internet allowed, perfect for limiting kids device use and home school

"Apply Whitelist to Group - during time frame"  
-- only allows specific sites be contacted, perfect for home school

---

<div class="post-metadata">

**Author:** ![DanSchaper](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/danschaper/32/91_2.png) [@DanSchaper](https://discourse.pi-hole.net/u/DanSchaper)\
**Post date:** [April 7, 2021, 4:24pm UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/11 "2021-04-07T16:24:58Z")

</div>

> [@Ltek](#):
>
> We need to have this in the native UI (without hacks).

Sponsorships for features you require are acceptable.

---

<div class="post-metadata">

**Author:** ![treq](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/t/a587f6/32.png) [@treq](https://discourse.pi-hole.net/u/treq)\
**Post date:** [May 24, 2025, 3:11pm UTC](https://discourse.pi-hole.net/t/timed-dns-queries-block-dns-based-on-time/3495/13 "2025-05-24T15:11:51Z")

</div>

This is an old thread, but I have a very specific use case for scheduling pi-hole blocking. I run an Airbnb out of my home. As part of it I enable a guest network on my home network just for the guests. The router doesn't have a way to specify specific DNS just for the guest network, so when I have guests, I typically disable blocking during their stay so they don't have issues using their google/FB/whatever services. But I have to do it manually every time. If there was a way to schedule it so the pinhole disables blocking on the weekends when the guests typically book, it would help me not forget to turn off or back on the blocking.
