Filtering home Internet access with Squid
Client Maintenance
The next step is to modify the ACL
(Access Control List) settings in squid.conf. To assign different filter rules to different users – for example, stricter rules for children – you first need to tell Squid what criteria to apply to incoming requests.
Listing 2 adds client IP addresses for Mom (Marion), Dad (Archie), a son (Simon), and a daughter (Tanja). At the same time, the listing tells Squid to accept requests from the local network.
Listing 2
ACL Settings
# Individual client definitions acl marion src 192.168.1.1/32 acl archie src 192.168.1.2/32 acl simon src 192.168.1.3/32 acl tanja src 192.168.1.4/32 01 # Allow Squid to accept requests from the local network 02 acl localhost src 192.168.1.0/24 03 acl to_localhost dst 192.168.1.0/24
Time-Based and Manual Blocks
In my experience, it is often hard to keep the kids off the computer, especially if they have Internet access. Squid lets you block online access at certain times of the day. Listing 3 gives an example that defines a time slot for older kids between 1:00pm and 9:00pm Monday through Friday, while restricting access for the younger kids to 1:00pm and 7:00pm.
Listing 3
Time Slots
acl big_kids time MTWHF 13:00-21:00 acl small_kids time MTWHF 13:00-19:00 http_access deny simon ! big_kids http_access deny tanja ! small_kids
Because Simon is older, he is allowed to surf later than his little sister, Tanja; this is set in the http_access lines, which are read as follows: "The client called Simon is not allowed to surf the Internet, except at the times defined in the ACL big_kids." Both kids are allowed unrestricted Internet access on weekends, and no restrictions apply to the parents.
Sometimes it makes sense to completely block Internet access for a client. Just add the contents of Listing 4 to the configuration file. The /usr/share/squid/blocked_clients file itself only contains the IP addresses and netmasks of the clients you want to block (Listing 5).
Listing 4
Blocking Access
acl blocked_clients src "/usr/share/squid/blocked_clients" http_access deny blocked_clients
Listing 5
blocked_clients
192.168.1.3/32 192.168.1.4/32
A simple shell command is all it takes to add clients to the list. The command
echo 192.168.1.3/32 >> && /usr/share/squid/blocked_clients && /etc/init.d/squid reload
puts Simon on the block list. Typing
sed /^192.168.1.3\\/32$/d -i && /usr/share/squid/blocked_clients && /etc/init.d/squid reload
removes the entry.
Ads and Cookies
In addition to simple website blocking, Squid offers more advanced features: In combination with the free Privoxy [3] tool, it will filter banners and similar elements while you surf the web. To enable Privoxy, just add the lines from Listing 6.
Listing 6
Enable Privoxy
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.