carp, pf, nat will nicht

plepps

Active Member
Hallo,

ich versuche ausgegende verbindungen zu natten und das ganze bei einer carp/pfsync konfiguration.

genattet werden sollen ausgehenden verbindungen von einen internen host (10.100.102.67) translated auf die virt. ip (carp1 = 192.168.129.1) der firewall.

der firewallbuilder generiert mir folgendes: (jetzt bitte keine diskussion warum ichs mit diesen tool mache)

Code:
#
# Prolog script
#
set loginterface fxp0

#
# End of prolog script
#


#
# Scrub rules
#
scrub in all fragment reassemble no-df 
scrub out all random-id 



# Tables: (1)
table <tbl.r9999.d> { 10.100.199.1 , 192.168.129.1 , 10.100.199.2 , 192.168.129.2 , 192.168.127.2 } 


# 
# Rule  0 (NAT)
# 
# 
nat on carp1 proto {tcp udp icmp} from 10.100.102.67 to any -> 192.168.129.1 
# 
# Rule  backup ssh access rule
#    backup ssh access rule 
# 
pass in   quick inet proto tcp  from 10.100.105.1  to <tbl.r9999.d> port 22 keep state  label "RULE 9999 -- ACCEPT "  
# 
# Rule  0 (lo0)
# loopback connects
# 
pass in   log  quick on lo0 inet  from any  to any keep state  label "RULE 0 -- ACCEPT "  
pass out  log  quick on lo0 inet  from any  to any keep state  label "RULE 0 -- ACCEPT "  
# 
# Rule  1 (fxp2)
# for pfsync
# 
pass in   log  quick on fxp2 inet  from any  to any keep state  label "RULE 1 -- ACCEPT "  
pass out  log  quick on fxp2 inet  from any  to any keep state  label "RULE 1 -- ACCEPT "  
# 
# Rule  2 (fxp0,fxp1)
# allowthe carp protokoll
# 
pass in   log  quick on fxp0 inet proto 112  from any  to any keep state  label "RULE 2 -- ACCEPT "  
pass out  log  quick on fxp0 inet proto 112  from any  to any keep state  label "RULE 2 -- ACCEPT "  
pass in   log  quick on fxp1 inet proto 112  from any  to any keep state  label "RULE 2 -- ACCEPT "  
pass out  log  quick on fxp1 inet proto 112  from any  to any keep state  label "RULE 2 -- ACCEPT "  
# 
# Rule  3 (global)
# managment services
# 
pass in   log  quick inet proto tcp  from 10.100.0.0/16  to any port 22 keep state  label "RULE 3 -- ACCEPT "  
pass out  log  quick inet proto tcp  from 10.100.0.0/16  to any port 22 keep state  label "RULE 3 -- ACCEPT "  
# 
# Rule  4 (global)
# pinging everywhere
# 
pass in   log  quick inet proto icmp  from any  to any keep state  label "RULE 4 -- ACCEPT "  
pass out  log  quick inet proto icmp  from any  to any keep state  label "RULE 4 -- ACCEPT "  
# 
# Rule  5 (global)
# Quickly reject attempts to connect
# to ident server to avoid SMTP delays
# 
block return-rst in   log  quick inet proto tcp  from any  to any port 113  label "RULE 5 -- REJECT "  
block return-rst out  log  quick inet proto tcp  from any  to any port 113  label "RULE 5 -- REJECT "  
# 
# Rule  6 (global)
# 
# 
block return-icmp   in   log  quick inet  from any  to any  label "deny_rest"  
block return-icmp   out  log  quick inet  from any  to any  label "deny_rest"  
# 
# Rule  fallback rule
#    fallback rule 
# 
block in   quick inet  from any  to any  label "RULE 10000 -- DROP "  
block out  quick inet  from any  to any  label "RULE 10000 -- DROP "


die ssh verbindung üer die firewall hinweg klappt, aber wird eben nicht genattet.

wo ist mein fehler?

der tom


Nachtrag:
grob sieht das so aus:
Code:
External LAN 192.168.129.0/24
  ^
  |
  |   Master Firewall
 ------------------------------------
|Real external fxp1:  192.168.129.2   |
|CARP external carp1: 192.168.129.1   |fxp2 192.169.127.2
|                                     |------------------>
|CARP internal carp0: 10.100.199.1    |
|Real internal: fxp0: 10.100.199.2    | 
 -------------------------------------
  |
  |
Internal LAN 10.100.0.0/16
 
hi
sorry wenn ich mir die regen anschaue ... wird mir uebel ......
aber es geht ja nicht um den firewall builder

versuchmal

nat on carp1 from 10.100.102.67 to any -> (carp1)

alternativ mal mit pfctl -v -sn schauen ob die nat rule ueberhaupt matched.

holger
 
versuchmal
nat on carp1 from 10.100.102.67 to any -> (carp1)
holger
mit deinem vorschlag greift die nat regel nicht.

Habe das ganze jetzt soweit, das die nat regel greift. Hier mal meine derzeitige test.conf:
Code:
set loginterface fxp0

nat on fxp1 proto {tcp udp icmp} from 10.100.102.67 to any -> (carp1)
pass out on fxp1 proto tcp from 192.168.129.2 to any port 22
pass out on carp1 proto tcp from 192.168.129.1 to any port 22

pass proto { pfsync carp }

# fuer ausgehendes SSH generell
pass in   log  quick inet proto tcp from 10.100.0.0/16  to 192.168.129.99 port 22 keep state  label "ssh out"
pass out  log  quick inet proto tcp from 10.100.0.0/16  to 192.168.129.99 port 22 keep state  label "ssh out"

# adminzugang firewall
pass in quick inet proto tcp from 10.100.105.1 to { 10.100.199.1 , 10.100.199.2 } port 22 keep state  label "RULE 9999 -- ACCEPT "


block log all

jetzt wird die Verbindung zwar geNATet (sieht im pflog für mich zumindest so aus), aber nun werden die geNATeten, ausgehenden Verbindungen geblockt:

Code:
Aug 28 16:26:02.195209 rule 4/(match) pass in on fxp0: 10.100.102.67.43095 > 192.168.129.99.22: [|tcp] (DF)
Aug 28 16:26:02.195349 rule 8/(match) block out on fxp1: 192.168.129.1.62671 > 192.168.129.99.22: [|tcp] (DF)

dachte ja, das diese beiden regeln das lösen müssten:
Code:
pass out on fxp1 proto tcp from 192.168.129.2 to any port 22
pass out on carp1 proto tcp from 192.168.129.1 to any port 22
geht aber nicht.


tom
 
hi

erstmal solltest du dir im klaren sein das die reihenfolge der regeln
nicht dem entsprich was per default von openbsd vorgeshen ist.

sprich normalerweise erst options
dann nat , rdr , dann block dann die pass / allow regeln

grundsaetzlich solltest du zum testen erstmal die ganzen blocks weg lassen
und per pfctl -v -sr und pctl -v -sn testen ob die regeln matchen.

desweiteren solltest du ueberlegen was du willst und was du dann mit stateful connections erreichtst.

nat ist grundsaetzlich stateful !

was willst du von wo nach wo blocken ?
was wilst du erlauben von wo nach wo.


grundsaetzlich sollte das dan so aussehen

options

nat on fxp1 from 10.100.102.67 to any -> (carp1)
( hier war mein fehler zusagen das nat interface das carp interface ist statt dem physikalischen )

block on fxp1 all

pass quick on fxp1 from (fxp1) to any

das sollte grundsaetzlich reichen reichen um den traffic von dem 10.100 addr nach ueberall hin
mit der carp1 ip als absender addr zu naten.


natuerlich kommen hier noch die regen fuer scrub , carp und pfync dazu.

das die ausgehende verbingung von dem fxp1 interface geblock wird
liegt daran das du keine regel hast die der maschine selbst erlaubt
eine verbindung zu initieren,was bei nat aber zwingend ist.

holger
 
dann nat , rdr , dann block dann die pass / allow regeln

Um eigene Fehler zu vermeiden, oder mal irgendetwas zu übersehen, ist es möglicherweise sinnvoll, per Default alles zu blocken und dann nach und nach nur das zu erlauben, was durchkommen soll.
Dadurch kann es nicht vorkommen, dass du aus Versehen irgend ein Block-rule vergisst.
Das nur so nebenbei.
 
Da habe ich mich aber gepflegt von fwbuilder reinlegen lassen.
Is schon doof, wenn man die Reihenfolge von der Abarbeitung nicht versteht - Asche auf mein Haupt.

dachte bislang immer an Options, nat, Filter und am Ende die Default Policy. Halt in Verbindung mit die erste Regel die greift gewinnt, ansonsten greift die Default Policy.
Dem scheint ja dann nicht so zu sein.

wobei ich aber sagen muss, das ein:

set loginterface fxp0
nat on fxp1 proto {tcp udp icmp} from 10.100.102.67 to any -> (carp1)
block on fxp1 all
pass quick on fxp1 from (fxp1) to any
pass proto { pfsync carp }

nicht ausreicht, damit gehts immer noch nicht.





thx für die hilfe
tom
 
Zuletzt bearbeitet:
also ich habe jetzt eine Variante:
Code:
set loginterface fxp0

nat on fxp1 proto {tcp udp icmp} from 10.100.102.67 to any -> (carp1)
pass quick on fxp1 from (carp1) to any

pass proto { pfsync carp }

# fuer ausgehendes SSH generell
pass in   log  quick inet proto tcp from 10.100.0.0/16 to 192.168.129.99 port 22 keep state  label "ssh out"
pass out  log  quick inet proto tcp from 10.100.0.0/16 to 192.168.129.99 port 22 keep state  label "ssh out"

# adminzugang firewall
pass in quick inet proto tcp from 10.100.105.1 to { 10.100.199.1 , 10.100.199.2 } port 22 keep state  label "RULE 9999 -- ACCEPT "


block return-icmp   in   log  quick inet  from any  to any  label "deny_rest"
block return-icmp   out  log  quick inet  from any  to any  label "deny_rest"
block in   quick inet  from any  to any  label "RULE 10000 -- DROP "
block out  quick inet  from any  to any  label "RULE 10000 -- DROP "


damit gehts, wenn's auch nicht schön aussieht.

der tom
 
Zurück
Oben