Shorewall on RPM-based Servers: Difference between revisions

From Alteeve Wiki
Jump to navigation Jump to search
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 5: Line 5:
= Install =
= Install =


{{note|1=Updated on <span class="code">2012-12-27</span> for Shorewall release 4.5.11.}}
{{note|1=Updated on <span class="code">2015-05-05</span> for Shorewall release 4.6.8.}}


Install is trivial, we just need to install dependencies and and the latest RPMs.
Install is trivial, we just need to install dependencies and and the latest RPMs.


<source lang="bash">
<syntaxhighlight lang="bash">
yum install perl perl-Digest-SHA perl-Digest-SHA1
yum install perl perl-Digest-SHA perl-Digest-SHA1
</source>
</syntaxhighlight>


You can check for the [http://shorewall.net/download.htm latest version here].
You can check for the [http://shorewall.net/download.htm latest version here].


<source lang="bash">
<syntaxhighlight lang="bash">
rpm -Uvh http://canada.shorewall.net/pub/shorewall/4.5/shorewall-4.5.11/shorewall-4.5.11-0base.noarch.rpm \
rpm -Uvh http://canada.shorewall.net/pub/shorewall/4.6/shorewall-4.6.8/shorewall-core-4.6.8-0base.noarch.rpm \
         http://canada.shorewall.net/pub/shorewall/4.5/shorewall-4.5.11/shorewall-core-4.5.11-0base.noarch.rpm
         http://canada.shorewall.net/pub/shorewall/4.6/shorewall-4.6.8/shorewall-4.6.8-0base.noarch.rpm
</source>
</syntaxhighlight>


Done!
Done!
Line 24: Line 24:
= Setup =
= Setup =


== Public IP Address Range ==
You need to decide which interface will have your internet connection on it and which will connect to your internal network. For this tutorial;


If you have multiple public IP addresses, make sure your Internet facing ethernet device, <span class="code">eth1</span> in our case, has all of those public IPs assigned to it. Do this by:
* <span class="code">eth0</span>; Faces the internal network, has the IP <span class="code">10.255.255.254/16</span> and provides DHCP services to the LAN.
# Copying the <span class="code">ifcfg-eth0</span> to <span class="code">ifcfg-eth0:x</span> where <span class="code">x</span> is a number, starting at 0, with the next public IP in the pool.
* <span class="code">eth1</span>; Faces the Internet.
# In each <span class="code">ifcfg-eth0:x</span> file:
## Add <span class="code">:x</span> to <span class="code">DEVICE=eth1</span>, for example <span class="code">DEVICE=eth1:0</span> in the <span class="code">ifcfg-eth0:0</span> file.
## Change the IP address in the <span class="code">IPADDR=</span> line. For example, <span class="code">208.67.144.34</span>.
## Comment out the <span class="code">GATEWAY=</span> line.
 
Here is an example showing what an <span class="code">ifcfg-eth0</span> and it's corresponding <span class="code">ifcfg-eth0:0</span> alias might look like:
 
<source lang="bash">
vim /etc/sysconfig/network-scripts/ifcfg-eth0
</source>
<source lang="bash">
HWADDR="00:16:36:71:84:2F"
DEVICE="eth0"
BOOTPROTO="static"
NM_CONTROLLED="no"
ONBOOT="yes"
IPADDR="192.168.1.253"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.254"
DNS1="8.8.8.8"
DNS2="8.8.4.4"
</source>
 
<source lang="bash">
vim /etc/sysconfig/network-scripts/ifcfg-eth0:0
</source>
<source lang="bash">
HWADDR="00:16:36:71:84:2F"
DEVICE="eth0:0"
BOOTPROTO="static"
NM_CONTROLLED="no"
ONBOOT="yes"
IPADDR="206.108.5.129"
NETMASK="255.255.255.255"
</source>
 
When done, simply restart networking:
 
<source lang="bash">
/etc/init.d/network restart
</source>
 
Or manually bring up each device with:
 
<source lang="bash">
ifup eth0:x
</source>
 
Setting <span class="code">x</span> to the number of each alias device you are starting. If you are connected over ssh, using <span class="code">ifup</span> is recommended as you are less likely to lose your ssh session.


== Configuring Shorewall ==
== Configuring Shorewall ==


All configuration files are in the following directory, unless explicitly defined:
All configuration files are in the <span class="code">/etc/shorewall</span> directory, unless explicitly defined. The main Shorewall configuration file, which we will edit last is <span class="code">/etc/shorewall/shorewall.conf</span>.
 
<source lang="bash">
/etc/shorewall
</source>
 
The main Shorewall configuration file, which we will edit last is <span class="code">/etc/shorewall/shorewall.conf</span>.
</source>


The files to edit are listed in the order we will edit them in the following subsections.
The files to edit are listed in the order we will edit them in the following subsections.
Line 93: Line 37:
=== zones ===
=== zones ===


This controls the main "zones" used by Shorewall. The <span class="code">fw</span> is special in that it defines the firewall itself. The <span class="code">net</span> zone is the Internet-facing network (eth1 on the firewall). The <span class="code">loc</span> is the local network, the virtual machine network on eth0.
This controls the main "zones" used by Shorewall. The <span class="code">fw</span> is special in that it defines the firewall itself. The <span class="code">net</span> zone is the Internet-facing network (<span class="code">eth1</span> in this tutorial). The <span class="code">loc</span> is the local network, the internal network of machines the firewall is protecting, which is <span class="code">eth0</span> in this tutorial. Both <span class="code">eth0</span> and <span class="code">eth1</span> are <span class="code">[[ipv4]]</span> networks.


Add:
Append two new lines telling shorewall that we have two new <span class="code">ipv4</span> networks that it will use:


<source lang="bash">
<syntaxhighlight lang="bash">
vim /etc/shorewall/zones
vim /etc/shorewall/zones
</source>
</syntaxhighlight>
<source lang="text">
<syntaxhighlight lang="text">
fw      firewall
net    ipv4
net    ipv4
loc    ipv4
loc    ipv4
</source>
</syntaxhighlight>


So that the 'zones' file looks like:
So that the <span class="code">zones</span> file looks like:


<source lang="text">
<syntaxhighlight lang="text">
###############################################################################
###############################################################################
#ZONE  TYPE            OPTIONS        IN                      OUT
#ZONE  TYPE            OPTIONS        IN                      OUT
Line 115: Line 58:
net    ipv4
net    ipv4
loc    ipv4
loc    ipv4
</source>
</syntaxhighlight>


=== interfaces ===
=== interfaces ===


{{Note|1=There are now two <span class="code">FORMAT</span> types; <span class="code">1</span>, which is the old-style and <span class="code">2</span>, the new style which this tutorial now uses.}}
Just above, we told shorewall that we had two new <span class="code">ipv4</span> networks. In the <span class="code">interfaces</span> configuration file, we link these networks to physical interfaces.


Here you tell Shorewall which network [[#zones|zones]] are on which interfaces.
{{note|1=If you plan to [[DHCP on an RPM-based OS|setup a DHCP]] server on your firewall, you will need to specify the <span class="code">dhcp</span> option, as shown here. You can see a full list of options and their uses on Shorewall's <span class="code">[http://www.shorewall.net/manpages/shorewall-interfaces.html interfaces]</span> page.}}


Add:
To link the new networks to the physical interfaces, append the following entries;


<source lang="bash">
<syntaxhighlight lang="bash">
vim /etc/shorewall/interfaces
vim /etc/shorewall/interfaces
</source>
</syntaxhighlight>
<source lang="text">
<syntaxhighlight lang="text">
net             eth0
loc             eth0                   dhcp
loc             eth1                   dhcp
net             eth1
</source>
</syntaxhighlight>
 
{{note|1=If you plan to [[DHCP on an RPM-based OS|setup a DHCP]] server on your firewall, you will need to specify the <span class="code">dhcp</span> option, as shown here. You can see a full list of options and their uses on Shorewall's <span class="code">[http://www.shorewall.net/manpages/shorewall-interfaces.html interfaces]</span> page.}}


So that the <span class="code">interfaces</span> file looks like:
So that the <span class="code">interfaces</span> file looks like:


<source lang="text">
<syntaxhighlight lang="text">
#
# Shorewall version 4 - Interfaces File
#
# For information about entries in this file, type "man shorewall-interfaces"
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-interfaces.html
#
###############################################################################
###############################################################################
FORMAT 2
?FORMAT 2
###############################################################################
###############################################################################
#ZONE          INTERFACE              OPTIONS
#ZONE          INTERFACE              OPTIONS
net             eth0
loc             eth0                   dhcp
loc             eth1                   dhcp
net             eth1
</source>
</syntaxhighlight>


=== policy ===
=== policy ===


Here you tell Shorewall what the default policy is for each network when receiving new connection requests. You don't need to worry about ESTABLISHED and RELATED connections as Shorewall handles these rules. The choices are:
Here you tell shorewall what the default policy is for each network when receiving new connection requests. You don't need to worry about <span class="code">ESTABLISHED</span> and <span class="code">RELATED</span> connections as shorewall handles these rules. The choices are:


* ACCEPT
* <span class="code">ACCEPT</span>; Accept the connection.
** Accept the connection.
* <span class="code">DROP</span>; Ignore the connection request.
* DROP
* <span class="code">REJECT</span>; Return an appropriate error to the connection request.
** Ignore the connection request.
* REJECT
** Return an appropriate error to the connection request.


You can also set the log level for connection requests that fall off the chain and hit these policies. It's a good idea to log <span class="code">info</span> level so you can see twits trying to do "bad things(tm)".
You can also set the log level for connection requests that fall off the chain and hit these policies. It's a good idea to log <span class="code">info</span> level so you can see twits trying to do "bad things(tm)". The one downside to using <span class="code">info</span> is that it pushes a lot of data into the log files, which might make debugging other issues on the firewall. It's really up to you in the end.


<source lang="bash">
Append the following default policies;
 
<syntaxhighlight lang="bash">
vim /etc/shorewall/policy
vim /etc/shorewall/policy
</source>
</syntaxhighlight>
<source lang="text">
<syntaxhighlight lang="text">
### These are the default policies;
# Let everything from the firewall machine out onto the net.
# This allows the firewall out onto the Internet
fw      net    ACCEPT
fw      net    ACCEPT


# Anything from the firewall to local machines is default ACCEPTed.
# Likewise, allow everything from the firewall out onto the local network.
fw      loc    ACCEPT
fw      loc    ACCEPT


# Protect the firewall from compromised machines by default DROPing packets.  
# Don't allow incoming connections from the web into the fireall *or* into the
# local network. Add 'info' here if you want to log failed connection attempts.
net    all    DROP            info
 
# Don't allow incoming connections from the local network into the firewall.
loc    fw      DROP
loc    fw      DROP


# Let anything from the local network out onto the Internet.
# Let machines on the local network out onto the web
loc    net    ACCEPT
loc    net    ACCEPT
 
</syntaxhighlight>
# DROP and log anything else.
net    all    DROP            info
</source>


So that the <span class="code">policy</span> file looks like:
So that the <span class="code">policy</span> file looks like:


<source lang="text">
<syntaxhighlight lang="text">
#
# Shorewall version 4 - Policy File
#
# For information about entries in this file, type "man shorewall-policy"
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-policy.html
#
###############################################################################
###############################################################################
#SOURCE DEST    POLICY          LOG    LIMIT:          CONNLIMIT:
#SOURCE DEST    POLICY          LOG    LIMIT:          CONNLIMIT:
#                              LEVEL  BURST          MASK
#                              LEVEL  BURST          MASK


### These are the default policies;
# Let everything from the firewall machine out onto the net.
# This allows the firewall out onto the Internet
fw      net    ACCEPT
fw      net    ACCEPT


# Anything from the firewall to local machines is default ACCEPTed.
# Likewise, allow everything from the firewall out onto the local network.
fw      loc    ACCEPT
fw      loc    ACCEPT


# Protect the firewall from compromised machines by default DROPing packets.  
# Don't allow incoming connections from the web into the fireall *or* into the
# local network. Add 'info' here if you want to log failed connection attempts.
net    all    DROP            info
 
# Don't allow incoming connections from the local network into the firewall.
loc    fw      DROP
loc    fw      DROP


# Let anything from the local network out onto the Internet.
# Let machines on the local network out onto the web
loc    net    ACCEPT
loc    net    ACCEPT
</syntaxhighlight>


# DROP and log anything else.
=== rules ===
net    all    DROP            info
 
</source>
This is really the heart of the firewall.


=== rules ===
Here you tell shorewall what the exceptions there are to the default policies. The first rule to match is used.


Here you tell Shorewall what the exceptions are to the default policies. The first rule to match is used. This is really the heart of the firewall.
The example below shows a setup where remote access in to the firewall itself is allowed only on port <span class="code">22000</span> (modified [[SSH]] port). Then two [[Microsoft]] Windows servers are setup. Both servers are internally set to listen for RDP connections on the same default port (<span class="code">3389</span>). To allow for this with just one external IP address, the firewall is told to route incoming connections on port <span class="code">3390</span> to the internal machine at IP <span class="code">10.255.0.11</span> on port <span class="code">3393</span>. Likewise, incoming connections on port <span class="code">3389</span> will be forwarded to directly to <span class="code">10.255.0.10:3389</span>.


The example below shows a setup where remote access in to the firewall itself is allowed only on port <span class="code">22869</span> (modified [[SSH]] port). Then two [[Microsoft]] Windows servers are setup. Both servers are internally set to listen for RDP connections on the same default port (<span class="code">3389</span>). To allow for this with just one external IP address, the firewall is told to route incoming connections on port <span class="code">3394</span> to the internal machine at IP <span class="code">10.254.0.11</span> on port <span class="code">3393</span>. Likewise, incoming connections on port <span class="code">3393</span> will be forwarded to <span class="code">10.254.0.10:3393</span>. A few other ports are opened for various services as further examples.
We'll also add a couple special rules that tells shorewall to respond to [[ICMP]] ping requests. Some people don't like this as ping sweeps are a quick way for malicious people to find servers on the net. Personally, I find the usefulness of being able to ping my firewall more beneficial.


Edit <span class="code">rules</span> so that the it file looks like.
Append <span class="code">rules</span> so that the it file looks like.


<source lang="bash">
<syntaxhighlight lang="bash">
vim /etc/shorewall/rules
vim /etc/shorewall/rules
</source>
</syntaxhighlight>
<source lang="text">
<syntaxhighlight lang="text">
######################################################################################################################################################################################
#ACTION        SOURCE          DEST            PROTO  DEST    SOURCE          ORIGINAL        RATE            USER/  MARK    CONNLIMIT      TIME        HEADERS        SWITCH
#                                                      PORT    PORT(S)        DEST            LIMIT          GROUP
#SECTION BLACKLIST
#SECTION ALL
#SECTION ESTABLISHED
#SECTION RELATED
 
### Rules for data going into the firewall. Consult /etc/services or your local
### Rules for data going into the firewall. Consult /etc/services or your local
### search engine for ports and protocols used by your favourite programs.
### search engine for ports and protocols used by your favourite programs.
# Allow SSH connections to the firewall itself.
# Answer ICMP queries
ACCEPT          net            fw                      tcp    22
Ping(ACCEPT) net fw
# Allow SSH and DHCP requests from the VMs into the firewall.
Ping(ACCEPT) loc fw
 
# Allow incoming SSH connections to the firewall itself from the web on port
# 22000. Allow incoming SSH connections to the firewall on port 22 and 22000
# from the local network.
ACCEPT          net            fw                      tcp    22000
ACCEPT          loc            fw                      tcp    22
ACCEPT          loc            fw                      tcp    22
ACCEPT          loc            fw                      udp     67,68
ACCEPT          loc            fw                      tcp     22000


### Forwards using DNAT
# Allow incoming connections from the internet to two windows servers listening
## Internet into 'vm0002_c6_ws1' (webserver)
# for RDP connections on the same port. This will be handled using different
#DNAT          <src>          loc:<ip>:<srv_port>    tcp    <ext_port>
# external ports using destination network address translation.
# Windows RDP Forwards
ACCEPT          net            loc:10.255.0.10:3389   tcp     3389
DNAT            net            loc:10.254.0.10:3393    tcp    3393
ACCEPT          net            loc:10.255.0.11:3389   tcp     3390
DNAT            net            loc:10.254.0.11:3393    tcp    3394
</syntaxhighlight>
# SSH forward to firewall and internal nodes.
 
DNAT            net            loc:10.255.255.254:22  tcp    22869
This is a spartan example of what you can do. It's meant to show how you can do matching and non-matching TCP port forwards. With this simple format, you should be able to create all the rules you need to setup your network.
DNAT            net            loc:10.255.0.1:22      tcp   22001
DNAT            net            loc:10.255.0.2:22      tcp   22002
DNAT            net            loc:10.255.0.3:22      tcp   22003
DNAT            net            loc:10.255.0.4:22      tcp   22004
DNAT            net            loc:10.255.0.5:22      tcp    22005
DNAT            net            loc:10.255.0.6:22      tcp    22006
DNAT            net            loc:10.255.0.7:22      tcp    22007
</source>


=== masq ===
=== masq ===


This is the file that handles [[MASQ]]erading the virtual machine LAN (the <span class="code">loc</span> zone). Even though there may be several public IP addresses, they are not [[SNAT]]ed to hosts but instead used as a pool of addresses to do Port Forward/[[DNAT]]ing on.
This is the file that handles [[MASQ]]erading the machines on the local LAN (the <span class="code">loc</span> zone). This is how shorewall provides internet access to an entire [[subnet]] of machines on a given network.


So to enable Internet access from your servers, you need to add a line with the Internet facing interface followed by the subnet that you will be MASQing.
So to enable Internet access from your machines, you need to add a line with the '''Internet facing interface''' followed by the subnet of the '''local''' network that you will be masquerading.


<source lang="bash">
<syntaxhighlight lang="bash">
vim /etc/shorewall/masq
vim /etc/shorewall/masq
</source>
</syntaxhighlight>
<source lang="text">
<syntaxhighlight lang="text">
eth1                    10.255.0.0/16
eth1                    10.255.0.0/16
</source>
</syntaxhighlight>


So that the 'rules' file looks like:
So that the <span class="code">masq</span> file looks like:


<source lang="text">
<syntaxhighlight lang="text">
###############################################################################
################################################################################################################
#INTERFACE             SOURCE          ADDRESS        PROTO  PORT(S) IPSEC  MARK    USER/
#INTERFACE:DEST        SOURCE          ADDRESS        PROTO  PORT(S) IPSEC  MARK    USER/   SWITCH  ORIGINAL
#                                                                                      GROUP
#                                                                                      GROUP           DEST
eth1                    10.255.0.0/16
eth1                    10.255.0.0/16
</source>
</syntaxhighlight>


=== shorewall.conf ===
=== shorewall.conf ===
Line 293: Line 210:
Edit <span class="code">/etc/shorewall/shorewall.conf</span> and change the following lines:
Edit <span class="code">/etc/shorewall/shorewall.conf</span> and change the following lines:


<source lang="bash">
<syntaxhighlight lang="bash">
vim /etc/shorewall/shorewall.conf
vim /etc/shorewall/shorewall.conf
</source>
</syntaxhighlight>
<source lang="text">
<syntaxhighlight lang="bash">
STARTUP_ENABLED=No
STARTUP_ENABLED=No
LOGFILE=/var/log/messages
</syntaxhighlight>
</source>


To:
To:


<source lang="text">
<syntaxhighlight lang="bash">
STARTUP_ENABLED=Yes
STARTUP_ENABLED=Yes
LOGFILE=/var/log/shorewall
</syntaxhighlight>
</source>


= Starting the Firewall =
= Starting the Firewall =
Line 312: Line 227:
To start the firewall, simply run:
To start the firewall, simply run:


<source lang="bash">
<syntaxhighlight lang="bash">
/etc/init.d/shorewall restart
/etc/init.d/shorewall restart
</source>
</syntaxhighlight>


The firewall should now be running. To see the new rules, simply run:
The firewall should now be running. To see the new rules, simply run:


<source lang="bash">
<syntaxhighlight lang="bash">
iptables-save
iptables-save
</source>
</syntaxhighlight>


This will print out the actual firewall rules. You will need some experience with <span class="code">iptables</span> to understand all their meaning, but the general flow should be understandable.
This will print out the actual firewall rules. You will need some experience with <span class="code">[[TLUG Talk: Netfilter|iptables]]</span> to understand all their meaning, but the general flow should be understandable.


Lastly, make sure the firewall starts on boot by running:
Lastly, make sure the firewall starts on boot by running:


<source lang="bash">
<syntaxhighlight lang="bash">
chkconfig shorewall on
chkconfig shorewall on
</source>
</syntaxhighlight>
 
== Fixing SELinux Problems ==
 
If you get an error like:
 
<syntaxhighlight lang="bash">
/etc/init.d/shorewall start
</syntaxhighlight>
<syntaxhighlight lang="text">
Compiling...
Can't exec "/usr/lib/shorewall/getparams": Permission denied at /usr/share/perl5/Shorewall/Config.pm line 5041.
  ERROR: Processing of /etc/shorewall/params failed
</syntaxhighlight>
 
If we check <span class="code">/var/log/audit/audit.log</span>, we see:
 
<syntaxhighlight lang="text">
type=AVC msg=audit(1403851868.309:165): avc:  denied  { execute_no_trans } for  pid=11114 comm="perl" path="/usr/lib/shorewall/getparams" dev=sda3 ino=1705335 scontext=unconfined_u:system_r:shorewall_t:s0 tcontext=system_u:object_r:lib_t:s0 tclass=file
</syntaxhighlight>
 
To fix this, run:
 
<syntaxhighlight lang="text">
semanage fcontext -a -t bin_t /usr/lib/shorewall/getparams
restorecon -vF /usr/lib/shorewall/getparams
</syntaxhighlight>
 
Now <span class="code">shorewall</span> should start properly.
 
<syntaxhighlight lang="bash">
/etc/init.d/shorewall start
</syntaxhighlight>
<syntaxhighlight lang="text">
Compiling...
Shorewall configuration compiled to /var/lib/shorewall/.start
Starting Shorewall....
done.
</syntaxhighlight>


{{footer}}
{{footer}}

Latest revision as of 22:21, 5 May 2015

 AN!Wiki :: How To :: Shorewall on RPM-based Servers

This covers setup and maintenance of Shorewall 4.5 on Red Hat Enterprise Linux 5.x, 6.x, RHEL derivatives and several recent Fedora releases.

Install

Note: Updated on 2015-05-05 for Shorewall release 4.6.8.

Install is trivial, we just need to install dependencies and and the latest RPMs.

yum install perl perl-Digest-SHA perl-Digest-SHA1

You can check for the latest version here.

rpm -Uvh http://canada.shorewall.net/pub/shorewall/4.6/shorewall-4.6.8/shorewall-core-4.6.8-0base.noarch.rpm \
         http://canada.shorewall.net/pub/shorewall/4.6/shorewall-4.6.8/shorewall-4.6.8-0base.noarch.rpm

Done!

Setup

You need to decide which interface will have your internet connection on it and which will connect to your internal network. For this tutorial;

  • eth0; Faces the internal network, has the IP 10.255.255.254/16 and provides DHCP services to the LAN.
  • eth1; Faces the Internet.

Configuring Shorewall

All configuration files are in the /etc/shorewall directory, unless explicitly defined. The main Shorewall configuration file, which we will edit last is /etc/shorewall/shorewall.conf.

The files to edit are listed in the order we will edit them in the following subsections.

zones

This controls the main "zones" used by Shorewall. The fw is special in that it defines the firewall itself. The net zone is the Internet-facing network (eth1 in this tutorial). The loc is the local network, the internal network of machines the firewall is protecting, which is eth0 in this tutorial. Both eth0 and eth1 are ipv4 networks.

Append two new lines telling shorewall that we have two new ipv4 networks that it will use:

vim /etc/shorewall/zones
net     ipv4
loc     ipv4

So that the zones file looks like:

###############################################################################
#ZONE   TYPE            OPTIONS         IN                      OUT
#                                       OPTIONS                 OPTIONS
fw      firewall
net     ipv4
loc     ipv4

interfaces

Just above, we told shorewall that we had two new ipv4 networks. In the interfaces configuration file, we link these networks to physical interfaces.

Note: If you plan to setup a DHCP server on your firewall, you will need to specify the dhcp option, as shown here. You can see a full list of options and their uses on Shorewall's interfaces page.

To link the new networks to the physical interfaces, append the following entries;

vim /etc/shorewall/interfaces
loc             eth0                    dhcp
net             eth1

So that the interfaces file looks like:

###############################################################################
?FORMAT 2
###############################################################################
#ZONE           INTERFACE               OPTIONS
loc             eth0                    dhcp
net             eth1

policy

Here you tell shorewall what the default policy is for each network when receiving new connection requests. You don't need to worry about ESTABLISHED and RELATED connections as shorewall handles these rules. The choices are:

  • ACCEPT; Accept the connection.
  • DROP; Ignore the connection request.
  • REJECT; Return an appropriate error to the connection request.

You can also set the log level for connection requests that fall off the chain and hit these policies. It's a good idea to log info level so you can see twits trying to do "bad things(tm)". The one downside to using info is that it pushes a lot of data into the log files, which might make debugging other issues on the firewall. It's really up to you in the end.

Append the following default policies;

vim /etc/shorewall/policy
# Let everything from the firewall machine out onto the net.
fw      net     ACCEPT

# Likewise, allow everything from the firewall out onto the local network.
fw      loc     ACCEPT

# Don't allow incoming connections from the web into the fireall *or* into the
# local network. Add 'info' here if you want to log failed connection attempts.
net     all     DROP            info

# Don't allow incoming connections from the local network into the firewall.
loc     fw      DROP

# Let machines on the local network out onto the web
loc     net     ACCEPT

So that the policy file looks like:

###############################################################################
#SOURCE DEST    POLICY          LOG     LIMIT:          CONNLIMIT:
#                               LEVEL   BURST           MASK

# Let everything from the firewall machine out onto the net.
fw      net     ACCEPT

# Likewise, allow everything from the firewall out onto the local network.
fw      loc     ACCEPT

# Don't allow incoming connections from the web into the fireall *or* into the
# local network. Add 'info' here if you want to log failed connection attempts.
net     all     DROP            info

# Don't allow incoming connections from the local network into the firewall.
loc     fw      DROP

# Let machines on the local network out onto the web
loc     net     ACCEPT

rules

This is really the heart of the firewall.

Here you tell shorewall what the exceptions there are to the default policies. The first rule to match is used.

The example below shows a setup where remote access in to the firewall itself is allowed only on port 22000 (modified SSH port). Then two Microsoft Windows servers are setup. Both servers are internally set to listen for RDP connections on the same default port (3389). To allow for this with just one external IP address, the firewall is told to route incoming connections on port 3390 to the internal machine at IP 10.255.0.11 on port 3393. Likewise, incoming connections on port 3389 will be forwarded to directly to 10.255.0.10:3389.

We'll also add a couple special rules that tells shorewall to respond to ICMP ping requests. Some people don't like this as ping sweeps are a quick way for malicious people to find servers on the net. Personally, I find the usefulness of being able to ping my firewall more beneficial.

Append rules so that the it file looks like.

vim /etc/shorewall/rules
### Rules for data going into the firewall. Consult /etc/services or your local
### search engine for ports and protocols used by your favourite programs.
# Answer ICMP queries
Ping(ACCEPT)	net		fw
Ping(ACCEPT)	loc		fw

# Allow incoming SSH connections to the firewall itself from the web on port
# 22000. Allow incoming SSH connections to the firewall on port 22 and 22000
# from the local network.
ACCEPT          net             fw                      tcp     22000
ACCEPT          loc             fw                      tcp     22
ACCEPT          loc             fw                      tcp     22000

# Allow incoming connections from the internet to two windows servers listening
# for RDP connections on the same port. This will be handled using different
# external ports using destination network address translation.
ACCEPT          net             loc:10.255.0.10:3389    tcp     3389
ACCEPT          net             loc:10.255.0.11:3389    tcp     3390

This is a spartan example of what you can do. It's meant to show how you can do matching and non-matching TCP port forwards. With this simple format, you should be able to create all the rules you need to setup your network.

masq

This is the file that handles MASQerading the machines on the local LAN (the loc zone). This is how shorewall provides internet access to an entire subnet of machines on a given network.

So to enable Internet access from your machines, you need to add a line with the Internet facing interface followed by the subnet of the local network that you will be masquerading.

vim /etc/shorewall/masq
eth1                    10.255.0.0/16

So that the masq file looks like:

################################################################################################################
#INTERFACE:DEST         SOURCE          ADDRESS         PROTO   PORT(S) IPSEC   MARK    USER/   SWITCH  ORIGINAL
#                                                                                       GROUP           DEST
eth1                    10.255.0.0/16

shorewall.conf

Once you have the above files in place, you need to enable the firewall.

Edit /etc/shorewall/shorewall.conf and change the following lines:

vim /etc/shorewall/shorewall.conf
STARTUP_ENABLED=No

To:

STARTUP_ENABLED=Yes

Starting the Firewall

To start the firewall, simply run:

/etc/init.d/shorewall restart

The firewall should now be running. To see the new rules, simply run:

iptables-save

This will print out the actual firewall rules. You will need some experience with iptables to understand all their meaning, but the general flow should be understandable.

Lastly, make sure the firewall starts on boot by running:

chkconfig shorewall on

Fixing SELinux Problems

If you get an error like:

/etc/init.d/shorewall start
Compiling...
Can't exec "/usr/lib/shorewall/getparams": Permission denied at /usr/share/perl5/Shorewall/Config.pm line 5041.
   ERROR: Processing of /etc/shorewall/params failed

If we check /var/log/audit/audit.log, we see:

type=AVC msg=audit(1403851868.309:165): avc:  denied  { execute_no_trans } for  pid=11114 comm="perl" path="/usr/lib/shorewall/getparams" dev=sda3 ino=1705335 scontext=unconfined_u:system_r:shorewall_t:s0 tcontext=system_u:object_r:lib_t:s0 tclass=file

To fix this, run:

semanage fcontext -a -t bin_t /usr/lib/shorewall/getparams
restorecon -vF /usr/lib/shorewall/getparams

Now shorewall should start properly.

/etc/init.d/shorewall start
Compiling...
Shorewall configuration compiled to /var/lib/shorewall/.start
Starting Shorewall....
done.

 

Any questions, feedback, advice, complaints or meanderings are welcome.
Alteeve's Niche! Enterprise Support:
Alteeve Support
Community Support
© Alteeve's Niche! Inc. 1997-2024   Anvil! "Intelligent Availability®" Platform
legal stuff: All info is provided "As-Is". Do not use anything here unless you are willing and able to take responsibility for your own actions.