Shorewall – A High-Level Firewall for Configuring Linux Servers

[‘

n

Setting up a firewall in Linux can be very daunting for a newbie, or for someone not very familiar with iptables. Luckily, there is a very easy to use solution in Shorewall.

n

Install Shorewall Firewall in Linux
Install Shorewall Firewall in Linux

n

In this multi-part tutorial, I am going to get you started with Shorewall, and walk you through some more advanced topics with this awesome firewall system.

n

What is Shorewall?

n

Shorewall is essentially a front-end to iptables, but it is a command line environment front-end that utilizes a number of text files for its configuration. While Shorewall is a robust firewall system that can be scaled over very large networks servicing numerous machines, we are going to start off with a basic two-interface configuration and nail down the basics.

n

A two-interface configuration consists of a machine with two Ethernet ports, one coming in, and one going out to the local network.

n

Installation of Shorewall in Linux

n

Shorewall can be installed using apt-get and yum package manager tools.

n

On Debian/Ubuntu/Linux Mint

n

$ sudo apt-get install shorewall6

n

On RHEL/CentOS/Fedora

n

$ sudo yum install shorewall6

n

After installation, we need to copy a sample configuration from the “/usr/share/doc/shorewall” directory to Shorewall’s default directory “/etc/shorewall”.

n

$ sudo cp /usr/share/doc/shorewall/example/two-interfaces/* /etc/shorewall

n

And then cd to /etc/shorewall.

n

$ cd /etc/shorewall

n

If we take a look in this directory, we see a bunch of files and shorewall.conf file. Shorewall views the network as a group of different zones, so the first file we want to take a look it is the “/etc/shorewall/zones” file.

n

Zones
Zones

n

In here, we see that there are three zones defined by default: net, loc, and all. It is important to note that Shorewall treats the firewall machine itself as its own zone and stores it in a variable called $FW. You will see this variable throughout the rest of the configuration files.

n

The “/etc/shorewall/zones” file is pretty self-explanatory. You have the net zone (internet facing interface), the loc zone (LAN facing interface), and all, which is everything.

n

Policy
Policy

n

This setup up gives up the following:

n

    n

  1. It allows all connection requests from the loc zone (LAN) to the net zone (Internet).
  2. n

  3. Drops all connection requests (ignores) from the net zone to the firewall and the LAN.
  4. n

  5. Rejects and logs all other requests.
  6. n

n

The LOG LEVEL bit should be familiar to anyone who has done administrating with Apache, MySQL, or any other number of other FOSS programs. In this case, we are telling Shorewall to use the info level of logging.

n

If you wish to have your firewall available to you to administer from your LAN, you can add the following lines to your “/etc/shorewall/policy” file.

n

#SOURCEttDESTtPOLICYttLOGttLEVELttLIMIT:BURSTrnlocttt$FWttACCEPTrn$FWtttlocttACCEPT

n

Now that our zones and policy are set, we have to configure our interfaces. You do this by editing the “/etc/shorewall/interfaces” file.

n

Interfaces
Interfaces

n

Here, we have set our internet facing interface as eth0 to the net zone. On our LAN side, we have set the other interface, eth1, to the loc zone. Please adjust this file to fir your configuration properly.

n

The various options you can place for either of these interfaces is extensive, and are best explained in detail on the man page.

n

$ man shorewall-interfaces

n

A quick run down of some of them are as follows:

n

    n

  1. nosmurfs – filter packets with broadcast address as source.
  2. n

  3. logmartians – log packets with impossible source address.
  4. n

  5. routefilter – kernel route filtering for anti-spoofing.
  6. n

n

Of course, now that our system is firewalled, we are going to need certain connections to be allowed through in order to get what we need to do done. You define these in the rules file at “/etc/shorewall/rules“.

n

Rules
Rules

n

This file looks confusing at first, mainly because the columns overlap, but the headers are pretty self-explanatory. First, you have the ACTION column, that describes what you want to perform.

n

Next, you have a SOURCE header where you define the zone where the packet is originating. Then, you have your DEST, or destination, which is the zone or IP address of the destination. Lets use an example.

n

Suppose you want to run an SSH server behind your firewall on the machine with the IP address of 192.168.1.25. Not only are you going to have to open up a port in your firewall, but you are going to have to tell the firewall that any traffic coming on port 22 needs to get routed to the machine at 192.168.1.25.

n

This is known as Port Forwarding. It is a common feature on most firewall/routers. In “/etc/shorewall/rules“, you would accomplish this by adding a line like this:

n

SSH(DNAT)tnetttloc:192.168.1.25

n

SSH Port Forwarding
SSH Port Forwarding

n

Above, we have defined any SSH destined packets coming from the net zone to the firewall have to be routed (DNAT) to port 22 on machine with address 192.168.1.25.

n

This is called Network Address Translation or NAT. The “D” simply tells Shorewall that this is a NAT for a destination address.

n

In order for this to work, you have to have NAT support enabled in your kernel. If you need NAT and don’t have it, please see my tutorial on Recompiling a Debian Kernel.

n

Reference Links

n

Shorewall Homepage

n

In the next article, we will walk through some more advanced topics, but there should be plenty here to get you started with for now. As always, please have a look at the man pages for a more in-depth understanding.

n

Read Also : Exploring Shorewall Firewall Configuration and Command Line Options

n

‘]