Redirect all requests to a website to my server in my local netwwork

Posted on

QUESTION :

I have a D-Link-DIR-615 router.
Hardware version: T3.
Firmware Version: 20.22.

I want to redirect all requests made to https://www.youtube.com/ to my own NodeJS server running in the Local Network at say 192.168.0.4

Note: I want requests of all devices connected to my network to be redirected!

I tried changing my router firmware to DD-WRT, OpenWrt, etc but my router was not installing it!

I cannot find any way to do it as of now?

Can anyone help?

ANSWER :

I checked the manual of your router for the ability to create a static DNS entry, however I did not find that it supports that (can’t rule out it does allow that).

One way to achieve this would be to host your own DNS relay server in your LAN. This is a DNS server that caches DNS requests and forwards DNS requests that are not in cache to another recursive DNS server. There, you can normally add static entries, in this case an A record for youtube.com to 192.168.0.4.

A popular software for this is pi-hole, which many people use to block requests to ad-serving hosts (e.g. something with ads.example.com resolves to 0.0.0.0 based on a blacklist in the server). To achieve what you are trying to do with this exemplary software you need to:

  • Setup pihole
  • Make pihole the primary DNS server in the DHCP settings of your router (ie telling every host on the network to use this server to resolve domains)
  • Add a custom entry to resolve youtube.com

A few things need to be noted here:

  • This only blocks access to youtube.com on the DNS-layer. For example, an application that has a hardcoded IP-address of youtube.com as a fallback will still be able to connect to that server since the blocking/redirecting is on a layer above that.
  • You will get SSL warnings/errors in the clients connecting to the host on your LAN if https://youtube.com is being used since that is essentially a man-in-the-middle attack. Thus, such an approach works well for blocking access to that site but not for forwarding the traffic transparently. If you want to achieve that you will need to use a HTTP proxy and configure that in each browser of each host of the network. As you can see this solution would then involve manual configuration of each host and is not a transparent network-wide solution – therefore it is probably not what you want.

Leave a Reply

Your email address will not be published. Required fields are marked *