This month we discuss how to secure an Internet gateway (or any Linux computer connected to the Internet, for that matter) using a firewall. A firewall is essentially a barrier between a computer and the network to which it is connected: it inspects data travelling in both directions and only permits certain data to pass, according to a set of rules given to the firewall when it is set up.
The most basic firewall strategy, and the one we will implement in this article, is to deny all connections from the outside network, while allowing the local computer to access the outside network without restriction. With this configuration we can access the Internet as we always have, while at the same time being protected against nasties such as hacking attempts.
Two tools are used to configure a firewall; which tool you use is dependent on the kernel your Linux system runs. To determine your kernel version, type the following in a shell:
$ uname -r
On my computer, this returns "2.4.17". The second number in this version is important. If your kernel version is of the form 2.2.x, follow the instructions under the heading IP Chains. If your kernel is like mine, and of the form 2.4.x, follow the instructions under the heading IP Tables.
The following script will set up a basic firewall on your computer. Open up your text editor and type in the script below. You will then have to save the script as /etc/rc.d/rc.firewall. Change
# flush existing rules
$IPCHAINS -F input
# allow traffic from the LAN to pass.
$IPCHAINS -A input -s
# flush existing rules
$IPTABLES -F INPUT
# allow traffic from the LAN to pass
$IPTABLES -A INPUT -s
$ chmod 700 /etc/rc.d/rc.firewallIf you are a modem user, add the following to the end of /etc/ppp/ip-up:
If you use a service such as cable or DSL, you will need to call this script after you have established your Internet connection by typing the following:
Testing the firewall
There are a number of free Web-based services on the Internet with which you can test your firewall. These services will try to connect to your computer in a number of common ways to test for servers and holes in your firewall. They will then return the results for your inspection. Some good free testing services are www.auditmypc.com and www.dslreports.com/secureme_go.