PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : masquerading



dunervst
23.04.02, 18:30
Wie mache ich masquerading für ftp ? für alles andere habe ich hinbekommen. Nur nicht für ftp.

Michael

honeymill
28.04.02, 00:39
Mit FTP ist das etwas tricky, weil hier nachdem der Client zum Server eine Verbindung aufgebaut hat, der Server eine weitere Verbindung zum Client für die Dateiübertragung aufbauen will (oder so ähnlich, bitte berichtigen!)
Jedenfalls weiß das Gateway dann für die zweite Verbindung dann nicht für welchen Rechner es die Verbindung maskieren soll. Es sei denn, dein Gateway führt Buch darüber, welcher Client zuletzt zu welchem Server eine Verbindung aufgebaut hat. Und sowas gibt es sogar :)

Bei mir sieht das wie folgt aus:
Ich hab SuSE 7.3 mit einem 2.4er Kernel und dem Netfilter/iptables Paket. Auf früheren Kerneln geht das so nicht, aber mittlerweile ist das wohl Standard.

iptables ist extrem cool. Für FTP und Masquerading kann man die Module nachladen und dann Firewalling, Masquerading und Logging in einem Skript machen. Mein Firewallskript sieht zum Beispiel so aus:

------ schnipp --------

# Deleting all rules (for stopping) be careful with this:
iptables -F
iptables -X

# Netfilter Module laden
modprobe iptable_nat
modprobe iptable_filter
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ipt_LOG
modprobe ipt_MASQUERADE

#### Masquerading
#

#### DSL masquerading for ppp0
# In the NAT table (-t nat), Append a rule (-A) after routing
# (POSTROUTING) for all packets from subnet 192.168.0.0 going out ppp0
# (-o ppp0) which says to MASQUERADE the connection (-j MASQUERADE).
iptables -t nat -A POSTROUTING -o ppp0 -s 192.168.0.0/16 -j MASQUERADE

# Turn on IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# default policy
iptables -P FORWARD DROP
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT

#### ungueltige Pakete abweisen
iptables -A INPUT -m unclean -j DROP

# timeouts haerten
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
echo 0 > /proc/sys/net/ipv4/tcp_window_scaling
echo 0 > /proc/sys/net/ipv4/tcp_sack

#Syn-flood protection:
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
#Furtive port scanner:
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
#Ping of death:
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT

#falsche Absender
iptables -t nat -A PREROUTING -i ppp0 -s 192.168.0.0/16 -j DROP
iptables -t nat -A PREROUTING -i ppp0 -s 10.0.0.0/8 -j DROP
iptables -t nat -A PREROUTING -i ppp0 -s 172.16.0.0/12 -j DROP
iptables -t nat -A PREROUTING -i ppp0 -s 127.0.0.0/8 -j DROP

iptables -A FORWARD -i ppp0 -s 192.168.0.0/16 -j DROP
iptables -A FORWARD -i ppp0 -s 10.0.0.0/8 -j DROP
iptables -A FORWARD -i ppp0 -s 72.16.0.0/12 -j DROP
iptables -A FORWARD -i ppp0 -s 127.0.0.0/8 -j DROP

### Folgende Verbindungen aus dem Internet weiterleiten
# kazaa auf laptop
iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 1214 -j DNAT --to-destination 192.168.0.2
iptables -t nat -A PREROUTING -i ppp0 -p udp --dport 1214 -j DNAT --to-destination 192.168.0.2

## Create chain which blocks new connections, except if coming from inside.
iptables -N block
# kazaa auf laptop #2
iptables -A block -i ppp0 -p tcp --dport 1214 -j ACCEPT
iptables -A block -i ppp0 -p udp --dport 1214 -j ACCEPT
iptables -A block -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A block -m state --state NEW -i ! ppp0 -j ACCEPT
iptables -A block -m limit --limit 3/minute --limit-burst 3 -j LOG --log-prefix "BLOCKED: "
iptables -A block -j DROP

## Jump to that chain from INPUT and FORWARD chains.
iptables -A INPUT -j block
iptables -A FORWARD -j block

# Logging abgewiesener Pakete
iptables -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG

------ schnipp --------

Falls du schon mit iptables arbeitest, musst du eigentlich nur die extra Module per "modprobe" (ab "# Netfilter Module laden") einbinden. Das war's.

Literatur: c't 04/2002, S. 202 ("Gut behütet: Firewall mit Linux 2.4")

Viel Spaß

Nighthawk
29.04.02, 15:21
Wichtig ist vor allem ip_conntrack_ftp für's Connection Tracking.