Re: Security, Distributed firewalling application...long ;-)




> Why I need a GUI & policy based framework for implementing my firewalls,
> when my requirements are static? Well, I may need to add additional role
> to a server on the LAN, if any other server fails. In fact, I intend to
> keep the services prepared on alternate servers, only not deploy them
> redundantly. Secondly, never know when needs change and something that
> is easily configured and deployed would adapt better.

No clue how to do this, I've never cared for anything like this.

My personal way of doing this is to write a small script that does 3 things:

1. Brings things to a safe init state (Flush all rules, turn off forwarding, etc.)
2. Brings things to a normal running state.
3. Brings things to a locked down state (drop everything but administrative stuff, increase logging, etc).

Then you can version the script in CVS (with comments!) which lets other people more clearly understand why you have what may ostensibly seem to be an odd rule. You also push the script around your network more easily. Finally, and most importantly, if you ever have to rebuild or upgrade getting the pretty (but admittedly nice) GUI up and running is often really annoying.

It's been my constant experience that to do things once or twice, a GUI is much nicer but to do things in a repeatable and traceable way, a script is your best friend.

Below is a short example script that may get you started.

Sam

#!/bin/bash

# ---- short *example* of an iptables script suitable for personal use
# ---- Obviously, this comes with no guarantee etc etc etc.
# ---- It is a teaching example only.

IPT='sudo /sbin/iptables'

flush()
{
 echo -n "Flushing rules and locking down filter rules... "

 $IPT -P INPUT    DROP
 $IPT -P OUTPUT   DROP
 $IPT -P FORWARD  DROP

 $IPT -F INPUT
 $IPT -F OUTPUT
 $IPT -F FORWARD

 echo done.
}

default()
{

 flush

 echo -n "Applying default profile... "

$IPT -A INPUT -i lo -j ACCEPT # allow lo to talk to us. :)
$IPT -A OUTPUT -p tcp --tcp-flags SYN SYN -j ACCEPT # TCP out OK
$IPT -A OUTPUT -p udp -j ACCEPT # UDP out OK
$IPT -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT # echo out ok
$IPT -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT # reply in ok
$IPT -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT # Conntrack
$IPT -A INPUT -m conntrack --ctstate RELATED -j ACCEPT # Conntrack
$IPT -A OUTPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT # Conntrack
$IPT -A OUTPUT -m conntrack --ctstate RELATED -j ACCEPT # Conntrack


echo done.
}


stop()
{
 echo -n "Putting filters into typical default states (ACCEPT w/ no rules)... "

 $IPT        -P INPUT       ACCEPT
 $IPT        -P OUTPUT      ACCEPT
 $IPT        -P FORWARD     ACCEPT
 $IPT -t nat -P PREROUTING  ACCEPT
 $IPT -t nat -P POSTROUTING ACCEPT
 $IPT -t nat -P OUTPUT      ACCEPT

 $IPT -t nat -F PREROUTING
 $IPT -t nat -F POSTROUTING
 $IPT -t nat -F OUTPUT
 $IPT        -F INPUT
 $IPT        -F OUTPUT
 $IPT        -F FORWARD

 echo done.
}

status()
{
 $IPT        -L
 echo ""
 $IPT -t nat -L
}

help()
{
 cat<<EOF
Ussage: $0 <profile>
flush      - set the rules to drop everything. Typically run 1st by a profile.
default    - set the iprules to be very tight. Flush is called automatically.
stop       - set the rules to be their default, very open, state.
EOF
}

# NOTE: This line is slightly dangerous. :) You really should validate input. :)
$@



Relevant Pages

  • IPTables with Virtual Interfaces and Multiple Public IPs
    ... Multiple Public IP addresses feed into a single ubuntu 7.04 server ... a server for web hosting (again port 80), ... $IPT -P FORWARD DROP ... Then at the end of the script I have ...
    (comp.os.linux.networking)
  • IPTables with Virtual Interfaces and Multiple Public IPs
    ... Multiple Public IP addresses feed into a single ubuntu 7.04 server ... a server for web hosting (again port 80), ... $IPT -P FORWARD DROP ... Then at the end of the script I have ...
    (comp.security.firewalls)
  • iptables - newbie
    ... NAT passes everything. ... this is called a choke firewall, ... $IPT -t mangle -X ... #REFUSE packets from private IPs ...
    (comp.os.linux.networking)
  • problems with my firewall
    ... I can get web server, ... # Take down the interfaces before setting up the bridge ... $IPT -P OUTPUT ACCEPT ... # Our interfaces don't have IP addresses so we have to start with the mangle ...
    (alt.os.linux)