Iptables scriptfehler,....

Post Reply
Message
Author
mann mit fragen

Iptables scriptfehler,....

#1 Post by mann mit fragen »

Hi,
ich habe irgendwie einen Fehler in meinem IpTables script <img src="http://www.pl-forum.de/UltraBoard/Images/Sad.gif" border="0" align="middle">
Ich hoffe ihr könnt mir helfen.
ich poste am besten erstmal mein script, und dann einen auszug aus dem Start log (ich glaube es war /var/log/boot.msg (oder war das die datei welche die Startmeldung beinhaltet welche beim Booten oder vor dem Login gezeigt wird?)da ich aber gerade auf der Arbeit bin kann ich es nicht mit sicherheit sagen,...)

########################paketfilter script########################

#!/bin/bash
# ---------------------------------------------------------------------
# Linux-iptables-Firewallskript, Copyright (c) 2002 under the GPL
# Autogenerated by iptables Generator v1.11 (c) 2002 by Harald Bertram
# Please visit http://www.harry.homelinux.org for new versions of
# the iptables Generator (c).
#
# This Script was generated by request from:
# verdencity_rulez@web.de on: 2002-11-21 13:32.38 MET
#
# If you have questions about the iptables Generator or about
# your Firewall-Skript feel free to take a look at out website or
# send me an E-Mail to webmaster@harry.homelinux.org
#
# My special thanks are going to Lutz Heinrich (trinitywork@hotmail.com) who
# made lots of Beta-Testing and gave me lots of well qualified
# Feedback that made me able to improve the iptables Generator
# --------------------------------------------------------------------

case "$1" in
start)
echo "Starte IP-Paketfilter"

# iptables-Modul
modprobe ip_tables
# Connection-Tracking-Module
modprobe ip_conntrack
# Das Modul ip_conntrack_irc ist erst bei Kerneln >= 2.4.19 verfuegbar
modprobe ip_conntrack_irc
modprobe ip_conntrack_ftp

# Tabelle flushen
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X

# Default-Policies setzen
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

# MY_REJECT-Chain
iptables -N MY_REJECT

# MY_REJECT fuellen
iptables -A MY_REJECT -p tcp -j LOG --log-prefix "REJECT TCP "
iptables -A MY_REJECT -p tcp -j REJECT --reject-with tcp-reset
iptables -A MY_REJECT -p udp -j LOG --log-prefix "REJECT UDP "
iptables -A MY_REJECT -p udp -j REJECT --reject-with icmp-port-unreachable
iptables -A MY_REJECT -p icmp -j LOG --log-prefix "DROP ICMP "
iptables -A MY_REJECT -p icmp -j DROP
iptables -A MY_REJECT -j LOG --log-prefix "REJECT OTHER "
iptables -A MY_REJECT -j REJECT --reject-with icmp-proto-unreachable

# MY_DROP-Chain
iptables -N MY_DROP
iptables -A MY_DROP -m limit --limit 7200/h -j LOG --log-prefix "PORTSCAN DROP "
iptables -A MY_DROP -j DROP

# Alle verworfenen Pakete protokollieren
iptables -A INPUT -m state --state INVALID -j LOG --log-prefix "INPUT INVALID "
iptables -A OUTPUT -m state --state INVALID -j LOG --log-prefix "OUTPUT INVALID "
iptables -A FORWARD -m state --state INVALID -j LOG --log-prefix "FORWARD INVALID "

# Korrupte Pakete zurueckweisen
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -m state --state INVALID -j DROP
iptables -A FORWARD -m state --state INVALID -j DROP

# Stealth Scans etc. DROPpen
# Keine Flags gesetzt
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j MY_DROP
iptables -A FORWARD -p tcp --tcp-flags ALL NONE -j MY_DROP

# SYN und FIN gesetzt
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j MY_DROP
iptables -A FORWARD -p tcp --tcp-flags SYN,FIN SYN,FIN -j MY_DROP

# SYN und RST gleichzeitig gesetzt
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j MY_DROP
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN,RST -j MY_DROP

# FIN und RST gleichzeitig gesetzt
iptables -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j MY_DROP
iptables -A FORWARD -p tcp --tcp-flags FIN,RST FIN,RST -j MY_DROP

# FIN ohne ACK
iptables -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j MY_DROP
iptables -A FORWARD -p tcp --tcp-flags ACK,FIN FIN -j MY_DROP

# PSH ohne ACK
iptables -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j MY_DROP
iptables -A FORWARD -p tcp --tcp-flags ACK,PSH PSH -j MY_DROP

# URG ohne ACK
iptables -A INPUT -p tcp --tcp-flags ACK,URG URG -j MY_DROP
iptables -A FORWARD -p tcp --tcp-flags ACK,URG URG -j MY_DROP

# Loopback-Netzwerk-Kommunikation zulassen
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Connection-Tracking aktivieren
iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i ! ppp0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state ETABLISHED, RELATED -j ACCEPT

# HTTPS
iptables -A INPUT -i ppp0 -m state --state NEW -p tcp --dport 443-j ACCEPT

#####################################################################

und hier die Fehlermeldung:
##############################
...
doneRunning /etc/init.d/boot.local
/etc/startfirewall.sh: : command not found
/etc/startfirewall.sh: line 20: syntax error near unexpected token `in'
/etc/startfirewall.sh: line 20: `case "$1" in'
failedCreating /var/log/boot.msg
done<notice>killproc: kill(24,29)
Enabling syn flood protectiondone
Enabling IP forwardingdone
...
Failed services in runlevel 5: route
...
##############################################################
Ich hoffe das das jetzt nicht zuviel Platz hier im Forum beansprucht wenn ich den ganzen krempel mal hier poste, aber ohne diese infos glaube ich kaum das mir irgendjemand helfen kann...
achso, kann es sein das ich einen Fehler in meinem Routingtable habe ?
da der service route fehlgeschlagen ist,... vielleicht liegts ja auch daran das die clients hinter dem router keine Verbindung ins netz aufbauen können.Ansonsten Stimmt alles (ipadressen und so)

hope for help
euer mann mit fragen.

ratte

Re: Iptables scriptfehler,....

#2 Post by ratte »

case struktures werden zb. wie folgt aufgebaut

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
#!/bin/sh
case "$1" in
start)
# do something
;;
stop)
# do something completly different
;;
*)
# do, what is not covered above
;;
esac
</font><hr></pre></blockquote>

mann mit fragen

Re: Iptables scriptfehler,....

#3 Post by mann mit fragen »

Hey, fin ich klasse das unwissenden hier so schnell geholfen wir <img src="http://www.pl-forum.de/UltraBoard/Images/Happy.gif" border="0" align="middle">
ich habe nun ein neues Scipt, da ist das case Konstrukt wenigstens mal richtig aufgebaut,...
aber wenn ich es ausführe enthalte ich folgene Fehlermeldung:

#######################aufruf des scriptes und fehlermeldung#######################################
router:/etc # bash startfirewall.sh start
Starte IP-Paketfilter
modprobe: Can't locate module ip_contrack_irc
iptables v1.2.2: Unkown arg '--to-destination'
Try 'iptables -h' or 'iptables --help' for more information.
Bad argument '80'
Try 'iptables -h' or 'iptables --help' for more information.
router:/etc #
###################################################################################################

###########################ausgabe lsmod#####################################
router:/etc # lsmod
Module Size Used by
ipt_MASQUERADE 1200 1 (autoclean)
ipt_state 624 13 (autoclean)
ipt_REJECT 2784 3 (autoclean)
ipt_LOG 3152 8 (autoclean)
ipt_limit 960 8 (autoclean)
iptable_mangle 1728 0 (autoclean) (unused)
ip_conntrack_ftp 3184 0 (unused)
nls_iso8859-1 2880 1 (autoclean)
nls_cp437 4384 1 (autoclean)
pppoe 6736 2 (autoclean)
pppox 1088 1 (autoclean) [pppoe]
af_packet 11552 1 (autoclean)
ppp_async 6160 0 (autoclean) (unused)
ppp_generic 15040 1 (autoclean) [pppoe pppox ppp_async]
slhc 4432 0 (autoclean) [ppp_generic]
ipv6 124736 -1 (autoclean)
evdev 4160 0 (unused)
input 3072 0 [evdev]
uhci 22400 0 (unused)
usbcore 47264 1 [uhci]
ne2k-pci 4864 1 (autoclean)
8390 5856 0 (autoclean) [ne2k-pci]
3c59x 24864 1 (autoclean)
iptable_nat 12656 0 (autoclean) [ipt_MASQUERADE]
ip_conntrack 12848 3 (autoclean) [ipt_MASQUERADE ipt_state ip_conntrack_ftp iptable_nat]
iptable_filter 1728 0 (autoclean) (unused)
ip_tables 10496 10 [ipt_MASQUERADE ipt_state ipt_REJECT ipt_LOG ipt_limit iptable_mangle iptable_nat iptable_filter]
router:/etc #
########################################################################

lsmod hat mir bestätigt das das modul ip_contrack_irc wohl nicht geladen oder installiert ist!
(bzw. interpretiere ich die Ausgabe so...)
Frage1: Wozu ist dieses Modul überhaupt da?
Frage2: Wie überprüfe ich ob es installiert ist aber nur nicht geladen?

welchen kernel ich installiert habe weiss ich so gar nicht (sitze mal wieder gerade nicht zuhause)
ähm falls es weiterhilft, im Moment läuft gerade suse 7.1 oder 7.2 ...

Warum er hier probleme hat weiss ich aufgrund mangelden wissens leider auch nicht <img src="http://www.pl-forum.de/UltraBoard/Images/Sad.gif" border="0" align="middle">

# NAT fuer HTTP
iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 80 -j DNAT --to-destination
iptables -t nat -A POSTROUTING -o eth0 -p tcp --dport 80 -j SNAT --to-source $LAN_IP
iptables -A FORWARD -i ppp0 -m state --state NEW -p tcp -d --dport 80 -j ACCEPT

@ratte kannst du mir vielleicht nochmal weiterhelfen?

oder meinetwegen auch jemand anders ...

wäre echt nett!

*mann mit fragen*

ratte

Re: Iptables scriptfehler,....

#4 Post by ratte »

modprobe: Can't locate module ip_contrack_irc

kann vielleicht an

# Das Modul ip_conntrack_irc ist erst bei Kerneln >= 2.4.19 verfuegbar

liegen? Wenn du einen Kernel kleiner als 2.4.19 (mach mal auf konsole `uname -r`) hast, die Zeile im Script einfach kommentieren mit # sodass sie nicht ausgefuehrt wird.

ansonsten musst du dich mal fuer kernel und module kompilieren interessieren.

ratte

mann mit fragen

Re: Iptables scriptfehler,....

#5 Post by mann mit fragen »

Ja <img src="http://www.pl-forum.de/UltraBoard/Images/Happy.gif" border="0" align="middle">
okay habe noch nicht den richtigen Kernel, aber erstmal egal auch wenn kein irc funktioniert
(dafür wird das modul wohl da sein)
aber Hauptsache die Clients können erstmal surfen.
mit dem Backen von kernel und modulen habe ich mich schon auseinandergestzt,
ist ja auch nicht schwer (finde ich).
allerdings will er ja die Zeile mit dem PREROUTING nicht nehmen
( iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 80 -j DNAT --to-destination )
weil er über "--to-destination" meckert, warum auch immer.
und komischerweise will er die 80 auch nicht haben <img src="http://www.pl-forum.de/UltraBoard/Images/Sad.gif" border="0" align="middle">
aber das werde ich bestimmt auch noch hinbekommen....
Vielen Dank erstmal für die bisherigen Antworten,
das hat mir wirklich schon weitergeholfen!!!

der #mann_mit_fragen#

Post Reply