Redirect url to another. CNAME?

General discussion about Gargoyle, OpenWrt or anything else even remotely related to the project

Moderator: Moderators

Hercules
Posts: 23
Joined: Sun Sep 29, 2013 6:58 pm

Redirect url to another. CNAME?

Post by Hercules »

Hi Guys,

I have a complex setup at home that I am trying to make even more complex! I am running Gargoyle 1.5.10 on a TP-LINK WDR4300

I am in Australia and use getflix as geo-block avoidance measure. To do this requires changing the DNS servers to use getflix's. However, as part of my child friendly home network I use openDNS parental controls. Using the info from here: https://getflix.zendesk.com/hc/en-gb/ar ... c-domains- I have successfully implemented the geoblocking and opendns filtering together by adding dnsmasq entries in /etc/config/dhcp. So great!

Now I want to expand that further by forceing google safe search by using option 3 from here: https://support.google.com/websearch/an ... 6669?hl=en

However, I don't know whether that is possible and I don't really know what I am doing! I have tried adding the following to dhcp:
config 'cname'
option cname 'www.google.com'
option target 'forcesafesearch.google.com'

However, that is not working. So is it possible to selectively redirect a URL with Gargoyle? Can I do it with the hosts file?

Thanks!

Hercules
Posts: 23
Joined: Sun Sep 29, 2013 6:58 pm

Re: Redirect url to another. CNAME?

Post by Hercules »

Yes I have added a new hosts file with all the google domains redirecting to forcesafesearch.google.com and then added a line to the dhcp config file under dnsmasq of "list addnhosts '/etc/redirect.google' and that seems to be working.

Hope someone finds this useful in the future!

Just note that if you are in the US then it might break some things because stuff that hangs off google.com like "www.google.com/calendar" will no longer work. I have asked a question on the google forum but no reply as yet. Since I am in Australia I took that redirect off so I don't have the issue and since google redirects my www.google.com to www.google.com.au which I then redirect to forcesafesearch.google.com it works!

tehpensfan
Posts: 16
Joined: Thu Oct 31, 2013 10:35 am

Re: Redirect url to another. CNAME?

Post by tehpensfan »

Thanks!
I followed your lead and it works for me.
I am based in Canada so my local google search domain is google.ca

As you noted, being in a different country domain actually makes it possible to not break desktop calendar or anything else other than search that uses http://www.google.com

I've written up a mini guide below to help others with the same configuration. If it's decent, we should add it to the documentation maybe in a new section about parental controls. It would be nice if the FamilyShield OpenDNS servers were one of the pulldown options :)

Forcing Google SafeSearch
Skill Level: Intermediate
  1. ssh/telnet into your gargoyle router and navigate to the /etc directory

    Code: Select all

    cd /etc
    
    Choose one of the following two methods to create the redirect hosts file:

    Easy Method:
    (Requires that your Gargoyle Router has internet access. Looks up the Virtrual IP address of forcesafesearch.google.com and finds the list of google country domains dynamically.)
    Use the following command on the router:

    Code: Select all

    wget -O - http://www.google.com/supported_domains | grep -v google.com$ | awk -v vip=`nslookup forcesafesearch.google.com 127.0.0.1 | awk '{print $3}' | tail -1` '{print vip"     www"$0}' > redirect.google
    Then we need to modify some of the domains that google uses that have ".co.<country>" or ".com.<country>" but for some reason does not include them in their domain list and we'll append these domains to the hosts redirect file as well:

    Code: Select all

    egrep ".co\.|.com" /etc/redirect.google | sed -e 's/co\.//' -e 's/com\.//' >> redirect.google
    Copy-Paste method:
    Create a file called redirect.google containing the following text
    (N.B.: how to create files at the bash prompt: http://www.cyberciti.biz/faq/create-fil ... from-bash/):

    Code: Select all

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

    Code: Select all

    cp /etc/config/dhcp /root/dhcp.orig
    Edit /etc/config/dhcp and in the
    "config dnsmasq" section add

    Code: Select all

    cd /etc/config
    sed -i 's#config dnsmasq#config dnsmasq\n        list addnhosts '/etc/redirect.google' \# added#' dhcp
    so that the file we created above is used by the router's dns server.
  3. Reboot your gargoyle router
  4. Test: surf to http://www.google.ca and you should see a banner with the following text:
    Your network has turned on SafeSearch to filter explicit content. More info Dismiss
    Further more, all Top Level Domains URLs added should show the same banner (e.g. http://www.google.gm
Back Out
If something is messed up and you want to back out:
  1. copy your backup dhcp config file over the one you've modified.

    Code: Select all

    cp /root/dhcp.orig /etc/config/dhcp
  2. Reboot the router
There you go.
If there are any questions/comments/clarifications, post to this thread and we can fix the post.

ETA: an easier dynamic method of creating the redirect.google file in step 2 above
ETA2: I had a bug in the grep -v meant to remove .google.com that wasn't limited to .com only but ending the regular expression with an end of string $ fixes it.
ETA3: Noticed that Google doesn't list *some* of their country domains and added a quick dirty way to get them covered althought it does add some domains that don't exist ;-)
Last edited by tehpensfan on Thu Aug 27, 2015 12:51 pm, edited 4 times in total.
-
1 x WRT54GL v1.1 Gargoyle 1.5.6
1 x TL-WR740N v4.23 Gargoyle 1.6.2
1 x TL-WR740N v4.26 Gargoyle 1.5.11
1 x TL-WR740N v4.26 Gargoyle 1.8.1
1 x TL-WDR3600 v1.3 Gargoyle 1.5.11

nworbnhoj
Posts: 914
Joined: Mon Jul 21, 2014 10:08 am
Location: Australia
Contact:

Re: Redirect url to another. CNAME?

Post by nworbnhoj »

Great post! :D

Looks like an excellent basis for a plugin! Lantis?

Also, looks like a great Common Scenario
http://www.gargoyle-router.com/wiki/dok ... _scenarios
However, all of the current common scenarios are limited to configuration via the Gargoyle interface - so this one is a little more "involved".

tehpensfan would you like to create a new scenario-familysafe or shall I have a crack at it?
Can you help someone else get Gargoyle up and running?
TL-WDR3600 : Gargoyle 1.9.0 : NBN FixedWireless
TL-WR1043ND-V2 : Gargoyle 1.8.0 : 3G Huawei E160E

tehpensfan
Posts: 16
Joined: Thu Oct 31, 2013 10:35 am

Re: Redirect url to another. CNAME?

Post by tehpensfan »

nworbnhoj wrote:Great post! :D

Looks like an excellent basis for a plugin! Lantis?

Also, looks like a great Common Scenario
http://www.gargoyle-router.com/wiki/dok ... _scenarios
However, all of the current common scenarios are limited to configuration via the Gargoyle interface - so this one is a little more "involved".

tehpensfan would you like to create a new scenario-familysafe or shall I have a crack at it?
I'd be willing to give it a shot.

I think there is a way to make it even easier to set up that might be able to be set up as a cron job.
-
1 x WRT54GL v1.1 Gargoyle 1.5.6
1 x TL-WR740N v4.23 Gargoyle 1.6.2
1 x TL-WR740N v4.26 Gargoyle 1.5.11
1 x TL-WR740N v4.26 Gargoyle 1.8.1
1 x TL-WDR3600 v1.3 Gargoyle 1.5.11

Lantis
Moderator
Posts: 6023
Joined: Mon Jan 05, 2015 5:33 am
Location: Australia

Re: Redirect url to another. CNAME?

Post by Lantis »

Sure. I could make this into a simple 1 click install scripts. I agree that it should be run as a CRON job to ensure the ip of forcesafesearch is always current. I wouldn't necessarily implement it as a plugin until there was a workaround for the calendar and other issues as discussed.
Also I believe you can save space in your hosts file by removing "www." For each entry.

But this is a great post by the way :) good info.
http://lantisproject.com/downloads/gargoyle_ispyisail.php for the latest releases
Please be respectful when posting. I do this in my free time on a volunteer basis.

tehpensfan
Posts: 16
Joined: Thu Oct 31, 2013 10:35 am

Re: Redirect url to another. CNAME?

Post by tehpensfan »

Lantis wrote:Sure. I could make this into a simple 1 click install scripts. I agree that it should be run as a CRON job to ensure the ip of forcesafesearch is always current. I wouldn't necessarily implement it as a plugin until there was a workaround for the calendar and other issues as discussed.
Also I believe you can save space in your hosts file by removing "www." For each entry.

But this is a great post by the way :) good info.
Thanks.
I tried with and without "www" in the host entries but I was only able to get it to work with.
-
1 x WRT54GL v1.1 Gargoyle 1.5.6
1 x TL-WR740N v4.23 Gargoyle 1.6.2
1 x TL-WR740N v4.26 Gargoyle 1.5.11
1 x TL-WR740N v4.26 Gargoyle 1.8.1
1 x TL-WDR3600 v1.3 Gargoyle 1.5.11

buildcomplete
Posts: 1
Joined: Tue Oct 20, 2015 1:22 pm

Re: Redirect url to another. CNAME?

Post by buildcomplete »

Just installed gargoyle on my new router, and its splendid.

I used the tip here slightly modified. since I have development web-server that I would like to visit with my phone, not possible before.

to /etc/redirect.local I have added

Code: Select all

IP    virtual-host-name1
IP    virtual-host-name2
IP    virtual-host-name3
IP    virtual-host-name4
and added

Code: Select all

list addnhosts /etc/redirect.local # added#config dnsmasq\n        list addnhosts '/et
to /etc/config/dhcp

and now I am access by the hostname from all my devices :D

so thanks for the tip tehpensfan!

msb1
Posts: 10
Joined: Wed Jun 10, 2015 12:35 am

Re: Redirect url to another. CNAME?

Post by msb1 »

Hi all,

This was working fine on 1.9.0 but doesn't seem to be working on 1.9.1.
Do I need to make any changes?

I had the following line in dhcp:
list addnhosts '/etc/redirect.local' \# added#' dhcp

And the file redirect.local contained:
192.168.1.1 airtel4grouter.cpe

dsalch
Posts: 116
Joined: Wed Jan 06, 2016 2:09 pm
Location: Tx

Re: Redirect url to another. CNAME?

Post by dsalch »

FYI

This method did seem to stop working somewhere around 1.9, and for sure did not work on my 1.10 after update. However, There is a page explaining an alternate method on OPENWRT that does work with 1.10 properly.

https://www.leowkahman.com/2017/09/11/e ... tube-bing/

Post Reply