BINAT Regeln unter PF - Ich schnalle das einfach nicht.

TobiasBXL

Member
Hallo,

Ich plage mich mit den NAT Regeln unter OpenBSD pf rum und komme einfach nicht weiter. Irgendetwas stimmt an meinen Regeln nicht und ich sehe es nicht.

Was ich machen will:

Ich habe zwei externe IP Adressen, nennen wir sie einfach 143.46.78.13 und 143.46.78.18.

Ich habe einen OpenBSD Rechner aufgesetzt, mit drei Netzwerkkarten, xl0, xl1 und xl2.

xl1 trägt die Adresse 143.46.78.13 und als Alias 143.46.78.18 ( fiktiv :) )
xl0 trägt die Adresse 192.168.0.1 und xl2 trägt die Adresse 192.168.2.1

Der OpenBSD Rechner ist sowohl von aussen als auch von innen über die Adressen auf xl1 und xl0 ansprechbar, xl2 wird noch nicht genutzt.

Ich möchte nun an xl0 eine DMZ hängen. Zur Zeit ist dort nur ein Rechner, der als Web Server fungieren soll, nennen wir ihn "test" mit der IP Adresse 192.168.0.15

Dabei soll "test" von aussen weiterhin exklusiv über 143.46.78.18 ansprechbar bleiben, ich will also über eine BINAT Regel arbeiten (richtig?).

Die nötige Vorarbeit in /etc/rc.conf.local, /etc/sysctl.conf usw. am System ist gemacht.

Die Regeln sehen so aus:

Code:
#/etc/pf.conf

## Macros 
SYN_ONLY="S/FSRA"
EXT_NIC="xl1"
INT_NIC="xl0"
OFFICE_NIC="xl2"

# External IP address
EXT_IP="143.46.78.13"
# Internal (DMZ) IP
INT_IP="192.168.0.1"
# Office Space ;-)
OFFICE_IP="192.168.2.1"

# Define which machines live behind the firewall and get their own outside alias

# Testrechner
TEST_EXT_IP="143.46.78.18"
TEST_IP="192.168.0.15"

# Define some common ports for later use
emailports = "{ smtp, pop3, imap, imap3, imaps, pop3s }"
webports = "{ http, https }"

# Define which ports are allowed by each of the inside clients
test_out = "{ ftp-data, ftp, ssh, domain, nntp, http, https, cvspserver, smtp }"
test_in = "{ ssh, http, https }"

## TABLES 
table <block_hosts> persist
table <private> const { 10/8, 172.16/12, 192.168/16, 224/8 }
table <clients> persist { 192.168.0.15 }

## GLOBAL OPTIONS 
set loginterface $EXT_NIC
set block-policy return

## TRAFFIC NORMALIZATION 
scrub in on $EXT_NIC all fragment reassemble
scrub out on $EXT_NIC all fragment reassemble random-id no-df

# For NFS
#scrub in on $INT_NIC all no-df
#scrub out on $INT_NIC all no-df

## QUEUEING RULES
# none so far...

## TRANSLATION RULES (NAT)

# exclude from NAT what's not explicitly defined later
no nat on $EXT_NIC from !<clients> to any

binat on $EXT_NIC from $TEST_IP to any -> $TEST_EXT_IP

rdr on $EXT_NIC proto TCP from any to $TEST_EXT_IP port $test_in -> $TEST_IP

# Redirect all FTP traffic to local ftp-proxy
rdr on $INT_NIC proto tcp from any to any port ftp -> 127.0.0.1 port 8021

## FILTER RULES 

# Block everything (inbound AND outbound on ALL interfaces) by default (catch-all)
block all
antispoof for EXT_NIC
antispoof for INT_NIC
antispoof for OFFICE_NIC

# Global filter stuff
block drop in log quick on $EXT_NIC from <block_hosts> to any
block drop in log quick on $EXT_NIC from <private> to any
block drop out log quick on $EXT_NIC from any to <private>

# Default TCP policy
block return-rst in log on $EXT_NIC proto TCP all
   pass in log quick on $EXT_NIC proto TCP from any to $EXT_IP port 22 flags $SYN_ONLY keep state
   pass in log quick on $EXT_NIC proto TCP from any to $EXT_IP port 113 flags $SYN_ONLY keep state

# Default UDP policy
block in log on $EXT_NIC proto udp all

# Default ICMP policy
block in log on $EXT_NIC proto icmp all
   pass in log quick on $EXT_NIC proto icmp from any to $EXT_IP keep state

block out log on $EXT_NIC all
   # firewall is allowed to make connections to the outside at will
   pass out log quick on $EXT_NIC from $EXT_IP to any keep state

# Allow the local interface to talk unrestricted
pass in quick on lo0 all
pass out quick on lo0 all

# Allow connections from the firewall into the internal network
pass out log on $INT_NIC from any to $INT_NIC:network keep state

# Allow FTP traffic to pass local ftp-proxy
pass in log on $EXT_NIC inet proto tcp from port ftp-data to $EXT_NIC user proxy flags S/SA keep state

# client filter rules inbound
pass in log on $EXT_NIC proto tcp from any to $TEST_IP port $test_in flags S/SA synproxy state

# client filter rules outbound
pass in log on $INT_NIC proto tcp from $TEST_IP to any port $test_out keep state

Der "test" Rechner hat seine IP Adresse fest und benutzt 192.168.0.1 als default gateway.

Nun möchte ich von aussen über 143.46.78.18 eine SSH Verbindung zu "test" aufbauen und nichts passiert. Schalte ich pf aus, dann mündet ein SSH Verbindungsversuch zu 143.46.78.18 natürlich über den Alias in einer Verbindung zum OpenBSD Rechner.

Ich komme an der Stelle nicht weiter, das mit rdr und binat habe ich nicht ausreichend verstanden, sieht jemand meinen Fehler oder kennt jemand funktionierende Setups, an denen ich mich orientieren kann?

Grüße,
Tobias

p.s.: Der lokale FTP proxy läuft, daran sollte es nicht liegen.
 
Hiro_Protagonis schrieb:
Imho kannst du bei BiNAT kein Port-redirecting vornehmen. Stattdessen muss man das 1:1 mapping so akzeptieren und halt mit pass/block rules arbeiten.

mfg

Hi,

ich habe mal scherzweiser alles aus den Regeln rausgenommen, ausser der binat Regel und eine "pass all" Regel dazugefügt. Dennoch bewegt sich nichts. Ich bin langsam ziemlich frustriert. Zurück zu iptables?! Das kann's ja wohl nicht sein...
 
Zurück
Oben