10.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:

EXTERNAL_INTERFACE

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

LOCAL_INTERFACE_1

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

LOOPBACK_INTERFACE

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

IPADDR

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).

LOCALNET_1

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 192.168.1.0/24, part of the Class C private address range.

ANYWHERE

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 0.0.0.0/0.

NAMESERVER_1

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

NAMESERVER_2

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

MY_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.

LOOPBACK

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

PRIVPORTS

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

UNPRIVPORTS

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.

Tip: 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