Hosts file based redirection will only work if going through the local DNS resolver.
You could use iptables on the raspberry pi, redirecting connections for certain IP:Port combos to wherever you like. The difficulty with this approach is, services like youtube might use way more than a single IP. For example:
Code: Select all
So you'd have to redirect all of these IPs, and even then it might not work reliably because new IPs might get introduced any day. I guess you could make a script that runs periodically, uses nslookup to obtain all IPs of a given site and creates iptables rules accordingly.
Another possibility would be to set up a DNS server on the Pi, and have your clients use this server for resolving. You might use an additional DHCP server on your Pi to achieve this. You can then have the DNS server on the Pi give out any IP you like for any site you want (by the means of zone files), while forwarding all other lookup requests to your provider's DNS server.
However, your users may simply override this system by configuring a different DNS server on their clients. This could be supressed by blocking outgoing DNS requests from the wlan (Port 53 TCP+UDP) that don't go to your Pi. Of course, the users could still circumvent that by editing their own hosts file...
Find more info on Raspberry Pi, Virtualization and all things cloudy on my blog: http://niston.wordpress.com