Kubuntu 14.04 Trusty Tahr and DansGuardian for
Filtering and Public Wireless Access

By John C. Rucker

Originally published on 8 August 2014. Last modified on 22 August 2018.

Introduction

Below are my local install notes for putting together a DansGuardian filtering system on Kubuntu 14.04 Trusty, including computer lab time and print management, video surveilance, shared file server space, usage statistics, and more.

You'll need to be pretty comfortable with Linux and the command line to replicate this. But it's really nothing too complicated. Basic steps needing no explanation for someone experienced in Linux are omitted. Using this guide, it takes me about 3 hours to set up a new machine from starting installation to full working order. These notes are for my benefit, but I hope you find it useful, too.

Install Kubuntu

Prep things for basic server tasks:

$ sudo apt-get install -y lamp-server^ samba-server^ openssh-server^

Tweak a Few Things

$ sudo apt install -y ntp vim exfat-fuse exfat-utils traceroute
*******************************************************************************
                              NOTICE TO USERS

This computer system is the property of the Branch District Library.  It is
for authorized use only.  Users (authorized or unauthorized) have no explicit
or implicit expectation of privacy.

Any or all uses of this system and all files on this system may be intercepted,
monitored, recorded, copied, audited, inspected, and disclosed to authorized
officials of law enforcement and government agencies.

By using this system, the user consents to such interception, monitoring,
recording, auditing, inspection, and disclosure at the discretion of the Branch
District Library or other authorized officials of law enforcement or government
agencies.

Unauthorized or improper use of this system may result in civil and criminal
penalties and administrative or disciplinary action, as appropriate.  By
continuing to use this system you indicate your awareness of and consent to
these terms and conditions of use.  LOG OFF IMMEDIATELY if you do not agree to
the conditions stated in this notice.

*******************************************************************************
auto eth0
iface eth0 inet static
address 192.168.40.2
netmask 255.255.255.0
broadcast 192.168.40.255
gateway 192.168.40.1
dns-nameservers DNS1 DNS2

auto eth1
iface eth1 inet static
address 192.168.1.1
netmask 255.255.255.0
broadcast 192.168.1.255
dns-nameservers DNS1 DNS2

DHCP Server

$ sudo apt install -y isc-dhcp-server && \
sudo mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak

Edit /etc/dhcp/dhcpd.conf as needed, adding static address assignments for your library-provided public computers. If you are using this DHCP server to give addresses to all your public and staff computers, make sure all library computers are defined in this file. The file should look something like this:

authoritative;
default-lease-time 3600;
max-lease-time 3600;
ddns-update-style none;
log-facility local7;
option routers 192.168.1.1;
option domain-name-servers YOUR-DNS-SERVER-1,YOUR-DNS-SERVER-2;

subnet [Subnet of eth0, just ending in .0] netmask 255.255.255.0 
{
}

subnet 192.168.1.0 netmask 255.255.255.0 
{
    range 192.168.1.100 192.168.1.254; # desired public service IP address range
    host HOSTNAME-HERE # host names for static IP assignment
    {
        hardware ethernet MAC-ADDRESS-USING-COLONS;
        fixed-address DESIRED-IP-ADDRESS-FOR-THIS-MACHINE;
    }
}

Edit /etc/rsyslog.d/50-default.conf. Find the line that reads:

*.*;auth,authpriv.none              -/var/log/syslog

and change it to:

*.*;auth,authpriv.none,local7.none              -/var/log/syslog

Restart DHCP server and rsyslog:

$ sudo service rsyslog restart && sudo service isc-dhcp-server restart

Shorewall

We'll use Shorewall to make it easier to maintain rules for public Internet access. Note: I highly recommend that you have this gateway behind another firewall, limiting access from the public Internet. In this case, think of "net" in all the examples below to mean your staff network and "loc" is your public access network.

Install shorewall and copy configuration files:

$ sudo apt-get install -y shorewall shorewall-init && \
sudo cp /usr/share/doc/shorewall/examples/two-interfaces/interfaces /etc/shorewall/ && \
sudo cp /usr/share/doc/shorewall/examples/two-interfaces/masq /etc/shorewall/ && \
sudo cp /usr/share/doc/shorewall/examples/two-interfaces/policy /etc/shorewall/ && \
sudo cp /usr/share/doc/shorewall/examples/two-interfaces/rules /etc/shorewall/ && \
sudo cp /usr/share/doc/shorewall/examples/two-interfaces/zones /etc/shorewall/
#ZONE   INTERFACE    OPTIONS

net     eth0            dhcp,tcpflags,nosmurfs,routefilter,sourceroute=0
loc     eth1            dhcp,tcpflags,nosmurfs,routefilter

Edit /etc/shorewall/masq:

eth0          192.168.1.0/24

Edit /etc/shorewall/policy:

loc             all             ACCEPT
fw              loc             ACCEPT
fw              net             REJECT
net             all             DROP
# THE FOLLOWING POLICY MUST BE LAST
all             all             REJECT
Edit /etc/shorewall/rules. At minimum, append the following rules to the end of the existing file. More likely, use the huge ruleset we normally use.

# file sharing
SMB(ACCEPT)  net    fw
SMB(ACCEPT)  fw    net

# Accept SSH connections for administration
ACCEPT      net                     fw      tcp     22

# Accept HTTP for the wifi stats
ACCEPT      net                     fw      tcp     80,443

# let the other servers access apcupsd for shutdown commands
#     after a power failure
ACCEPT      net                     fw      tcp     3551 

# VNC
ACCEPT      net                     fw      tcp     5900

# Allow both sides of the firewall to access the filter
# (as in your staff side can use the filter, too)
ACCEPT      net       fw          tcp    8081

# Route all HTTP traffic from library computers to the filter
# make the IP address range match your needs
REDIRECT    loc:192.168.1.2-192.168.1.255 8081    tcp    80,8000,8001,8080   -

####################################################
# RULES TO LET CERTAIN TRAFFIC OUT OF THE FIREWALL #
####################################################


# ping
ACCEPT      fw      net                     icmp

#DNS
ACCEPT      fw      net                     udp     53
ACCEPT      fw      net                     tcp     53

# HTTP(s)
ACCEPT      fw      net                     tcp     80,8000,8001,8080,443

# NTP
ACCEPT      fw      net                     udp     123

# Security Cams
ACCEPT      fw      net                     tcp     7001,7002

# Allow all traffic out to the local staff and public networks
ACCEPT     fw      net:192.168.0.0/16     all
ACCEPT     fw      loc                    all

########################################################
# END RULES TO LET CERTAIN TRAFFIC OUT OF THE FIREWALL #
########################################################

# This last rule needs to be in place to allow for unfiltered library computers. It needs to be kept last.
ACCEPT      loc     net                     tcp     80 

#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE
fw      firewall
net     ipv4
loc     ipv4
$ sudo shorewall restart

Proxy: Squid or Tinyproxy

This setup will work fine with either Squid or Tinyproxy. Tinyproxy, as the name implies, is easier to setup and has less overhead. Squid has fewer problems with sites not loading, but requires more overhead and is more difficult to set up. We typically use Squid here.

Squid (do this step OR Tinyproxy, not both!)

Install Squid:

$ sudo apt-get install squid3

Edit /etc/squid3/squid.conf: search for http_port 3128 and below it add the line http_port 3129 intercept. Search for # access_log /var/log/squid3/access.log squid. Add a line below that reading access_log none. Search for cache_store_log. There will be a commented out code block for this tag with Default: none at the bottom. Add a new line below this reading cache_store_log none. Finally, add lines like the below to the end of the file to throttle HTTP traffic as needed (adjust the numbers in bytes to match your bandwidth and throttling needs):

########Squid Delay Pools#########
# a simple global throttle, users sharing 5 Mbit/s
delay_pools 1
delay_class 1 1
# 5 Mbit/s fill rate, 6 Mbit/s reserve, units in bytes
delay_parameters 1 655360/786432
acl All src 0/0
delay_access 1 allow All
$ sudo service squid3 restart

Tinyproxy (do this step OR Squid, not both!)

$ sudo apt-get install -y tinyproxy
$ sudo /etc/init.d/tinyproxy restart
0 2 * * * /etc/init.d/tinyproxy restart

DansGuardian

# sudo apt-get install -y dansguardian
# for Google
#we add &safe=vss to the end of every search
"(^http[s]?://[0-9a-z]+\.google\.[a-z]+[-/%.0-9a-z]*/search\?.*)"->"\1&safe=vss"

#for Bing
#similar, but &adlt=strict is the keyword
"(http[s]?://[0-9a-z]+.bing.com/images/search\?.*)"->"\1&adlt=strict"
1 *  *   *   *     wget http://localhost/DHCPd-parse.php -O /dev/null > /dev/null 2>&1

Temp Drive for Sharing Files and Ninite Update Cache

$ sudo mkdir /home/temp
$ sudo chown nobody:nogroup /home/temp
$ sudo chmod 777 /home/temp
[temp]
 comment = Public file sharing space
 path = /home/temp
 read only = no
 user mask = nobody
 create mask = 0666
 directory mask = 0777
 browseable = no
 public = yes
 writeable = yes
 guest ok = yes
 guest only = yes
$ sudo service samba restart

Print Release Station