A local firewall for ubuntu

April 1, 2008 at 11:22 pm Leave a comment

A very simple local firewall for Ubuntu machines using iptables.

I use the following set up:

In /etc/network/if-pre-up.d, I have an executable shell script called firewall which uses iptables-restore to load firewall settings stored in /etc/network/firewall. This script is as follows:

#!/bin/bash
#/etc/network/if-pre-up.d/firewall - A script to restore a saved firewall on startup.
cat /etc/network/firewall | iptables-restore

The firewall settings file /etc/network/firewall was created using the command:

iptables-save > /etc/network/firewall

after I set up a working firewall using iptables. (See man iptables). This file currently looks like this.

#/etc/network/firewall
*filter
:INPUT ACCEPT [1745:1484069]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1763:303728]
:DROPCHAIN - [0:0]
:LOGCONNECT - [0:0]
-A INPUT -s 127.0.0.1 -p tcp -j ACCEPT
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j LOGCONNECT
-A FORWARD -j DROPCHAIN
-A LOGCONNECT -j LOG --log-prefix "IPTABLES: BLOCK TCP CONNECT"
-A LOGCONNECT -j DROP
COMMIT

This stops any forwarding and any attempts to form incoming tcp connections. Any attempts to open a connection are logged via kernel logging.

I couldn’t find an easy way to filter just these messages into a file (short off piping all appropriate messages to a process in /etc/syslogd.conf that only keeps iptables messages… though I’m sure there is a clever way of doing this).

Also, I probably should be paying attention to rpc udp packets… or something like that.

Shout at me if there is some better way of doing this.

Advertisements

Entry filed under: Uncategorized. Tags: , , .

Turning a while loop into a recursive function How to backup a directory using tar in one line.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


April 2008
M T W T F S S
« Mar   May »
 123456
78910111213
14151617181920
21222324252627
282930  

%d bloggers like this: