Ubuntu IPtables Configuration

on Oct. 3, 2013, 11:58 p.m.

This is the init.d script that's needed since ubuntu doesn't come with one.


#!/bin/bash
IPT=/sbin/iptables
IPT6=/sbin/ip6tables
IPTR=/sbin/iptables-restore
IPTCONFIG=/root/.config/fw/firewall.conf
PROG=iptables

_stop(){
### reset ipv4 iptales ###
echo "Stopping iptables..."
$IPT -F
$IPT -X
$IPT -Z
for table in $( do
$IPT -t $table -F
$IPT -t $table -X
$IPT -t $table -Z
done
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD ACCEPT
### reset ipv6 iptales ###
$IPT6 -F
$IPT6 -X
$IPT6 -Z
for table in $( do
$IPT6 -t $table -F
$IPT6 -t $table -X
$IPT6 -t $table -Z
done
$IPT6 -P INPUT ACCEPT
$IPT6 -P OUTPUT ACCEPT
$IPT6 -P FORWARD ACCEPT

}

_start(){
### add your commands here ###
echo "Starting iptables..."
$IPTR < "$IPTCONFIG"
}

# See how we were called.
case "$1" in
start)
_start
;;
stop)
_stop
;;
restart)
_stop
_start
;;
*)
echo $"Usage: $PROG {start|stop|restart}"
exit 1
esac

This is how you save it
mkdir -p /root/.config/fw/
iptables-save > /root/.config/fw/firewall.conf