Portranges mit PF mappen

Einen wunderschönen guten Tag wünsche ich allerseits.
Ich hab ein kleines Problem mit pf unter FreeBSD 6.1, und zwar versuche ich Portranges zu einem in einem Jail laufenden Dienst (bittorrent und pureftpd) durchzureichen, scheitere aber kläglich.
Meine pf.conf
Code:
# Macros: define common values, so they can be referenced and changed easily.
ext_if="tun0"   # replace with actual external interface name i.e., dc0
int_if="xl0"    # replace with actual internal interface name i.e., dc1
vpn_if="tun1"
www_addr="192.168.8.253"
ftp_addr="192.168.8.251"
p2p_addr="192.168.8.252"
xenon="192.168.8.50"
internal_net="192.168.8.0/24"
external_addr="tun1"
ipphone="192.168.8.3"

# Tables: similar to macros, but more flexible for many addresses.
#table <foo> { 10.0.0.0/8, !10.1.0.0/16, 192.168.0.0/24, 192.168.1.18 }
table <firewall> const { self }

set skip on lo0

# Normalization: reassemble fragments and resolve or reduce traffic ambiguities.
scrub in all

# Translation: specify how addresses are to be mapped or redirected.
# nat: packets going out through $ext_if with source address $internal_net will
# get translated as coming from the address of $ext_if, a state is created for
# such packets, and incoming packets will be redirected to the internal address.
nat on $ext_if from $internal_net to any -> ($ext_if)

rdr on $ext_if proto tcp from any to any port 80 -> $www_addr port 80
rdr on $ext_if proto tcp from any to any port 443 -> $www_addr port 443
rdr on $ext_if proto tcp from any to any port 21 -> $ftp_addr port 21
rdr on $ext_if proto tcp from any to any port 45000:50000 -> $ftp_addr
rdr on $ext_if proto tcp from any to any port 9881:9888 -> $p2p_addr port 9881:9888
rdr on $ext_if proto tcp from any to any port 8662 -> $p2p_addr port 8662
rdr on $ext_if proto tcp from any to any port 49160:49300 -> $p2p_addr port 49160:49300
rdr on $ext_if proto udp from any to any port 49160:49300 -> $p2p_addr port 49160:49300
rdr on $ext_if proto tcp from any to any port 41300 -> $xenon port 41300
rdr on $ext_if proto udp from any to any port 41300 -> $xenon port 41300

# Filtering: the implicit first two rules are
pass in all
pass out all

pass in  on $int_if from 192.168.8.0/24 to 192.168.8.254
pass out on $int_if from 192.168.8.254 to 192.168.8.0/24
pass in  on $int_if from 172.16.0.1/24 to 192.168.8.254
pass out on $int_if from 192.168.8.254 to 172.16.0.1/24
pass out on $ext_if proto tcp all modulate state flags S/SA
pass out on $ext_if proto { udp, icmp, gre } all keep state

block return log on $ext_if all
pass  in  on $ext_if proto tcp from any to any port 1194 keep state
pass  in  on $ext_if proto tcp from any to $www_addr port 443 keep state
pass  in  on $ext_if proto tcp from any to $www_addr port 80 keep state
pass  in  on $ext_if proto tcp from any to $ftp_addr port 21 keep state
pass  in  on $ext_if proto tcp from any to $ftp_addr port 45000:50000 keep state
pass  in  on $ext_if proto tcp from any to $p2p_addr port 8662 keep state
pass  in  on $ext_if proto tcp from any to $p2p_addr port 9881:9888 keep state
pass  in  on $ext_if proto tcp from any to $p2p_addr port 49160:49300 keep state
pass  in  on $ext_if proto udp from any to $p2p_addr port 49160:49300 keep state
pass  in  on $ext_if proto udp from any to any port 7400:7402 keep state
pass  in  on $ext_if proto tcp from any to any port 7400:7402 keep state
pass  in  on $ext_if proto tcp from any to any port 58713 keep state
pass  in  on $ext_if proto udp from any to any port 58713 keep state
pass  in  on $ext_if proto tcp from any to any port 41300 keep state
pass  in  on $ext_if proto udp from any to any port 41300 keep state

pass  out on $ext_if proto { tcp, udp, gre } all keep state
pass  on  $ext_if inet proto icmp all icmp-type 8 code 0 keep state
pass  out on $ext_if proto udp all keep state

Der Teil von Interesse ist:
Code:
rdr on $ext_if proto tcp from any to any port 45000:50000 -> $ftp_addr
rdr on $ext_if proto tcp from any to any port 49160:49300 -> $p2p_addr port 49160:49300
rdr on $ext_if proto udp from any to any port 49160:49300 -> $p2p_addr port 49160:49300
pass  in  on $ext_if proto tcp from any to $ftp_addr port 45000:50000 keep state
pass  in  on $ext_if proto tcp from any to $p2p_addr port 49160:49300 keep state
pass  in  on $ext_if proto udp from any to $p2p_addr port 49160:49300 keep state
Habe mich an:
$p2p_addr port 49160:49300
$p2p_addr
$p2p_addr port 49160:*
versucht, keine der Varianten brachte den erwünschten Effekt.
Wäre nett wenn jemand Licht in mein Dunkel bringen könnte. Sonstige Kommentare zu Dummheiten meinerseits bzw. Verbesserungsvorschläge sind natürlich auch willkommen.
 
Das isses nich. Zur Verdeutlichung sollte ich am end dazusagen das alle Regel die einzelne Ports mappen wunderbar funzen. Habe es eben mal exemplarisch an Port 80 getestet. Wenn ich die pass regel rausnehme ist der nicht mehr erreichbar.
Danke aber für den Hinweis :)
edit: habe jetzt Spasseshalber die pass in regel mal in
pass in on $ext_if proto tcp from any to $p2p_addr port 49159><49301 keep state
geändert wie in http://www.bsdforen.de/showthread.php?t=1687 vorgeschlagen, ohne erfolg...
 
Zuletzt bearbeitet:
Hoi,

also auf 6.1 hab ich das noch nie versucht. Auf der 6.2 habe port fwd mit ranges jedoch problemlos am Start.

ggf. schaust mal auf http://www.openbsd.org/faq/pf/rdr.html nochmal nach, da gibts auch entsprechend Beispiele und Erklärungen hierzu.

Für den Anfang würde ich mal die Config auf ein Minimum reduzieren, um beim Testen da einen besseren Überblick zu bekommen.

Bezüglich FTP solltest Du Dir mal http://www.openbsd.org/faq/pf/ftp.html ansehen.

Gruß Bummibaer
 
Hmm hab mich da jetzt mal durchgewühlt bin aber nicht wirklich schlauer als vorher.
Was mich kurz ins Grübeln brachte war:
Translated packets must still pass through the filter engine and will be blocked or passed based on the filter rules that have been defined.[...]
Also be aware that since translation occurs before filtering, the filter engine will see the translated packet as it looks after it's had its destination IP address and/or destination port changed to match the redirection address/port specified in the rdr rule.
Schön und gut, aber die einzelnen Ports gehen ja, lediglich die ranges funzen nicht, das macht mich stutzig...
@Bummibaer kannst du mal auszüge aus deiner pf.conf posten?
 
aus meiner nicht, aber ich zeig dir mal wie es auf dem Testserver z.B. aussieht:
...
vip_ports = "{ 4000:4009, 5004, 5005, 5060, 10010 }"
vip = "10.0.0.1"
...
nat on $ext_if inet from $local_net to any -> ($ext_if)
...
rdr on $ext_if inet proto udp from any to ($ext_if) port $vip_ports -> $vip
...
weiter unten dann die entsprechende pass rule noch, is klar. Alternativ kann man z.b. auch rdr pass on ... nehmen wenn gewünscht.

Gruß Bummibaer
 
Habe jetzt die pass und die rdr regel zusammengefügt und die ports inne variable gepackt. habe jetzt also:
p2p_addr="192.168.8.252"
bt_ports="49160:49300"
rdr pass on $ext_if proto tcp from any to any port $bt_ports -> $p2p_addr
rdr pass on $ext_if proto udp from any to any port $bt_ports -> $p2p_addr.
Damit sollte das alles etwas übersichtlicher werden, der durchblick lässt aber auf sich warten. Tausche ich die bt_ports gegen port 80 aus (in dem jail läuft auch lighttpd) funktioniert das auf anhieb, ein Portscan des Jails bzw netstat/sockstat verrät das Torrentflux auf den entsprechenden Ports läuft. Es müßte also an der Defintion der Range liegen, finde da aber keinen Fehler.. bin ratlos..

Du willst die ports in "{ ..... }" setzen :)
 
Zuletzt bearbeitet von einem Moderator:
Code:
rdr on $ext_if proto tcp from any to any port 45000:50000 -> $ftp_addr
rdr on $ext_if proto tcp from any to any port 9881:9888 -> $p2p_addr port 9881:9888
rdr on $ext_if proto tcp from any to any port 8662 -> $p2p_addr port 8662
rdr on $ext_if proto tcp from any to any port 49160:49300 -> $p2p_addr port 49160:49300
rdr on $ext_if proto udp from any to any port 49160:49300 -> $p2p_addr port 49160:49300

vieleicht liegt es da dran das die portrange vom torrent in der weitergeleiteten port range der ftp ports ist :)
 
Code:
rdr on $ext_if proto tcp from any to any port 45000:50000 -> $ftp_addr
rdr on $ext_if proto tcp from any to any port 9881:9888 -> $p2p_addr port 9881:9888
rdr on $ext_if proto tcp from any to any port 8662 -> $p2p_addr port 8662
rdr on $ext_if proto tcp from any to any port 49160:49300 -> $p2p_addr port 49160:49300
rdr on $ext_if proto udp from any to any port 49160:49300 -> $p2p_addr port 49160:49300

vieleicht liegt es da dran das die portrange vom torrent in der weitergeleiteten port range der ftp ports ist :)

Arghhh!!1
Du bist mein Held danke :)
Ja, daran lag es. Tausend Dank für den netten Hinweis auf einen allzu offensichtlichen Fehler.
Es geht :cool:
 
Zurück
Oben