Enforce Safe Search on Google, YouTube, Bing

Enforce safe search on Google, YouTube, and Bing without a HTTP proxy. Instead, override DNS lookups, resolving to strict search server IP addresses.

Motivation

I wanted to enforce safe search on my home network. OpenDNS offers FamilyShield which blocks adult sites but they do not block explicit search results from Google, YouTube or Bing. Instead, OpenDNS support page details how to enforce safe search on Google, YouTube, and Bing. Therefore, I needed to figure a workaround.

The solution for Google, YouTube, and Bing

The concept

When performing lookup on www.google.com or any of its supported domains, DNS server resolves to the regular non-safe search version.

Instead of sending lookup requests to DNS servers, resolve to safe search IP addresses as below. Note that these are subject to change, correct as at 11th September 2017:

Safe Search ServiceCNAMEIP
Googleforcesafesearch.google.com216.239.38.120
YouTube Strictrestrict.youtube.com216.239.38.120
YouTube Moderaterestrictmoderate.youtube.com216.239.38.119
Bingstrict.bing.com204.79.197.220

Do not use these domains in web browsers directly. They are to be used only in DNS records. If you browse to forcesafesearch.google.com, you will land on a 404 page.

Service providers generally recommend referring to CNAME instead of IP as the latter may change. If you do not have an option, just refer to the IP address. When it breaks, you will know about it eventually.

For OpenWRT users, jump to Using OpenWRT section below.
Alternatively, to use hosts file option, the solution is right below.

Using hosts file

The hosts file should be available on most (if not all) operating systems. Administrator rights are required to edit this, which is a good thing as non-admins cannot tamper with it. i.e. parents with admin rights can pre-configure these for their kids where the latter do not have admin rights.

On Windows, it can be found at C:\Windows\System32\drivers\etc\hosts.
On Unix, Linux, Raspberry Pi Raspbian, it can be found at /etc/hosts.

The format of the file is <IP address> <host name>.
Note that the two fields are separated by space(s) or tab(s).

To capture domain names from Google supported domains, I used regular expression:

\.([\w\.]+)(?:\s)?

Then substitute with:

cname=$1,forcesafesearch.google.com\ncname=www.$1,forcesafesearch.google.com\n

$1 denotes capture group 1.
Prefix it with www because that is absent in the capture.

If you are not into RegEx, that is fine. Here is the result:

cname=google.com,forcesafesearch.google.com
cname=www.google.com,forcesafesearch.google.com
cname=google.ad,forcesafesearch.google.com
cname=www.google.ad,forcesafesearch.google.com
cname=google.ae,forcesafesearch.google.com
cname=www.google.ae,forcesafesearch.google.com
cname=google.com.af,forcesafesearch.google.com
cname=www.google.com.af,forcesafesearch.google.com
cname=google.com.ag,forcesafesearch.google.com
cname=www.google.com.ag,forcesafesearch.google.com
cname=google.com.ai,forcesafesearch.google.com
cname=www.google.com.ai,forcesafesearch.google.com
cname=google.al,forcesafesearch.google.com
cname=www.google.al,forcesafesearch.google.com
cname=google.am,forcesafesearch.google.com
cname=www.google.am,forcesafesearch.google.com
cname=google.co.ao,forcesafesearch.google.com
cname=www.google.co.ao,forcesafesearch.google.com
cname=google.com.ar,forcesafesearch.google.com
cname=www.google.com.ar,forcesafesearch.google.com
cname=google.as,forcesafesearch.google.com
cname=www.google.as,forcesafesearch.google.com
cname=google.at,forcesafesearch.google.com
cname=www.google.at,forcesafesearch.google.com
cname=google.com.au,forcesafesearch.google.com
cname=www.google.com.au,forcesafesearch.google.com
cname=google.az,forcesafesearch.google.com
cname=www.google.az,forcesafesearch.google.com
cname=google.ba,forcesafesearch.google.com
cname=www.google.ba,forcesafesearch.google.com
cname=google.com.bd,forcesafesearch.google.com
cname=www.google.com.bd,forcesafesearch.google.com
cname=google.be,forcesafesearch.google.com
cname=www.google.be,forcesafesearch.google.com
cname=google.bf,forcesafesearch.google.com
cname=www.google.bf,forcesafesearch.google.com
cname=google.bg,forcesafesearch.google.com
cname=www.google.bg,forcesafesearch.google.com
cname=google.com.bh,forcesafesearch.google.com
cname=www.google.com.bh,forcesafesearch.google.com
cname=google.bi,forcesafesearch.google.com
cname=www.google.bi,forcesafesearch.google.com
cname=google.bj,forcesafesearch.google.com
cname=www.google.bj,forcesafesearch.google.com
cname=google.com.bn,forcesafesearch.google.com
cname=www.google.com.bn,forcesafesearch.google.com
cname=google.com.bo,forcesafesearch.google.com
cname=www.google.com.bo,forcesafesearch.google.com
cname=google.com.br,forcesafesearch.google.com
cname=www.google.com.br,forcesafesearch.google.com
cname=google.bs,forcesafesearch.google.com
cname=www.google.bs,forcesafesearch.google.com
cname=google.bt,forcesafesearch.google.com
cname=www.google.bt,forcesafesearch.google.com
cname=google.co.bw,forcesafesearch.google.com
cname=www.google.co.bw,forcesafesearch.google.com
cname=google.by,forcesafesearch.google.com
cname=www.google.by,forcesafesearch.google.com
cname=google.com.bz,forcesafesearch.google.com
cname=www.google.com.bz,forcesafesearch.google.com
cname=google.ca,forcesafesearch.google.com
cname=www.google.ca,forcesafesearch.google.com
cname=google.cd,forcesafesearch.google.com
cname=www.google.cd,forcesafesearch.google.com
cname=google.cf,forcesafesearch.google.com
cname=www.google.cf,forcesafesearch.google.com
cname=google.cg,forcesafesearch.google.com
cname=www.google.cg,forcesafesearch.google.com
cname=google.ch,forcesafesearch.google.com
cname=www.google.ch,forcesafesearch.google.com
cname=google.ci,forcesafesearch.google.com
cname=www.google.ci,forcesafesearch.google.com
cname=google.co.ck,forcesafesearch.google.com
cname=www.google.co.ck,forcesafesearch.google.com
cname=google.cl,forcesafesearch.google.com
cname=www.google.cl,forcesafesearch.google.com
cname=google.cm,forcesafesearch.google.com
cname=www.google.cm,forcesafesearch.google.com
cname=google.cn,forcesafesearch.google.com
cname=www.google.cn,forcesafesearch.google.com
cname=google.com.co,forcesafesearch.google.com
cname=www.google.com.co,forcesafesearch.google.com
cname=google.co.cr,forcesafesearch.google.com
cname=www.google.co.cr,forcesafesearch.google.com
cname=google.com.cu,forcesafesearch.google.com
cname=www.google.com.cu,forcesafesearch.google.com
cname=google.cv,forcesafesearch.google.com
cname=www.google.cv,forcesafesearch.google.com
cname=google.com.cy,forcesafesearch.google.com
cname=www.google.com.cy,forcesafesearch.google.com
cname=google.cz,forcesafesearch.google.com
cname=www.google.cz,forcesafesearch.google.com
cname=google.de,forcesafesearch.google.com
cname=www.google.de,forcesafesearch.google.com
cname=google.dj,forcesafesearch.google.com
cname=www.google.dj,forcesafesearch.google.com
cname=google.dk,forcesafesearch.google.com
cname=www.google.dk,forcesafesearch.google.com
cname=google.dm,forcesafesearch.google.com
cname=www.google.dm,forcesafesearch.google.com
cname=google.com.do,forcesafesearch.google.com
cname=www.google.com.do,forcesafesearch.google.com
cname=google.dz,forcesafesearch.google.com
cname=www.google.dz,forcesafesearch.google.com
cname=google.com.ec,forcesafesearch.google.com
cname=www.google.com.ec,forcesafesearch.google.com
cname=google.ee,forcesafesearch.google.com
cname=www.google.ee,forcesafesearch.google.com
cname=google.com.eg,forcesafesearch.google.com
cname=www.google.com.eg,forcesafesearch.google.com
cname=google.es,forcesafesearch.google.com
cname=www.google.es,forcesafesearch.google.com
cname=google.com.et,forcesafesearch.google.com
cname=www.google.com.et,forcesafesearch.google.com
cname=google.fi,forcesafesearch.google.com
cname=www.google.fi,forcesafesearch.google.com
cname=google.com.fj,forcesafesearch.google.com
cname=www.google.com.fj,forcesafesearch.google.com
cname=google.fm,forcesafesearch.google.com
cname=www.google.fm,forcesafesearch.google.com
cname=google.fr,forcesafesearch.google.com
cname=www.google.fr,forcesafesearch.google.com
cname=google.ga,forcesafesearch.google.com
cname=www.google.ga,forcesafesearch.google.com
cname=google.ge,forcesafesearch.google.com
cname=www.google.ge,forcesafesearch.google.com
cname=google.gg,forcesafesearch.google.com
cname=www.google.gg,forcesafesearch.google.com
cname=google.com.gh,forcesafesearch.google.com
cname=www.google.com.gh,forcesafesearch.google.com
cname=google.com.gi,forcesafesearch.google.com
cname=www.google.com.gi,forcesafesearch.google.com
cname=google.gl,forcesafesearch.google.com
cname=www.google.gl,forcesafesearch.google.com
cname=google.gm,forcesafesearch.google.com
cname=www.google.gm,forcesafesearch.google.com
cname=google.gp,forcesafesearch.google.com
cname=www.google.gp,forcesafesearch.google.com
cname=google.gr,forcesafesearch.google.com
cname=www.google.gr,forcesafesearch.google.com
cname=google.com.gt,forcesafesearch.google.com
cname=www.google.com.gt,forcesafesearch.google.com
cname=google.gy,forcesafesearch.google.com
cname=www.google.gy,forcesafesearch.google.com
cname=google.com.hk,forcesafesearch.google.com
cname=www.google.com.hk,forcesafesearch.google.com
cname=google.hn,forcesafesearch.google.com
cname=www.google.hn,forcesafesearch.google.com
cname=google.hr,forcesafesearch.google.com
cname=www.google.hr,forcesafesearch.google.com
cname=google.ht,forcesafesearch.google.com
cname=www.google.ht,forcesafesearch.google.com
cname=google.hu,forcesafesearch.google.com
cname=www.google.hu,forcesafesearch.google.com
cname=google.co.id,forcesafesearch.google.com
cname=www.google.co.id,forcesafesearch.google.com
cname=google.ie,forcesafesearch.google.com
cname=www.google.ie,forcesafesearch.google.com
cname=google.co.il,forcesafesearch.google.com
cname=www.google.co.il,forcesafesearch.google.com
cname=google.im,forcesafesearch.google.com
cname=www.google.im,forcesafesearch.google.com
cname=google.co.in,forcesafesearch.google.com
cname=www.google.co.in,forcesafesearch.google.com
cname=google.iq,forcesafesearch.google.com
cname=www.google.iq,forcesafesearch.google.com
cname=google.is,forcesafesearch.google.com
cname=www.google.is,forcesafesearch.google.com
cname=google.it,forcesafesearch.google.com
cname=www.google.it,forcesafesearch.google.com
cname=google.je,forcesafesearch.google.com
cname=www.google.je,forcesafesearch.google.com
cname=google.com.jm,forcesafesearch.google.com
cname=www.google.com.jm,forcesafesearch.google.com
cname=google.jo,forcesafesearch.google.com
cname=www.google.jo,forcesafesearch.google.com
cname=google.co.jp,forcesafesearch.google.com
cname=www.google.co.jp,forcesafesearch.google.com
cname=google.co.ke,forcesafesearch.google.com
cname=www.google.co.ke,forcesafesearch.google.com
cname=google.com.kh,forcesafesearch.google.com
cname=www.google.com.kh,forcesafesearch.google.com
cname=google.ki,forcesafesearch.google.com
cname=www.google.ki,forcesafesearch.google.com
cname=google.kg,forcesafesearch.google.com
cname=www.google.kg,forcesafesearch.google.com
cname=google.co.kr,forcesafesearch.google.com
cname=www.google.co.kr,forcesafesearch.google.com
cname=google.com.kw,forcesafesearch.google.com
cname=www.google.com.kw,forcesafesearch.google.com
cname=google.kz,forcesafesearch.google.com
cname=www.google.kz,forcesafesearch.google.com
cname=google.la,forcesafesearch.google.com
cname=www.google.la,forcesafesearch.google.com
cname=google.com.lb,forcesafesearch.google.com
cname=www.google.com.lb,forcesafesearch.google.com
cname=google.li,forcesafesearch.google.com
cname=www.google.li,forcesafesearch.google.com
cname=google.lk,forcesafesearch.google.com
cname=www.google.lk,forcesafesearch.google.com
cname=google.co.ls,forcesafesearch.google.com
cname=www.google.co.ls,forcesafesearch.google.com
cname=google.lt,forcesafesearch.google.com
cname=www.google.lt,forcesafesearch.google.com
cname=google.lu,forcesafesearch.google.com
cname=www.google.lu,forcesafesearch.google.com
cname=google.lv,forcesafesearch.google.com
cname=www.google.lv,forcesafesearch.google.com
cname=google.com.ly,forcesafesearch.google.com
cname=www.google.com.ly,forcesafesearch.google.com
cname=google.co.ma,forcesafesearch.google.com
cname=www.google.co.ma,forcesafesearch.google.com
cname=google.md,forcesafesearch.google.com
cname=www.google.md,forcesafesearch.google.com
cname=google.me,forcesafesearch.google.com
cname=www.google.me,forcesafesearch.google.com
cname=google.mg,forcesafesearch.google.com
cname=www.google.mg,forcesafesearch.google.com
cname=google.mk,forcesafesearch.google.com
cname=www.google.mk,forcesafesearch.google.com
cname=google.ml,forcesafesearch.google.com
cname=www.google.ml,forcesafesearch.google.com
cname=google.com.mm,forcesafesearch.google.com
cname=www.google.com.mm,forcesafesearch.google.com
cname=google.mn,forcesafesearch.google.com
cname=www.google.mn,forcesafesearch.google.com
cname=google.ms,forcesafesearch.google.com
cname=www.google.ms,forcesafesearch.google.com
cname=google.com.mt,forcesafesearch.google.com
cname=www.google.com.mt,forcesafesearch.google.com
cname=google.mu,forcesafesearch.google.com
cname=www.google.mu,forcesafesearch.google.com
cname=google.mv,forcesafesearch.google.com
cname=www.google.mv,forcesafesearch.google.com
cname=google.mw,forcesafesearch.google.com
cname=www.google.mw,forcesafesearch.google.com
cname=google.com.mx,forcesafesearch.google.com
cname=www.google.com.mx,forcesafesearch.google.com
cname=google.com.my,forcesafesearch.google.com
cname=www.google.com.my,forcesafesearch.google.com
cname=google.co.mz,forcesafesearch.google.com
cname=www.google.co.mz,forcesafesearch.google.com
cname=google.com.na,forcesafesearch.google.com
cname=www.google.com.na,forcesafesearch.google.com
cname=google.com.nf,forcesafesearch.google.com
cname=www.google.com.nf,forcesafesearch.google.com
cname=google.com.ng,forcesafesearch.google.com
cname=www.google.com.ng,forcesafesearch.google.com
cname=google.com.ni,forcesafesearch.google.com
cname=www.google.com.ni,forcesafesearch.google.com
cname=google.ne,forcesafesearch.google.com
cname=www.google.ne,forcesafesearch.google.com
cname=google.nl,forcesafesearch.google.com
cname=www.google.nl,forcesafesearch.google.com
cname=google.no,forcesafesearch.google.com
cname=www.google.no,forcesafesearch.google.com
cname=google.com.np,forcesafesearch.google.com
cname=www.google.com.np,forcesafesearch.google.com
cname=google.nr,forcesafesearch.google.com
cname=www.google.nr,forcesafesearch.google.com
cname=google.nu,forcesafesearch.google.com
cname=www.google.nu,forcesafesearch.google.com
cname=google.co.nz,forcesafesearch.google.com
cname=www.google.co.nz,forcesafesearch.google.com
cname=google.com.om,forcesafesearch.google.com
cname=www.google.com.om,forcesafesearch.google.com
cname=google.com.pa,forcesafesearch.google.com
cname=www.google.com.pa,forcesafesearch.google.com
cname=google.com.pe,forcesafesearch.google.com
cname=www.google.com.pe,forcesafesearch.google.com
cname=google.com.pg,forcesafesearch.google.com
cname=www.google.com.pg,forcesafesearch.google.com
cname=google.com.ph,forcesafesearch.google.com
cname=www.google.com.ph,forcesafesearch.google.com
cname=google.com.pk,forcesafesearch.google.com
cname=www.google.com.pk,forcesafesearch.google.com
cname=google.pl,forcesafesearch.google.com
cname=www.google.pl,forcesafesearch.google.com
cname=google.pn,forcesafesearch.google.com
cname=www.google.pn,forcesafesearch.google.com
cname=google.com.pr,forcesafesearch.google.com
cname=www.google.com.pr,forcesafesearch.google.com
cname=google.ps,forcesafesearch.google.com
cname=www.google.ps,forcesafesearch.google.com
cname=google.pt,forcesafesearch.google.com
cname=www.google.pt,forcesafesearch.google.com
cname=google.com.py,forcesafesearch.google.com
cname=www.google.com.py,forcesafesearch.google.com
cname=google.com.qa,forcesafesearch.google.com
cname=www.google.com.qa,forcesafesearch.google.com
cname=google.ro,forcesafesearch.google.com
cname=www.google.ro,forcesafesearch.google.com
cname=google.ru,forcesafesearch.google.com
cname=www.google.ru,forcesafesearch.google.com
cname=google.rw,forcesafesearch.google.com
cname=www.google.rw,forcesafesearch.google.com
cname=google.com.sa,forcesafesearch.google.com
cname=www.google.com.sa,forcesafesearch.google.com
cname=google.com.sb,forcesafesearch.google.com
cname=www.google.com.sb,forcesafesearch.google.com
cname=google.sc,forcesafesearch.google.com
cname=www.google.sc,forcesafesearch.google.com
cname=google.se,forcesafesearch.google.com
cname=www.google.se,forcesafesearch.google.com
cname=google.com.sg,forcesafesearch.google.com
cname=www.google.com.sg,forcesafesearch.google.com
cname=google.sh,forcesafesearch.google.com
cname=www.google.sh,forcesafesearch.google.com
cname=google.si,forcesafesearch.google.com
cname=www.google.si,forcesafesearch.google.com
cname=google.sk,forcesafesearch.google.com
cname=www.google.sk,forcesafesearch.google.com
cname=google.com.sl,forcesafesearch.google.com
cname=www.google.com.sl,forcesafesearch.google.com
cname=google.sn,forcesafesearch.google.com
cname=www.google.sn,forcesafesearch.google.com
cname=google.so,forcesafesearch.google.com
cname=www.google.so,forcesafesearch.google.com
cname=google.sm,forcesafesearch.google.com
cname=www.google.sm,forcesafesearch.google.com
cname=google.sr,forcesafesearch.google.com
cname=www.google.sr,forcesafesearch.google.com
cname=google.st,forcesafesearch.google.com
cname=www.google.st,forcesafesearch.google.com
cname=google.com.sv,forcesafesearch.google.com
cname=www.google.com.sv,forcesafesearch.google.com
cname=google.td,forcesafesearch.google.com
cname=www.google.td,forcesafesearch.google.com
cname=google.tg,forcesafesearch.google.com
cname=www.google.tg,forcesafesearch.google.com
cname=google.co.th,forcesafesearch.google.com
cname=www.google.co.th,forcesafesearch.google.com
cname=google.com.tj,forcesafesearch.google.com
cname=www.google.com.tj,forcesafesearch.google.com
cname=google.tk,forcesafesearch.google.com
cname=www.google.tk,forcesafesearch.google.com
cname=google.tl,forcesafesearch.google.com
cname=www.google.tl,forcesafesearch.google.com
cname=google.tm,forcesafesearch.google.com
cname=www.google.tm,forcesafesearch.google.com
cname=google.tn,forcesafesearch.google.com
cname=www.google.tn,forcesafesearch.google.com
cname=google.to,forcesafesearch.google.com
cname=www.google.to,forcesafesearch.google.com
cname=google.com.tr,forcesafesearch.google.com
cname=www.google.com.tr,forcesafesearch.google.com
cname=google.tt,forcesafesearch.google.com
cname=www.google.tt,forcesafesearch.google.com
cname=google.com.tw,forcesafesearch.google.com
cname=www.google.com.tw,forcesafesearch.google.com
cname=google.co.tz,forcesafesearch.google.com
cname=www.google.co.tz,forcesafesearch.google.com
cname=google.com.ua,forcesafesearch.google.com
cname=www.google.com.ua,forcesafesearch.google.com
cname=google.co.ug,forcesafesearch.google.com
cname=www.google.co.ug,forcesafesearch.google.com
cname=google.co.uk,forcesafesearch.google.com
cname=www.google.co.uk,forcesafesearch.google.com
cname=google.com.uy,forcesafesearch.google.com
cname=www.google.com.uy,forcesafesearch.google.com
cname=google.co.uz,forcesafesearch.google.com
cname=www.google.co.uz,forcesafesearch.google.com
cname=google.com.vc,forcesafesearch.google.com
cname=www.google.com.vc,forcesafesearch.google.com
cname=google.co.ve,forcesafesearch.google.com
cname=www.google.co.ve,forcesafesearch.google.com
cname=google.vg,forcesafesearch.google.com
cname=www.google.vg,forcesafesearch.google.com
cname=google.co.vi,forcesafesearch.google.com
cname=www.google.co.vi,forcesafesearch.google.com
cname=google.com.vn,forcesafesearch.google.com
cname=www.google.com.vn,forcesafesearch.google.com
cname=google.vu,forcesafesearch.google.com
cname=www.google.vu,forcesafesearch.google.com
cname=google.ws,forcesafesearch.google.com
cname=www.google.ws,forcesafesearch.google.com
cname=google.rs,forcesafesearch.google.com
cname=www.google.rs,forcesafesearch.google.com
cname=google.co.za,forcesafesearch.google.com
cname=www.google.co.za,forcesafesearch.google.com
cname=google.co.zm,forcesafesearch.google.com
cname=www.google.co.zm,forcesafesearch.google.com
cname=google.co.zw,forcesafesearch.google.com
cname=www.google.co.zw,forcesafesearch.google.com
cname=google.cat,forcesafesearch.google.com
cname=www.google.cat,forcesafesearch.google.com

Copy the the above into your hosts file. Then flush your DNS cache.
On Windows, ipconfig /flushdns.
Your browser may have its own DNS cache, restart it.

To test it, simply browse to Google and type in explicit words to see if adult content appears.

For YouTube, append the following into your hosts file:

216.239.38.120 youtube.com www.youtube.com
216.239.38.120 m.youtube.com
216.239.38.120 youtubei.googleapis.com
216.239.38.120 youtube.googleapis.com
216.239.38.120 youtube-nocookie.com www.youtube-nocookie.com

Use 216.239.38.119 if you prefer moderate restrictions.

For Bing, append the following into your hosts file:

204.79.197.220 bing.com www.bing.com

Using OpenWRT

I am using dnsmasq-full version 2.73-1 on OpenWRT Chaos Calmer 15.05.1 instead of the default dnsmasq. The solution described below should also work with the latter. Otherwise, please install the full version.

Edit /etc/dnsmasq.conf and add lines formatted as cname=<target>,<cname>.
To produce that format using Regex:

cname=www$1,forcesafesearch.google.com\n

If you want just the output, here it is:

# Google safe search
cname=google.com,www.google.com,forcesafesearch.google.com
cname=google.ad,www.google.ad,forcesafesearch.google.com
cname=google.ae,www.google.ae,forcesafesearch.google.com
cname=google.com.af,www.google.com.af,forcesafesearch.google.com
cname=google.com.ag,www.google.com.ag,forcesafesearch.google.com
cname=google.com.ai,www.google.com.ai,forcesafesearch.google.com
cname=google.al,www.google.al,forcesafesearch.google.com
cname=google.am,www.google.am,forcesafesearch.google.com
cname=google.co.ao,www.google.co.ao,forcesafesearch.google.com
cname=google.com.ar,www.google.com.ar,forcesafesearch.google.com
cname=google.as,www.google.as,forcesafesearch.google.com
cname=google.at,www.google.at,forcesafesearch.google.com
cname=google.com.au,www.google.com.au,forcesafesearch.google.com
cname=google.az,www.google.az,forcesafesearch.google.com
cname=google.ba,www.google.ba,forcesafesearch.google.com
cname=google.com.bd,www.google.com.bd,forcesafesearch.google.com
cname=google.be,www.google.be,forcesafesearch.google.com
cname=google.bf,www.google.bf,forcesafesearch.google.com
cname=google.bg,www.google.bg,forcesafesearch.google.com
cname=google.com.bh,www.google.com.bh,forcesafesearch.google.com
cname=google.bi,www.google.bi,forcesafesearch.google.com
cname=google.bj,www.google.bj,forcesafesearch.google.com
cname=google.com.bn,www.google.com.bn,forcesafesearch.google.com
cname=google.com.bo,www.google.com.bo,forcesafesearch.google.com
cname=google.com.br,www.google.com.br,forcesafesearch.google.com
cname=google.bs,www.google.bs,forcesafesearch.google.com
cname=google.bt,www.google.bt,forcesafesearch.google.com
cname=google.co.bw,www.google.co.bw,forcesafesearch.google.com
cname=google.by,www.google.by,forcesafesearch.google.com
cname=google.com.bz,www.google.com.bz,forcesafesearch.google.com
cname=google.ca,www.google.ca,forcesafesearch.google.com
cname=google.cd,www.google.cd,forcesafesearch.google.com
cname=google.cf,www.google.cf,forcesafesearch.google.com
cname=google.cg,www.google.cg,forcesafesearch.google.com
cname=google.ch,www.google.ch,forcesafesearch.google.com
cname=google.ci,www.google.ci,forcesafesearch.google.com
cname=google.co.ck,www.google.co.ck,forcesafesearch.google.com
cname=google.cl,www.google.cl,forcesafesearch.google.com
cname=google.cm,www.google.cm,forcesafesearch.google.com
cname=google.cn,www.google.cn,forcesafesearch.google.com
cname=google.com.co,www.google.com.co,forcesafesearch.google.com
cname=google.co.cr,www.google.co.cr,forcesafesearch.google.com
cname=google.com.cu,www.google.com.cu,forcesafesearch.google.com
cname=google.cv,www.google.cv,forcesafesearch.google.com
cname=google.com.cy,www.google.com.cy,forcesafesearch.google.com
cname=google.cz,www.google.cz,forcesafesearch.google.com
cname=google.de,www.google.de,forcesafesearch.google.com
cname=google.dj,www.google.dj,forcesafesearch.google.com
cname=google.dk,www.google.dk,forcesafesearch.google.com
cname=google.dm,www.google.dm,forcesafesearch.google.com
cname=google.com.do,www.google.com.do,forcesafesearch.google.com
cname=google.dz,www.google.dz,forcesafesearch.google.com
cname=google.com.ec,www.google.com.ec,forcesafesearch.google.com
cname=google.ee,www.google.ee,forcesafesearch.google.com
cname=google.com.eg,www.google.com.eg,forcesafesearch.google.com
cname=google.es,www.google.es,forcesafesearch.google.com
cname=google.com.et,www.google.com.et,forcesafesearch.google.com
cname=google.fi,www.google.fi,forcesafesearch.google.com
cname=google.com.fj,www.google.com.fj,forcesafesearch.google.com
cname=google.fm,www.google.fm,forcesafesearch.google.com
cname=google.fr,www.google.fr,forcesafesearch.google.com
cname=google.ga,www.google.ga,forcesafesearch.google.com
cname=google.ge,www.google.ge,forcesafesearch.google.com
cname=google.gg,www.google.gg,forcesafesearch.google.com
cname=google.com.gh,www.google.com.gh,forcesafesearch.google.com
cname=google.com.gi,www.google.com.gi,forcesafesearch.google.com
cname=google.gl,www.google.gl,forcesafesearch.google.com
cname=google.gm,www.google.gm,forcesafesearch.google.com
cname=google.gp,www.google.gp,forcesafesearch.google.com
cname=google.gr,www.google.gr,forcesafesearch.google.com
cname=google.com.gt,www.google.com.gt,forcesafesearch.google.com
cname=google.gy,www.google.gy,forcesafesearch.google.com
cname=google.com.hk,www.google.com.hk,forcesafesearch.google.com
cname=google.hn,www.google.hn,forcesafesearch.google.com
cname=google.hr,www.google.hr,forcesafesearch.google.com
cname=google.ht,www.google.ht,forcesafesearch.google.com
cname=google.hu,www.google.hu,forcesafesearch.google.com
cname=google.co.id,www.google.co.id,forcesafesearch.google.com
cname=google.ie,www.google.ie,forcesafesearch.google.com
cname=google.co.il,www.google.co.il,forcesafesearch.google.com
cname=google.im,www.google.im,forcesafesearch.google.com
cname=google.co.in,www.google.co.in,forcesafesearch.google.com
cname=google.iq,www.google.iq,forcesafesearch.google.com
cname=google.is,www.google.is,forcesafesearch.google.com
cname=google.it,www.google.it,forcesafesearch.google.com
cname=google.je,www.google.je,forcesafesearch.google.com
cname=google.com.jm,www.google.com.jm,forcesafesearch.google.com
cname=google.jo,www.google.jo,forcesafesearch.google.com
cname=google.co.jp,www.google.co.jp,forcesafesearch.google.com
cname=google.co.ke,www.google.co.ke,forcesafesearch.google.com
cname=google.com.kh,www.google.com.kh,forcesafesearch.google.com
cname=google.ki,www.google.ki,forcesafesearch.google.com
cname=google.kg,www.google.kg,forcesafesearch.google.com
cname=google.co.kr,www.google.co.kr,forcesafesearch.google.com
cname=google.com.kw,www.google.com.kw,forcesafesearch.google.com
cname=google.kz,www.google.kz,forcesafesearch.google.com
cname=google.la,www.google.la,forcesafesearch.google.com
cname=google.com.lb,www.google.com.lb,forcesafesearch.google.com
cname=google.li,www.google.li,forcesafesearch.google.com
cname=google.lk,www.google.lk,forcesafesearch.google.com
cname=google.co.ls,www.google.co.ls,forcesafesearch.google.com
cname=google.lt,www.google.lt,forcesafesearch.google.com
cname=google.lu,www.google.lu,forcesafesearch.google.com
cname=google.lv,www.google.lv,forcesafesearch.google.com
cname=google.com.ly,www.google.com.ly,forcesafesearch.google.com
cname=google.co.ma,www.google.co.ma,forcesafesearch.google.com
cname=google.md,www.google.md,forcesafesearch.google.com
cname=google.me,www.google.me,forcesafesearch.google.com
cname=google.mg,www.google.mg,forcesafesearch.google.com
cname=google.mk,www.google.mk,forcesafesearch.google.com
cname=google.ml,www.google.ml,forcesafesearch.google.com
cname=google.com.mm,www.google.com.mm,forcesafesearch.google.com
cname=google.mn,www.google.mn,forcesafesearch.google.com
cname=google.ms,www.google.ms,forcesafesearch.google.com
cname=google.com.mt,www.google.com.mt,forcesafesearch.google.com
cname=google.mu,www.google.mu,forcesafesearch.google.com
cname=google.mv,www.google.mv,forcesafesearch.google.com
cname=google.mw,www.google.mw,forcesafesearch.google.com
cname=google.com.mx,www.google.com.mx,forcesafesearch.google.com
cname=google.com.my,www.google.com.my,forcesafesearch.google.com
cname=google.co.mz,www.google.co.mz,forcesafesearch.google.com
cname=google.com.na,www.google.com.na,forcesafesearch.google.com
cname=google.com.nf,www.google.com.nf,forcesafesearch.google.com
cname=google.com.ng,www.google.com.ng,forcesafesearch.google.com
cname=google.com.ni,www.google.com.ni,forcesafesearch.google.com
cname=google.ne,www.google.ne,forcesafesearch.google.com
cname=google.nl,www.google.nl,forcesafesearch.google.com
cname=google.no,www.google.no,forcesafesearch.google.com
cname=google.com.np,www.google.com.np,forcesafesearch.google.com
cname=google.nr,www.google.nr,forcesafesearch.google.com
cname=google.nu,www.google.nu,forcesafesearch.google.com
cname=google.co.nz,www.google.co.nz,forcesafesearch.google.com
cname=google.com.om,www.google.com.om,forcesafesearch.google.com
cname=google.com.pa,www.google.com.pa,forcesafesearch.google.com
cname=google.com.pe,www.google.com.pe,forcesafesearch.google.com
cname=google.com.pg,www.google.com.pg,forcesafesearch.google.com
cname=google.com.ph,www.google.com.ph,forcesafesearch.google.com
cname=google.com.pk,www.google.com.pk,forcesafesearch.google.com
cname=google.pl,www.google.pl,forcesafesearch.google.com
cname=google.pn,www.google.pn,forcesafesearch.google.com
cname=google.com.pr,www.google.com.pr,forcesafesearch.google.com
cname=google.ps,www.google.ps,forcesafesearch.google.com
cname=google.pt,www.google.pt,forcesafesearch.google.com
cname=google.com.py,www.google.com.py,forcesafesearch.google.com
cname=google.com.qa,www.google.com.qa,forcesafesearch.google.com
cname=google.ro,www.google.ro,forcesafesearch.google.com
cname=google.ru,www.google.ru,forcesafesearch.google.com
cname=google.rw,www.google.rw,forcesafesearch.google.com
cname=google.com.sa,www.google.com.sa,forcesafesearch.google.com
cname=google.com.sb,www.google.com.sb,forcesafesearch.google.com
cname=google.sc,www.google.sc,forcesafesearch.google.com
cname=google.se,www.google.se,forcesafesearch.google.com
cname=google.com.sg,www.google.com.sg,forcesafesearch.google.com
cname=google.sh,www.google.sh,forcesafesearch.google.com
cname=google.si,www.google.si,forcesafesearch.google.com
cname=google.sk,www.google.sk,forcesafesearch.google.com
cname=google.com.sl,www.google.com.sl,forcesafesearch.google.com
cname=google.sn,www.google.sn,forcesafesearch.google.com
cname=google.so,www.google.so,forcesafesearch.google.com
cname=google.sm,www.google.sm,forcesafesearch.google.com
cname=google.sr,www.google.sr,forcesafesearch.google.com
cname=google.st,www.google.st,forcesafesearch.google.com
cname=google.com.sv,www.google.com.sv,forcesafesearch.google.com
cname=google.td,www.google.td,forcesafesearch.google.com
cname=google.tg,www.google.tg,forcesafesearch.google.com
cname=google.co.th,www.google.co.th,forcesafesearch.google.com
cname=google.com.tj,www.google.com.tj,forcesafesearch.google.com
cname=google.tk,www.google.tk,forcesafesearch.google.com
cname=google.tl,www.google.tl,forcesafesearch.google.com
cname=google.tm,www.google.tm,forcesafesearch.google.com
cname=google.tn,www.google.tn,forcesafesearch.google.com
cname=google.to,www.google.to,forcesafesearch.google.com
cname=google.com.tr,www.google.com.tr,forcesafesearch.google.com
cname=google.tt,www.google.tt,forcesafesearch.google.com
cname=google.com.tw,www.google.com.tw,forcesafesearch.google.com
cname=google.co.tz,www.google.co.tz,forcesafesearch.google.com
cname=google.com.ua,www.google.com.ua,forcesafesearch.google.com
cname=google.co.ug,www.google.co.ug,forcesafesearch.google.com
cname=google.co.uk,www.google.co.uk,forcesafesearch.google.com
cname=google.com.uy,www.google.com.uy,forcesafesearch.google.com
cname=google.co.uz,www.google.co.uz,forcesafesearch.google.com
cname=google.com.vc,www.google.com.vc,forcesafesearch.google.com
cname=google.co.ve,www.google.co.ve,forcesafesearch.google.com
cname=google.vg,www.google.vg,forcesafesearch.google.com
cname=google.co.vi,www.google.co.vi,forcesafesearch.google.com
cname=google.com.vn,www.google.com.vn,forcesafesearch.google.com
cname=google.vu,www.google.vu,forcesafesearch.google.com
cname=google.ws,www.google.ws,forcesafesearch.google.com
cname=google.rs,www.google.rs,forcesafesearch.google.com
cname=google.co.za,www.google.co.za,forcesafesearch.google.com
cname=google.co.zm,www.google.co.zm,forcesafesearch.google.com
cname=google.co.zw,www.google.co.zw,forcesafesearch.google.com
cname=google.cat,www.google.cat,forcesafesearch.google.com

# YouTube restricted
cname=youtube.com,restrict.youtube.com
cname=www.youtube.com,restrict.youtube.com
cname=m.youtube.com,restrict.youtube.com
cname=youtubei.googleapis.com,restrict.youtube.com
cname=youtube.googleapis.com,restrict.youtube.com
cname=youtube-nocookie.com,restrict.youtube.com
cname=www.youtube-nocookie.com,restrict.youtube.com

# Bing safe search
cname=bing.com,strict.bing.com
cname=www.bing.com,strict.bing.com

Dnsmasq CNAMEs must reference a domain that exists in the hosts file.
As such, the following lines need to be added into /etc/hosts file:

216.239.38.120 forcesafesearch.google.com
216.239.38.120 restrict.youtube.com
204.79.197.220 strict.bing.com

The solution for other search engines

DuckDuckGo

DuckDuckGo implemented their safe search differently whereby the safe search domain safe.duckduckgo.com resolves to the same IP as duckduckgo.com. Therefore, the solution concept described in this article cannot be applied to DuckDuckGo. Users would need to explicitly enter https://safe.duckduckgo.com.