O
OrBiTeR
Ik heb een script voor iptables met de volgende 2 bestanden:
acl.sh (var/bin) >Het script
lijst.txt (var/etc) > Lijst met IP nr's
De bedoeling is om bepaalde ip's alleen toegang te geven op mijn Dreambox
Hoe kan ik dit script automatisch laten opstarten. En is dit voldoende om e.e.a. te beveiligen op IP-niveau !!!
Het script acl.sh ziet er als volgt uit:
#!/bin/sh
#
#
#set -x
ACLFILE=/var/etc/lijst.txt
IPT=/sbin/iptables
DEFAULTIP1=192.168.1.1
DEFAULTIP2=192.168.1.2
DEFAULTIP3=192.168.1.3
SetACL()
{
# flush current list
$IPT -F
# allow return traffic of dreambox initiated sessions (keyupdate etc)
$IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# add some default ipnumber, in case acl file contains errors
$IPT -A INPUT -s 127.0.0.1 -j ACCEPT # add localhost
$IPT -A INPUT -s $LOCALIP -j ACCEPT # add current ipnr
$IPT -A INPUT -s $DEFAULTIP1 -j ACCEPT # for testing
$IPT -A INPUT -s $DEFAULTIP2 -j ACCEPT # for testing
$IPT -A INPUT -s $DEFAULTIP3 -j ACCEPT # for testing
# now read acl file and add these ip numbers as well
while read IPNR
do
$IPT -A INPUT -s $IPNR -j ACCEPT
done < $ACLFILE
# reject everything else
$IPT -A INPUT -j REJECT
# show user current INPUT chain
echo "New iptables INPUT chain:"
$IPT -nL INPUT
}
GetLocalIP() # get's local ipaddress ($localip)
{
a=`/sbin/ifconfig eth0 | grep inet | cut -f 2 -d ":"`
LOCALIP=${a% Bcast}
}
CheckNetpilot()
{
if [ `ps -ef | grep netpilot | grep -v grep` ]
then
$netpilot=ok #dummy actie
else
echo "netpilot not running, starting now"
/var/bin/netpilot 127.0.0.1 666 &
fi
}
Main()
{
if [ -e $ACLFILE ]
then
dos2unix $ACLFILE
GetLocalIP;
SetACL;
else
echo "File $ACLFILE does not exist!"
exit 1
fi
}
Main;
De IP lijst (lijst.txt) ziet er als volgt uit:
192.168.1.3
192.168.1.4
192.168.1.5
192.168.1.6
acl.sh (var/bin) >Het script
lijst.txt (var/etc) > Lijst met IP nr's
De bedoeling is om bepaalde ip's alleen toegang te geven op mijn Dreambox
Hoe kan ik dit script automatisch laten opstarten. En is dit voldoende om e.e.a. te beveiligen op IP-niveau !!!
Het script acl.sh ziet er als volgt uit:
#!/bin/sh
#
#
#set -x
ACLFILE=/var/etc/lijst.txt
IPT=/sbin/iptables
DEFAULTIP1=192.168.1.1
DEFAULTIP2=192.168.1.2
DEFAULTIP3=192.168.1.3
SetACL()
{
# flush current list
$IPT -F
# allow return traffic of dreambox initiated sessions (keyupdate etc)
$IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# add some default ipnumber, in case acl file contains errors
$IPT -A INPUT -s 127.0.0.1 -j ACCEPT # add localhost
$IPT -A INPUT -s $LOCALIP -j ACCEPT # add current ipnr
$IPT -A INPUT -s $DEFAULTIP1 -j ACCEPT # for testing
$IPT -A INPUT -s $DEFAULTIP2 -j ACCEPT # for testing
$IPT -A INPUT -s $DEFAULTIP3 -j ACCEPT # for testing
# now read acl file and add these ip numbers as well
while read IPNR
do
$IPT -A INPUT -s $IPNR -j ACCEPT
done < $ACLFILE
# reject everything else
$IPT -A INPUT -j REJECT
# show user current INPUT chain
echo "New iptables INPUT chain:"
$IPT -nL INPUT
}
GetLocalIP() # get's local ipaddress ($localip)
{
a=`/sbin/ifconfig eth0 | grep inet | cut -f 2 -d ":"`
LOCALIP=${a% Bcast}
}
CheckNetpilot()
{
if [ `ps -ef | grep netpilot | grep -v grep` ]
then
$netpilot=ok #dummy actie
else
echo "netpilot not running, starting now"
/var/bin/netpilot 127.0.0.1 666 &
fi
}
Main()
{
if [ -e $ACLFILE ]
then
dos2unix $ACLFILE
GetLocalIP;
SetACL;
else
echo "File $ACLFILE does not exist!"
exit 1
fi
}
Main;
De IP lijst (lijst.txt) ziet er als volgt uit:
192.168.1.3
192.168.1.4
192.168.1.5
192.168.1.6