PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : IPTables Script, Fehler??!!



Badboy2000
05.08.02, 22:29
Hi, könnte sich vielleicht mal jemand mein friewall script anschauen?
Ich wollte damit einen Router online setzen.
Die Firewall soll das interne Netz durchrouten und noch server ssh,ftp,http freigeben.
Könnt ihr mir da helfen und meine fehler korigieren?

# Flush
# -----
iptables --flush
iptables --table nat --flush
iptables -X
iptables --table nat -X
# ----------------------------------------
# Loopback freischalten
# ---------------------
iptables --append INPUT --in-interface lo -j ACCEPT
iptables --append OUTPUT --out-interface lo -j ACCEPT
# ----------------------------------------
# Sicherheitspolitik
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
# ----------------------------------------
# ----------------------------------------
# Masquerading
# ------------
echo 1 > /proc/sys/net/ipv4/ip_forward

# Set up IP FORWARDing and Masquerading
iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT
# ----------------------------------------
# ----------------------------------------
# echo 1 > /proc/sys/net/ipv4/ip_dynaddr
# ----------------------------------------
# Zugriff des internen Netzes aufs Gateway
iptables --append INPUT --in-interface eth0 -j ACCEPT
iptables --append OUTPUT --out-interface eth0 -j ACCEPT
# echo 1 > /proc/sys/net/ipv4/tcp_syncookies
# echo 1 > /proc/sys/net/ipv4/ip_always_defrag
# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
# ----------------------------------------
# Blocken von ICMP-Redirect-Paketen
for f in /proc/sys/net/ipv4/conf/*/accept_redirects; do echo 0 > $f
done
# ----------------------------------------
# Blocken von Source-Routed-Paketen
for f in /proc/sys/net/ipv4/conf/*/accept_source_route; do echo 0 > $f
done
# ----------------------------------------
# Rückkanal zu einer bestehenden Verbindung
iptables --append INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables --append OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# ----------------------------------------
# ----------------------------------------
# ICMP
#
# Benötigte ICMP-Typen freischalten
# ---------------------------------
# ping 8 und 0 ausgehend
iptables --append OUTPUT -p ICMP --icmp-type echo-request -j ACCEPT
iptables --append INPUT -p ICMP --icmp-type echo-reply -j ACCEPT
#
# source quench (4)
iptables --append OUTPUT -p ICMP --icmp-type source-quench -j ACCEPT
#
# time exceeded (11)
iptables --append OUTPUT -p ICMP --icmp-type time-exceeded -j ACCEPT
iptables --append INPUT -p ICMP --icmp-type time-exceeded -j ACCEPT
#
# parameter problem (12)
iptables --append OUTPUT -p ICMP --icmp-type parameter-problem -j ACCEPT
iptables --append INPUT -p ICMP --icmp-type parameter-problem -j ACCEPT
#
# destination unreachable (3)
iptables --append OUTPUT -p ICMP --icmp-type destination-unreachable -j ACCEPT
iptables --append INPUT -p ICMP --icmp-type destination-unreachable -j ACCEPT
iptables --append OUTPUT -p ICMP --icmp-type fragmentation-needed -j ACCEPT
iptables --append INPUT -p ICMP --icmp-type fragmentation-needed -j ACCEPT
# ---------------------------------
# HTTP
iptables --append INPUT -p TCP -s 0/0 --destination-port 80 -j ACCEPT
# HTTPS (Secure Web Server)
iptables --append INPUT -p TCP -s 0/0 --destination-port 443 -j ACCEPT
# FTP Server (Control)
iptables --append INPUT -p TCP -s 0/0 --destination-port 21 -j ACCEPT
# FTP Client (Data Port for non-PASV transfers)
iptables --append INPUT -p TCP -s 0/0 --source-port 20 -j ACCEPT
# sshd
iptables --append INPUT -p TCP -s 0/0 --destination-port 22 -j ACCEPT
# ---------------------------------
# Drop bad packets

# Accept TCP packets we want to forward from internal sources
iptables --append FORWARD -p tcp --in-interface eth0 -j ACCEPT

# Accept UDP packets we want to forward from internal sources
iptables --append FORWARD -p udp --in-interface eth0 -j ACCEPT

# If not blocked, accept any other packets from the internal interface
iptables --append FORWARD -p ALL --in-interface eth0 -j ACCEPT

# Deal with responses from the internet
iptables --append FORWARD --in-interface ppp0 -m state --state \
ESTABLISHED,RELATED -j ACCEPT

msi
05.08.02, 22:45
das leerzeichen nach dem \
:mad: :mad:
wie oft noch??

Badboy2000
05.08.02, 23:09
Und was soll das bewirken?
Ich bekomme keine Fehlermeldung.
Ich wollte doch nur wissen ob das Script so funzt wie ich das will. Ich habe meine Wünsche doch oben drüber geschrieben!
Ausserdem häuft sich mein Logfile wenn die Wall läuft!
Willst du etwa \ESTABLISHED..... in dem script schreiben?
Und was soll das bewirken?
Erklär doch mal!

msi
06.08.02, 11:46
sorry da hab ich dich wohl missverstanden. ich dachte da ist
ein fehler im script (so dass man es nicht ausführen kann) und
wenn ein leerzeichen nach dem \ kommt ist das ein Fehler.

ok. Wieso die logs zugeschissen werden weiß ich nicht,
du loggst ja nichts. was steht denn in den logfiles?
ansonsten denke ich ist das script soweit richtig,
außer dass du das forwarden von eth0 so umständlich und
oft erlaubst, POLICY auf DROP, ok
dann
akzeptierst du alle von eth0
dann akzeptierst du alle tcp von eth0
dann alle udp von eth0
und dann noch alle protokolle von eth0
(fürs forwarden)

Gruß Markus

Badboy2000
06.08.02, 12:22
So umständlich und oft?
Kannst du mir da nen konkretes Beispiel geben wie du es realisieren würdest?
Sprich also mir das im Script umbauen?

msi
06.08.02, 12:51
iptables -P FORWARD DROP #1. Zeile
....
iptables --append FORWARD --in-interface eth0 -j ACCEPT # 2. Zeile
.....
# Accept TCP packets we want to forward from internal sources
iptables --append FORWARD -p tcp --in-interface eth0 -j ACCEPT #3.
# Accept UDP packets we want to forward from internal sources
iptables --append FORWARD -p udp --in-interface eth0 -j ACCEPT #4.
# If not blocked, accept any other packets from the internal interface
iptables --append FORWARD -p ALL --in-interface eth0 -j ACCEPT #5.
# Deal with responses from the internet
iptables --append FORWARD --in-interface ppp0 -m state --state \
ESTABLISHED,RELATED -j ACCEPT #6.


so hast dus gemacht. Du lässt alle forward von eth0 in der 2. Zeile
zu. in der 3. und 4. lässt du dann extra udp und tcp nachmal zu obwohl
du in der 2. eh schon alles freigegeben hast. in der 5. gibst
du dann nochmal alles frei.
d.h. afaik zeile 3,4,5 sind überflüssig.

Gruß Markus