Shorewall Firewall on Ubuntu Feisty VPS Part 3

So lets setup the final piece of the puzzle so we can install some packages and start coding already. If you've been following along (Part Two), we are now ready to setup the shorewall firewall. This will lock down all ports we aren't using, both tcp and udp. Go ahead and ssh into your slice from terminal and type in the code below to install the shorewall package.

CODE:
  1. sudo -i
  2. apt-get install shorewall
  3. cd /etc/shorewall


Now we need to copy some example configuration files to get us started. Note the change to "cp" for copying (you do need to type the period at the end).

CODE:
  1. cp /usr/share/doc/shorewall/default-config/interfaces .
  2. cp /usr/share/doc/shorewall/default-config/policy .
  3. cp /usr/share/doc/shorewall/default-config/rules .
  4. cp /usr/share/doc/shorewall/default-config/zones .

Now we will edit each of the files to add our own secret sauce. The first line with the "#" character is a comment instruction for you, don't type it in. Remember to use <Ctrl> + X key combination and hit the <Enter> key to save.

CODE:
  1. nano /etc/shorewall/interfaces
  2. # add the following line to the end of the interfaces file and save/exit
  3. net eth0 detect

Now lets edit the zones file.

CODE:
  1. nano /etc/shorewall/zones
  2. # add the following line to the end of the zones file and save/exit
  3. net ipv4

The policy files also needs editing.

CODE:
  1. nano /etc/shorewall/policy
  2. # add the following  3 lines to the end of the policy file, then save/exit
  3. fw net ACCEPT
  4. net all DROP info
  5. all all REJECT info

The rules file also gets some sauce. Note that if you wish Shorewall to repond to pings you have to let it know. It does not by default (see BlueNovember's comment below).

CODE:
  1. nano /etc/shorewall/rules
  2. # add the following 2 lines to the end of the rules file, then save/exit
  3. ACCEPT net fw tcp 22
  4. ACCEPT net fw tcp 80
  5. # if you want your machine to respond to pings add the following line
  6. Ping/ACCEPT net $FW

The final file we will edit is the shorewall file.

CODE:
  1. nano /etc/default/shorewall
  2. # change startup=0 to startup=1, then save/exit

Now lets restart the firewall and test it out.

CODE:
  1. # Restart firewall
  2. invoke-rc.d shorewall start

There you have it. Shorewall firewall, shaken not stirred. Now we can install some packages and start writing that application that will lead us to early retirement.

5 Responses to “Shorewall Firewall on Ubuntu Feisty VPS Part 3”


  1. Gravatar Icon 1 BlueNovember Jul 29th, 2007 at 10:13 am

    Hey there.
    A great quick-start guide.
    I think however there’s a slight mistake:

    In the lines you say to add to /etc/shorewall/rules,
    net fw tcp 22
    net fw tcp 80

    should read:
    ACCEPT net fw tcp 22
    ACCEPT net fw tcp 80

    I’m not sure if that’s actually correct, but that’s what I understood from the man pages / other sources, and it worked for me. Without the changes I get this error after following your instructions:
    (in /var/log/shorewall-init.log)
    Compiling/etc/shorewall/rules …
    ERROR: Invalid Action in rule “net fw tcp 22″

    (running ubuntu server, fiesty fawn)

    Thanks once again for the guide =)
    ~
    Blue

  2. Gravatar Icon 2 Jeff Jul 29th, 2007 at 5:00 pm

    Good catch Blue, now corrected. Thx.

  3. Gravatar Icon 3 BlueNovember Aug 5th, 2007 at 4:49 am

    Hey again. Finally finished setting up my own shorewall, and thought I’d my thoughts on bits I found annoying/tricky:

    Shorewall will not reply to pings by default. To make it reply, add the following to your rules file:
    Ping/ACCEPT net $FW

    You can also add services by name, instead of port, eg:
    ACCEPT net $FW tcp microsoft-ds
    ACCEPT net $FW tcp mysql
    ACCEPT net $FW tcp netbios-ssn
    ACCEPT net $FW tcp ftp

    …although of course this will just add the default ports, not intelligently find the ones you are listening on.

  4. Gravatar Icon 4 Jon Nov 15th, 2007 at 4:28 am

    Excellent getting started guide :-)
    Shorewall also ships with a number of macros. In the rules file, you can do the same as above, with the following:

    SSH/ACCEPT net $FW
    Web/ACCEPT net $FW
    Ping/ACCEPT net $FW

    See ‘/usr/share/shorewall/’ for a list of all macros.

  1. 1 Because I Learn » Blog Archive » Firewall Pingback on Oct 24th, 2007 at 4:10 am

Leave a Reply





July 2007
M T W T F S S
« Jun   Sep »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Categories


Random Photos

  • IMG_2035.JPG
    IMG_1983.JPG
    IMG_2033.JPG
    IMG_2021.JPG


Now Reading

Planned books:

None

Current books:

  • The Consequences of Ideas: Understanding the Concepts that Shaped Our World

    The Consequences of Ideas: Understanding the Concepts that Shaped Our World by R. C. Sproul

  • Born Standing Up

    Born Standing Up by Steve Martin

Recent books:

View full Library