PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Frage zum IPTABLES Script



RedNuX
07-05-2003, 14:43
Warum geht meine modifizierte Version von /etc/init.d/iptables (Gentoo-Distribution) nicht und bringt Fehler ...

/etc/init.d/iptables (unverändert)
#!/sbin/runscript
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or
# later
# $Header: /home/cvsroot/gentoo-x86/net-firewall/iptables/files/iptables.init,v 1.1 2003/03/11 21:50:24 mholzer Exp $

opts="start stop save"

depend() {
need logger net
}

start() {
ebegin "Loading iptables state and starting firewall"
# This variable is set in /etc/conf.d/iptables
if [ ! -f ${IPTABLES_SAVE} ]
then
einfo "Not starting iptables. First create some rules then run"
einfo "/etc/init.d/iptables save"
else
einfo "Restoring iptables ruleset"
/sbin/iptables-restore ${SAVE_RESTORE_OPTIONS} < ${IPTABLES_SAVE}

if [ "${ENABLE_FORWARDING_IPv4}" = "yes" ] ; then
einfo "Enabling forwarding for ipv4"
echo "1" > /proc/sys/net/ipv4/conf/all/forwarding
fi

if [ "${ENABLE_FORWARDING_IPv6}" = "yes" ] ; then
einfo "Enabling forwarding for ipv6"
echo "1" > /proc/sys/net/ipv6/conf/all/forwarding
fi
fi

eend $?
}

stop() {
ebegin "Stopping firewall and saving iptables state"
# This way we don't forget to save changes
/sbin/iptables-save ${SAVE_RESTORE_OPTIONS} > ${IPTABLES_SAVE}

# set sane defaults that disable forwarding
if [ -f /proc/sys/net/ipv4/conf/all/forwarding ] ; then
echo "0" > /proc/sys/net/ipv4/conf/all/forwarding
fi

if [ -f /proc/sys/net/ipv6/conf/all/forwarding ] ; then
echo "0" > /proc/sys/net/ipv6/conf/all/forwarding
fi

for a in `cat /proc/net/ip_tables_names`; do
iptables -F -t $a
iptables -X -t $a

if [ $a == nat ]; then
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
elif [ $a == mangle ]; then
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P INPUT ACCEPT
iptables -t mangle -P FORWARD ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
iptables -t mangle -P POSTROUTING ACCEPT
elif [ $a == filter ]; then
iptables -t filter -P INPUT ACCEPT
iptables -t filter -P FORWARD ACCEPT
iptables -t filter -P OUTPUT ACCEPT
fi
done
eend $?
}

save() {
ebegin "Saving iptables state"
/sbin/iptables-save ${SAVE_RESTORE_OPTIONS} > ${IPTABLES_SAVE}
eend $?
}



/etc/init.d/iptables(modifiziert)
#!/sbin/runscript
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or
# later
# $Header: /home/cvsroot/gentoo-x86/net-firewall/iptables/files/iptables.init,v 1.1 2003/03/11 21:50:24 mholzer Exp $

opts="start stop save"

depend() {
need logger net
}

start() {
ebegin "Loading iptables state and starting firewall"
# This variable is set in /etc/conf.d/iptables
if [ ! -f ${IPTABLES_SAVE} ]
then
einfo "Not starting iptables. First create some rules then run"
einfo "/etc/init.d/iptables save"
else
einfo "Restoring iptables ruleset"
/sbin/iptables-restore ${SAVE_RESTORE_OPTIONS} < ${IPTABLES_SAVE}

if [ "${ENABLE_FORWARDING_IPv4}" = "yes" ] ; then
einfo "Enabling forwarding for ipv4"
echo "1" > /proc/sys/net/ipv4/conf/all/forwarding

# Schnittstelle zum lokalen Netzwerk
IFACE_INT=eth1

# Internetschnittstelle
IFACE_EXT=ppp0

# Loopback device
IFACE_LO=lo


# ++ POLICIES ++
# ++++++++++++

# Default-Policies setzen - alles fliegt raus
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP


# ++ INCOMING ++
# ++++++++++++

# Soll nicht sein
iptables -A INPUT -p TCP ! --syn -m state --state NEW -j DROP

# Vom internen Netz alles erlauben
iptables -A INPUT -i $IFACE_INT -j ACCEPT

# Vom Loopback Alles erlauben
iptables -A INPUT -i $IFACE_LO -j ACCEPT

# Vom Internet: Darf nicht sein
iptables -A INPUT -i $IFACE_EXT -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i $IFACE_EXT -s 172.16.0.0/12 -j DROP
iptables -A INPUT -i $IFACE_EXT -s 192.168.0.0/24 -j DROP

# Vom Internet Erlauben von bereits initialisierten Verbindungen
iptables -A INPUT -i $IFACE_EXT -m state \ --state ESTABLISHED,RELATED -j ACCEPT


# ++ FORWARDING ++
# +++++++++++++++

# Lokal -> Internet: Alles erlauben
iptables -A FORWARD -i $IFACE_INT -o $IFACE_EXT -j ACCEPT


# Internet -> Lokales: Nur Verkehr über bereits bestehende Verbindungen erlauben
iptables -A FORWARD -i $IFACE_EXT -o $IFACE_INT -m state \
--state ESTABLISHED,RELATED -j ACCEPT




# ++ OUTGOING ++
# +++++++++++++

# Ins lokale Netzwerk: Alles erlauben
iptables -A OUTPUT -o $IFACE_INT -j ACCEPT

# Ans Loopback: Alles erlauben
iptables -A OUTPUT -o $IFACE_LO -j ACCEPT

# Ins INternet : Alles erlauben
iptables -A OUTPUT -o $IFACE_EXT -j ACCEPT


# Masquerading
iptables -A POSTROUTING -o $IFACE_EXT -t nat -j MASQUERADE


# Alles was bis hier kommt, mitprotokollieren
iptables -A OUTPUT -j LOG --log-prefix "Nicht raus: "
iptables -A FORWARD -j LOG --log-prefix "Nicht durch: "
iptables -A INPUT -j LOG --log-prefix "Nicht rein: "

fi

if [ "${ENABLE_FORWARDING_IPv6}" = "yes" ] ; then
einfo "Enabling forwarding for ipv6"
echo "1" > /proc/sys/net/ipv6/conf/all/forwarding
fi
fi

eend $?
}

stop() {
ebegin "Stopping firewall and saving iptables state"
# This way we don't forget to save changes
/sbin/iptables-save ${SAVE_RESTORE_OPTIONS} > ${IPTABLES_SAVE}

# set sane defaults that disable forwarding
if [ -f /proc/sys/net/ipv4/conf/all/forwarding ] ; then
echo "0" > /proc/sys/net/ipv4/conf/all/forwarding
fi

if [ -f /proc/sys/net/ipv6/conf/all/forwarding ] ; then
echo "0" > /proc/sys/net/ipv6/conf/all/forwarding
fi

for a in `cat /proc/net/ip_tables_names`; do
iptables -F -t $a
iptables -X -t $a

if [ $a == nat ]; then
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
elif [ $a == mangle ]; then
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P INPUT ACCEPT
iptables -t mangle -P FORWARD ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
iptables -t mangle -P POSTROUTING ACCEPT
elif [ $a == filter ]; then
iptables -t filter -P INPUT ACCEPT
iptables -t filter -P FORWARD ACCEPT
iptables -t filter -P OUTPUT ACCEPT
fi
done
eend $? "uiui, Probleme beim starten der Firewall"
}

save() {
ebegin "Saving iptables state"
/sbin/iptables-save ${SAVE_RESTORE_OPTIONS} > ${IPTABLES_SAVE}
eend $?
}


/etc/init.d/iptables start
* ERROR: "/etc/init.d/iptables" has syntax errors in it; not executing...



könnte wer ahnen warum es nicht funktioniert?? wäre super nett wenn jemand vorschläge hat ...

tuxipuxi
07-05-2003, 16:28
poste mal nur das was du veraendert hast..

RedNuX
07-05-2003, 20:46
Ich habe das eingefügt ...


# Schnittstelle zum lokalen Netzwerk
IFACE_INT=eth1

# Internetschnittstelle
IFACE_EXT=ppp0

# Loopback device
IFACE_LO=lo


# ++ POLICIES ++
# ++++++++++++

# Default-Policies setzen - alles fliegt raus
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP


# ++ INCOMING ++
# ++++++++++++

# Soll nicht sein
iptables -A INPUT -p TCP ! --syn -m state --state NEW -j DROP

# Vom internen Netz alles erlauben
iptables -A INPUT -i $IFACE_INT -j ACCEPT

# Vom Loopback Alles erlauben
iptables -A INPUT -i $IFACE_LO -j ACCEPT

# Vom Internet: Darf nicht sein
iptables -A INPUT -i $IFACE_EXT -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i $IFACE_EXT -s 172.16.0.0/12 -j DROP
iptables -A INPUT -i $IFACE_EXT -s 192.168.0.0/24 -j DROP

# Vom Internet Erlauben von bereits initialisierten Verbindungen
iptables -A INPUT -i $IFACE_EXT -m state \ --state ESTABLISHED,RELATED -j ACCEPT


# ++ FORWARDING ++
# +++++++++++++++

# Lokal -> Internet: Alles erlauben
iptables -A FORWARD -i $IFACE_INT -o $IFACE_EXT -j ACCEPT


# Internet -> Lokales: Nur Verkehr über bereits bestehende Verbindungen erlauben
iptables -A FORWARD -i $IFACE_EXT -o $IFACE_INT -m state \
--state ESTABLISHED,RELATED -j ACCEPT




# ++ OUTGOING ++
# +++++++++++++

# Ins lokale Netzwerk: Alles erlauben
iptables -A OUTPUT -o $IFACE_INT -j ACCEPT

# Ans Loopback: Alles erlauben
iptables -A OUTPUT -o $IFACE_LO -j ACCEPT

# Ins INternet : Alles erlauben
iptables -A OUTPUT -o $IFACE_EXT -j ACCEPT


# Masquerading
iptables -A POSTROUTING -o $IFACE_EXT -t nat -j MASQUERADE


# Alles was bis hier kommt, mitprotokollieren
iptables -A OUTPUT -j LOG --log-prefix "Nicht raus: "
iptables -A FORWARD -j LOG --log-prefix "Nicht durch: "
iptables -A INPUT -j LOG --log-prefix "Nicht rein: "