4. Rules used in the Firewall script files

The following is an explanation of a few of the rules that will be used in the Firewalling examples below. This is shown just as a reference, the firewall scripts are well commented and very easy to modify. Constants are used, in the firewall scripts files for most values. The most basic constants are:


This is the name of the external network interface to the Internet. It's defined as eth0 in the examples.


This is the name of the internal network interface to the LAN, if any. It's defined as eth1 in the examples.


This is the name of the loopback interface. It's defined as lo in the examples.


This is the IP address of your external interface. It's either a static IP address registered with InterNIC, or else a dynamically assigned address from your ISP (usually via DHCP).


This is your LAN network address, if any - the entire range of IP addresses used by the machines on your LAN. These may be statically assigned, or you might run a local DHCP server to assign them. In these examples, the range is, part of the Class C private address range.


Anywhere is a label for an address used by ipchains to match any (non-broadcast) address. Both programs provide any/0 as a label for this address, which is


This is the IP address of your Primary DNS Server from your network or your ISP.


This is the IP address of your Secondary DNS Server from your network or your ISP.


This is your ISP & NOC address range. The value you specify here is used by the firewall to allow ICMP ping request and traceroute. If you don't specify an IP address range, then you will not be able to ping the Internet from your internal network.


The loopback address range is The interface itself is addressed as in /etc/hosts.


The privileged ports, 0 through 1023, are usually referenced in total.


The unprivileged ports, 1024 through 65535, are usually referenced in total. They are addresses dynamically assigned to the client side of a connection.

Please Note a firewall has a default policy and a collection of actions to take in response to specific message types. This means that if a given packet has not been selected by any other rule, then the default policy rule will be applied.


People with dynamically assigned IPs from an ISP may include the following two lines in their declarations for the firewall. The lines will determine the ppp0 IP address, and the network of the remote ppp server.

          IPADDR=`/sbin/ifconfig | grep -A 4 ppp0 | awk '/inet/ { print $2 } ' | sed -e s/addr://`
          MY_ISP=`/sbin/ifconfig | grep -A 4 ppp0 | awk '/P-t-P/ { print $3 } ' | sed -e s/P-t-P:// | cut -d '.' -f 1-3`.0/24

You need to Enable Local Traffic since the default policies for all example firewall rule script files in this book are to deny everything, some of these rules must be unset. Local network services do not go through the external network interface. They go through a special, private interface called the loopback interface. None of your local network programs will work until loopback traffic is allowed.

          # Unlimited traffic on the loopback interface.
          ipchains -A input  -i $LOOPBACK_INTERFACE -j ACCEPT
          ipchains -A output -i $LOOPBACK_INTERFACE -j ACCEPT