iptables - Kann mir das script mal einer erklären ?

Post Reply
Message
Author
ipt

iptables - Kann mir das script mal einer erklären ?

#1 Post by ipt »

Ich habe folgendes Script gefunden ... ich suche eine Firewall mit iptables, allerdings verwirrt mich dieses Script völlig :(

wenn ich diese Regeln bei mir anwende, dann ist soweit alles geschützt und ssh ist von außen offen.
Wenn ich jedoch mit

iptables -A INPUT -i ppp0 -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -i ppp0 -p udp --dport 21 -j ACCEPT

den Port für ftp freigeben will, so funktioniert das nicht ?

wie kann ich mit diesem Script Ports später temporär freigeben und wieder schließen ?

DANKE

#!/bin/sh

dev_world=ppp0
dev_int=eth1

addr_int=192.168.100.254
net_int=192.168.100.0/24

modprobe ip_tables
modprobe iptable_filter
modprobe ipt_MASQUERADE
modprobe ipt_MIRROR
modprobe ipt_REJECT
modprobe ipt_TCPMSS
modprobe ipt_state
modprobe ipt_mac
modprobe ipt_tcpmss
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp

iptables -F
iptables -t nat -F



# Define new chains
iptables -N BLOCK
iptables -N EXT-INT
iptables -N INT-EXT
iptables -N ICMP-DENY
iptables -N INT-IF
iptables -N EXT-IF

iptables -A BLOCK -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A BLOCK -m state --state NEW -i ! $dev_world -j ACCEPT
iptables -A BLOCK -j DROP
iptables -A INPUT -j BLOCK
iptables -A FORWARD -j BLOCK

# Point to chains
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i $dev_int -s $net_int -j INT-IF
iptables -A INPUT -d ! $addr_int -i $dev_world -s ! $net_int -j EXT-IF
iptables -A INPUT -i ppp0 -p tcp -j DROP

iptables -A FORWARD -d ! $net_int -i $dev_world -s $net_int -j INT-EXT
iptables -A FORWARD -d $net_int -i $dev_int -s ! $net_int -j EXT-INT
iptables -A FORWARD -j DROP

iptables -A OUTPUT -j ACCEPT

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

# Chain Rules
iptables -A EXT-INT -j DROP

iptables -A EXT-IF -i ! $dev_world -j DROP
iptables -A EXT-IF -p tcp --dport 22 -j ACCEPT
iptables -A EXT-IF -p tcp --dport 5901 -j DROP
iptables -A EXT-IF -p tcp --dport 1024: -j DROP
iptables -A EXT-IF -p udp --dport 1024: -j DROP
iptables -A EXT-IF -j DROP

iptables -A INT-IF -j ACCEPT

# Disable ftp
#iptables -A INPUT -i ppp0 -p udp --dport 21 -j DROP
#iptables -A INPUT -i ppp0 -p tcp --dport 21 -j DROP

# Enable IP-Forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# NAT Rules
# Standard Routing
#iptables -A POSTROUTING -t nat -o $dev_world -j MASQUERADE -s $net_int

############################## 192.168.101.1 #################################
#
iptables -A POSTROUTING -t nat -o $dev_world -j MASQUERADE -s 192.168.101.1/32
################################################################################


# Port Forwarding
#iptables -A PREROUTING -t nat -p tcp -d 192.168.1.1 --dport 5901 --to 192.168.1.2:5901 -j DNAT

ratte

Re: iptables - Kann mir das script mal einer erklären ?

#2 Post by ratte »

Hi,

sei nicht boese, aber mir fehlt die Lust, dein Script anzugucken...

Wieso nimmst du nicht einfach eine fertige Loesung, wenn du dich mit dem Thema nicht beschaeftigen willst?

Aber, um deine Frage mal kurz zu beantworten:

Iptables benutzt policies, um festzulegen, was passieren soll, wenn die chains nicht greifen.
Eine chain ist wie eine Tabelle, in der von oben nach unten nachgeguckt wird, ob eine Zeile trifft, wenn ja, wird nicht weitergeguckt. - Wenn also ein Packet von der "Tabellenzeile" 15 bearbeitet wird, wird die "Tabellenzeile" 21, die das Packet anders behandelt, gar nicht mehr verwendet. Wenn keine "Tabellenzeile", also eine Regel, trifft, kommt die policy zum Zuge.

Dies sollte dir sagen, warum dein nachtraegliches einfuegen, was in Wirklichkeit ein Anhaengen ist, nicht die gewuenschte Wirkung hat.

Du solltest wirklich einmal das Iptables-Howto lesen, versuchen zu verstehen, und dann erst fragen.

ratte

ipt

Re: iptables - Kann mir das script mal einer erklären ?

#3 Post by ipt »

hi danke für dir Antwort

... wenn ich die HOWTO verstanden hätte, dann hätte ich auch nicht gefragt <img src="http://www.pl-forum.de/UltraBoard/Images/Wilk.gif" border="0" align="middle">

wenn ich das richtig verstanden habe, dann muß ich die chains also löschen (-D) und neu definieren ???

DANKE

Post Reply