Skip to content

Instantly share code, notes, and snippets.

@DrJume
Last active September 1, 2024 16:33
Show Gist options
  • Save DrJume/490e08f7f1be1daf5f5d3ae82a1a733e to your computer and use it in GitHub Desktop.
Save DrJume/490e08f7f1be1daf5f5d3ae82a1a733e to your computer and use it in GitHub Desktop.
Using lancache with a FritzBox

Using lancache with a FritzBox is not very straight forward:

  1. You need to have access to the DNS settings in the FritzBox web interface. Some providers disable this setting to force their customers with specific settings, like their own (mostly slow) DNS servers.
  2. Set both DNS server entries to your local IP address, on which the lancache is accessable.
  3. The FritzBox has a DNS rebind protection. To disable this for the hostnames, which are used for the lancache, you need to specify them as a list format in the web interface.

All the hostnames can be found at uklans/cache-domains. Download the repo and switch into the directory.

cat *.txt | grep -v "^#" | sed -E 's/\*\.//' | sort | uniq

These commands pipe their output as a input into the next one. This is a very powerful technique in the world of Unix.

  • cat *.txt - display the content of all files ending with ".txt" in a concatenated form

  • grep -v "^#" - discard all lines beginning with a hashtag (comments)

  • sed -E 's/\*\.// - substitute all '*.' (wildcards) from the hostnames with an empty string. The symbols need to be escaped with a '\' for them to be interpreted literally and not as a placeholder. (beware of the -E flag, I mostly use the more modern Extended RegEx mode, which also is the standard in most scripting/programming languages)

  • sort | uniq - sort all the lines in order to remove duplicates with uniq

@mahoromax
Copy link

mahoromax commented May 5, 2023

Have you found any way to still have your internet working for all devices when your lancache dns is down?
Pointing both servers to my lancache dns will probably make internet on all devices that use the fritz.box as DNS (as advertised in dhcp) be gone :-/
But the fritz.box seems to recognize unauthorized answers as a fault, and immediately swaps to any other option it has (secondary server, or public one if the option to use public DNS when errors occur)...

Actually, it seems I didn't wait long enough. Pointing both primary and secondary to my local DNS and enabling the option to swap to public servers in case of errors does work - it takes a few seconds, but even with my DNS down the internet automatically comes back.
It seems to take a good while for the FB to switch back to its original DNS settings :-/
Although dis- and reenabling the option seems to do the trick.

@DrJume
Copy link
Author

DrJume commented May 5, 2023

Have you found any way to still have your internet working for all devices when your lancache dns is down? Pointing both servers to my lancache dns will probably make internet on all devices that use the fritz.box as DNS (as advertised in dhcp) be gone :-/ But the fritz.box seems to recognize unauthorized answers as a fault, and immediately swaps to any other option it has (secondary server, or public one if the option to use public DNS when errors occur)...

Actually, it seems I didn't wait long enough. Pointing both primary and secondary to my local DNS and enabling the option to swap to public servers in case of errors does work - it takes a few seconds, but even with my DNS down the internet automatically comes back. It seems to take a good while for the FB to switch back to its original DNS settings :-/ Although dis- and reenabling the option seems to do the trick.

Thank you for leaving this feedback! By providing this info, you may have saved someone a few hours.

Sadly, I personally only had used lancache with a provider/ISP FritzBox. To easily switch DNS settings on every Windows client, I made some funky PowerShell scripts (https://gist.github.com/DrJume/66d8662db29840a10d02f332ef885cd8). Using them, switches DNS almost instantly.

@mahoromax
Copy link

I think nowadays there's hardly any lock by providers (left). Back in the day I had to flash the original firmware once or twice (I can't actually see how old the gist is, or I don't know where to look).

For now I think I do prefer my solution, without that option to fallback to public servers I'd probably also implement your scripts. (I'm sure there is also a way to automate that, by checking whether a) your gateways mac address fits and b) if dns resolution works then use lancache dns otherwise reset to dhcp ones... and then shedule that maybe? There's probably also a way to have it execute when a network connection is established.

@janstuemmel
Copy link

Thank you! I stumbled accross rebind protection yesterday but didn't think of it today -.-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment