Https redirect for subdomains

What is best way to achieve this. You tube adds are frequent popping up repeatedly.
I have captured its url. all these are https urls going to sub domain
All these urls are dynamic. They are changing to random values. If these urls are blocked, apps on network does not work. so I planned fake url on one of the server in network. is it possible to redirect all the subdomain request to this server. I made below configuration, but ip of subdomains are different every time.


Can Any one suggest the best solution for this ?

This cannot be done at the router level, since it happens at the application layer. You need to do this at the browser level on your computer.


You can add a wildcard redirect in dnsmasq, but I'm not sure how it's going to solve the problem with the ads.


Server, 180 is windows server. It has IIS and it can have proxy etc. server is capable to manipulate the https request and return the status code 200. it may return any value that all clients want which youtube video url will serve. problem is I want to direct all subdomain request that goes to to this server at router level.

Is this option suitable?

exactly what I was going for, except I didn't think it could be done through the UI.

from the conf file

# Add domains which you want to force to an IP address here.
# The example below send any host in to a local
# web-server.
1 Like

config file name ?
Sorry I am not expert.


1 Like


I have this entry. Shall I make it * instead of or /

I'd put it in /etc/dnsmasq.conf, with the syntax from the example I posted.

1 Like

Thanks every one. I got it how to redirect to my server and its redirecting. I need to do further work.


Machine, is also connected to same network so it can not place request so I need to exclude this machine from blocked url. and then making request to youtube I have to serve the calling client. So I need way to exclude this machine from the block.

Adapted the script for openwrt and to run twice a day (sometimes would change IPs twice a day), it used to block all YT ads. SurprisedItWorks got tired with the cat and mouse...

did you try it ?
comments say it doesn't work any more ...

Yep, it was great while it lasted. I added lists from other projects that attempted the same (failing), nevertheless the lists were useful.

then why did you post it ?

Configure to use a different DNS server which doesn't have the intercept in place?

@kpise here's the short version script, it won't block all ads as it used to but it still manages to block a few. Simply blocking or redirecting won't work as it will end up blocking videos too. The script must run at least twice a day.

Just tried the script but it fails to print the result of nslookup so i had to add it manually, I can't find out what's wrong with it, maybe someone here...

dhcp add these two lines.

list address '/'
list addnhosts '/tmp/badhosts'

#YT adblocker (ipv4).

cat <<'EOF' >/tmp/adblocker
cd /tmp
DD=$(echo $D | sed 's/\./\\./g')
{ curl -kf
  curl -kf
  curl -kf
  curl -kf | sed '/---/d;s/^/ &/'
  curl -kf | sed '/---/d;s/^/ &/'
  curl -kf | sed '/---/d;s/^/ &/'
  curl -kf | sed '/---/d;s/^/ &/'
} 2>badhosts.log | sed "s/\t/ /g; /^0\.0\.0\.0 /!d; s/ *\#.*$//; s/\r//; / $DD$/d" | sort -u > badhosts
service dnsmasq restart; sleep 5
A='^Address [0-9]+: '; I='[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
nslookup $D 2>/dev/null | sed -nE "/$A$I/{s/$A($I).*/\1 $D/p;q}" >>badhosts
service dnsmasq restart
chmod +x /tmp/adblocker
( sleep 90; /tmp/adblocker ) &
root@OpenWrt:/tmp# nslookup

root@OpenWrt:/tmp# grep badhosts
root@OpenWrt:/tmp# wc -l badhosts
107973 badhosts