ipfw + natd

Perikles

Member
Hallo, ich habe einen PC als Router/Gateway mit FreeBSD aufgesetzt und ärgere mich mit ipfw und natd herum, da portforwarding nicht klappt.
Internet <--> (rl0/tun0) Gateway (nve0) <--> LAN

Hier erstmal relevante Infos:

dmesg|grep ipfw
Code:
ipfw2 (+ipv6) initialized, divert loadable, rule-based forwarding disabled, default to deny, logging disabled

/etc/rc.conf
Code:
ifconfig_nve0="inet 192.168.1.1  netmask 255.255.255.0"
ppp_enable="YES"
ppp_mode="mode"
ppp_profile="Arcor"
ifconfig_rl0="up"
gateway_enable="YES"
natd_enable="YES"
natd_interface="tun0"
natd_flags="-dynamic -f /etc/natd.rules"
natd_program="/sbin/natd"
firewall_enable="YES"
firewall_logging="YES"
firewall_script="/etc/firewall"
/etc/natd.rules
Code:
use_sockets yes
same_ports yes

# torrent
redirect_port tcp 192.168.1.9:6881 6881
redirect_port udp 192.168.1.9:6881 6881
/etc/firewall
Code:
#!/bin/sh

######## Variablen
# ipfw binary
cmd="/sbin/ipfw -q add"
# intern
iif="nve0"
# public
pif="rl0"

####### Alte Regeln löschen
/sbin/ipfw -q -f flush

####### Vorbereitungen
# Hiermit dürfen alle ins Internet
$cmd 005 divert natd all from any to any via $pif
# Erlaubt Loopbackverbindungen
$cmd 010 allow all from any to any via lo0
# Erlaubt internen Verkehr
$cmd 014 allow all from any to any via $iif keep-state 
# Stateful-Firewall
$cmd 015 check-state
# Erlaubt alle Verbindungen welche von hier initiiert wurden
$cmd 020 allow tcp from any to any out via $pif setup keep-state
# Wenn die Verbindung einmal hergestellt wurde, erlaube dieser offen zu stehen
$cmd 021 allow tcp from any to any via $pif established 

###### Spoofing verhindern

# Deny all inbound traffic from non-routable reserved address spaces
$cmd 300 deny all from 192.168.0.0/16  to any in via $pif  #RFC 1918 private IP
$cmd 301 deny all from 172.16.0.0/12   to any in via $pif  #RFC 1918 private IP
$cmd 302 deny all from 10.0.0.0/8      to any in via $pif  #RFC 1918 private IP
$cmd 303 deny all from 127.0.0.0/8     to any in via $pif  #loopback
$cmd 304 deny all from 0.0.0.0/8       to any in via $pif  #loopback
$cmd 305 deny all from 169.254.0.0/16  to any in via $pif  #DHCP auto-config
$cmd 306 deny all from 192.0.2.0/24    to any in via $pif  #reserved for docs
$cmd 307 deny all from 204.152.64.0/23 to any in via $pif  #Sun cluster
$cmd 308 deny all from 224.0.0.0/3     to any in via $pif  #Class D & E multicast

# Deny any late arriving packets
$cmd 330 deny all from any to any frag in via $pif
# Deny ACK packets that did not match the dynamic rule table
$cmd 332 deny tcp from any to any established in via $pif
# This sends a RESET to all ident packets.
$cmd 333 reset tcp from any to any 113 in via $pif

######## Offene Ports
$cmd 410 allow tcp from any to any 6881 in via $pif setup keep-state
$cmd 411 allow udp from any to any 6881 in via $pif setup keep-state
# snip
####### Alles andere aussperren
$cmd 1000 deny ip from any to any

Folgende Probleme:
- auf dem router selbst kann ich nicht pingen --> hostname lookup failure.
bei pings über die ip erhalte ich: sendto: Permission denied
aus dem LAN heraus ins Internet kann ich pingen.

forwarding klappt nicht --> Alles was auf Port 6881 ankommt wird nicht an 192.168.1.9 weitergeleitet.

Anregungen?
Danke.
 
Auf Verdacht weil ich dein Netz nicht kenne aber vielleicht hilft es. Zuerst map (alles hinaus lassen) und dann redirect. Ist ja eine Kiste mit 2 Nic! oder?

map ed0 from 192.168.1.25/24 to 0.0.0.0/0-> Nic hinaus(zb.213.54.14.44) portmap tcp/udp 20000:60000
rdr ed0 0.0.0.0/0 port 6881-> 192.168.1.25 port 6881

ed0 ist die Nic nach hinaus ins Internet
 
Hmm... ich habe keine Lust mehr auf ipfw, irgendwie läßt sich der Fehler nicht einkreisen.

Ergo: Umstieg auf pf+mpd4 hat sich gelohnt, 2 Stunden Lesen, Arbeit, Script schreiben --> fertig. :)
 
Zurück
Oben