I've tried two different commands in IPTables to block YouTube. They briefly work, but then, hours later, or the next day, I test it again, only to find that it comes through when I DON'T want it to. Does anyone know of a good solution to this?
23 Answers
That's because you're up against YouTube which is huge and has servers all over the planet and they use them very efficiently to stream Terabytes of data!!!
If you really want to do this: don't remove any YouTube address from your IPtables; just keep adding them and to start, just go here for a list of YouTube IP addresses and add those all in. Check it weekly as they keep adding servers...
Fair warning: Some day, when you finally nailed down all of the YouTube servers, someone will show up at your desk and tell you: "Look, there's this educational video on how to install my printer/teach me math/... and I really need it!" and then you're going to pull out all of your hair and remove the blocks you've so painstakingly put in. (Your mileage may vary, though)
Edit: Additionally there might be circumstances where you actually block other Google services if you block huge ranges of YouTube IP addresses in IPtables or any other IP based filtering.
5Another solution to this maybe adding the line 0.0.0.0 youtube.comto /etc/hosts. If it still does not block Youtube try flushing the DNS cache by sudo /etc/init.d/dns-clean restart
I have verified this on Linux-4.15.
Well, I was encountering something like this while configuring iptables to block different IPs (not YouTube's). The problem I noticed was that when I turned off my my laptop, I would lose the configuration.
The best way to keep the configurations is saving it using the iptables-save command.