pf: reload nötig nach Neustart

schorsch_76

FreeBSD Fanboy
Vor ca einer Woche hab ich meinen Server von Linux auf FreeBSD 12.0-RELEASE umgestellt. Es läuft auch soweit, nur nach einem Neustart hängt das Routing zu den VMs und ich muss ein "service pf reload" machen. Ich ab die Netwerkinterfaces der VMs und von openvpn schon in der rc.conf angelegt und ich hänge mich dann mit bhyve darauf. Das klappt auch, nur die NAT Tabelle will immer neu geladen werden (nach dem Server neustart)

Any Ideas? :confused: Das Preclone sorgt dafür das pf mich nicht aussperrt wenn ein tap nicht da wäre (was passiert ist (hust)).

rc.conf
Code:
clear_tmp_enable="YES"
syslogd_flags="-ss"
sendmail_enable="NONE"
hostname="server"
keymap="de.kbd"

#################################################################################
# Network
#################################################################################
ifconfig_re0="DHCP"

# precloned interfaces for VPN, VMs and jails
cloned_interfaces="bridge0 tap0 tap1 tap2 tap3"
ifconfig_bridge0="addm tap0 up addm tap1 up addm tap2 up addm tap3 up"
ifconfig_tap0="up"
ifconfig_tap1="up"
ifconfig_tap2="up"
ifconfig_tap3="up"

ifconfig_bridge0_alias1="inet 192.168.175.1 netmask 255.255.255.0"
ifconfig_bridge0_alias2="inet 192.168.175.11-20 netmask 255.255.255.0"

#################################################################################
# important services
#################################################################################
sshd_enable="YES"
ntpd_enable="YES"
powerd_enable="YES"

#################################################################################
# kernel modules
#################################################################################
kldlist="fuse vmm tun"

# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="NO"
zfs_enable="YES"

#################################################################################
# VMs + jails
#################################################################################
vm_enable="YES"
vm_dir="zfs:zroot/VM"
vm_list="vm-www vm-mail vm-ldap"
vm_delay="5"

jail_enable="YES"

#################################################################################
# firewall
#################################################################################
pf_enable="YES"
pf_rules="/etc/pf.conf"
pflog_enable="YES"
pflog_logfile="/var/log/pflog"

openvpn_enable="YES"
gateway_enable="YES"            # Enable as LAN gateway

Und hier die pf.conf
Code:
ext_if = "re0"
int_if = "{ bridge0, tap0 }"
if = "{ re0, tap0 }"

tcp_pass        = "{ ssh, http, https, 465, 993, 25, 6667, 25000 }"
udp_pass        = "{ 53 2031 1194 }"

local_tcp_pass  = "{5901, 5902, 5903, postgresql}"
local_udp_pass  = "{ 53 }"

table <intranet> { 192.168.175.0/24, 192.168.177.0/24 }
table <bruteforce> persist

############################################
# scrub
############################################
scrub in all

#############################################
# redirections + NAT
#############################################
rdr on $ext_if inet proto tcp from any to ($ext_if) port http   -> 192.168.175.21 port http
rdr on $ext_if inet proto tcp from any to ($ext_if) port https  -> 192.168.175.21 port https

# postgres
rdr on $int_if inet proto tcp from any to $int_if  port postgresql  -> 192.168.175.21 port postgresql

# mail
rdr on $ext_if inet proto tcp from any to ($ext_if) port 25   -> 192.168.175.22 port 25
rdr on $ext_if inet proto tcp from any to ($ext_if) port 465  -> 192.168.175.22 port 465
rdr on $ext_if inet proto tcp from any to ($ext_if) port 993  -> 192.168.175.22 port 993

# irc
rdr on $ext_if inet proto tcp from any to ($ext_if) port 6667 -> 192.168.175.11 port 6667
rdr on $ext_if inet proto tcp from any to ($ext_if) port 25000 -> 192.168.175.11 port 25000


# NAT for internal
nat on $ext_if inet from <intranet> to any -> $ext_if

#############################################
# Antispoof
#############################################
antispoof for $ext_if
antispoof for $int_if

#table <intranet> { 192.168.175.0/24, 192.168.177.0/24 }
#table <bruteforce> persist


#############################################
# rules
#############################################
set skip on lo0

block all
block quick from <bruteforce>

pass quick from <intranet> to any keep state

#############################################
# Ping
#############################################
icmp_types = "{ echoreq, unreach }"
pass in inet proto icmp from any to any icmp-type { 0, 3, 8, 11 }


#############################################
# regular ports
#############################################
pass in on $if proto tcp from any to any port $tcp_pass flags S/SA keep state (max-src-conn 100, max-src-conn-rate 15/5, overload <bruteforce> flush global)
pass in on $if proto udp to any port $udp_pass keep state

# local
pass in on $int_if proto tcp from $int_if to any port $local_tcp_pass flags S/SA keep state (max-src-conn 100, max-src-conn-rate 15/5, overload <bruteforce> flush global)
pass in on $int_if proto udp to any port $local_udp_pass keep state


#############################################
# Outgoing
#############################################
pass out quick all keep state

pass in quick from <intranet> to any keep state
 
hi

ich wuerde immer ein
"block log"
machen und pflog aktivieren damit ich sehen kann was er block um ggf dann zu regieren.

ggf ein skip auf lo


holger
 
Wahrscheinlich ist eine der in der pf.conf referenzierten NICs noch nicht verfügbar, wenn pf startet.
 
Kannst du mal den Bootprozess loggen? Kurze Anleitung dazu (als root):
Code:
touch /var/log/console.log
In der Datei /etc/syslog.conf folgende Zeile aktivieren:
Code:
# uncomment this to log all writes to /dev/console to /var/log/console.log
# touch /var/log/console.log and chmod it to mode 600 before it will work
console.info                                    /var/log/console.log
Jetzt einen Reboot machen und alles was auf der Konsole landet, wird jetzt in diese Datei geschrieben.
 
Mein aktueller "Workaround"

/root/restart-pf.sh
Code:
#!/bin/sh
sleep 60
service pf reload

/etc/rc.local
Code:
/usr/local/bin/screen -dmS /root/restart-pf.sh

und rc.conf
local_enable="YES"

Gibt es einen besseren Weg?

EDIT: console.log kommt
 
Console.log

Code:
cat /var/log/console.log
Dec 30 14:09:18 mouri kernel: Dec 30 14:07:58 mouri syslogd: exiting on signal 15
Dec 30 14:09:18 mouri kernel: Setting hostuuid: 22282860-d7da-11dd-bd45-c86000dda596.
Dec 30 14:09:18 mouri kernel: Setting hostid: 0x6c869190.
Dec 30 14:09:18 mouri kernel: Starting file system checks:
Dec 30 14:09:18 mouri kernel: Mounting local filesystems:.
Dec 30 14:09:18 mouri kernel: ELF ldconfig path: /lib /usr/lib /usr/lib/compat /usr/local/lib /usr/local/lib/perl5/5.26/mach/CORE
Dec 30 14:09:18 mouri kernel: 32-bit compatibility ldconfig path: /usr/lib32
Dec 30 14:09:18 mouri kernel: Setting hostname: mouri.
Dec 30 14:09:18 mouri kernel: Setting up harvesting: PURE_RDRAND,[UMA],[FS_ATIME],SWI,INTERRUPT,NET_NG,NET_ETHER,NET_TUN,MOUSE,KEYBOARD,ATTACH,CACHED
Dec 30 14:09:18 mouri kernel: Feeding entropy: .
Dec 30 14:09:18 mouri kernel: Created clone interfaces: bridge0 tap0 tap1 tap2 tap3.
Dec 30 14:09:18 mouri kernel: Starting dhclient.
Dec 30 14:09:18 mouri kernel: re0: no link .....
Dec 30 14:09:18 mouri kernel:  got link
Dec 30 14:09:18 mouri kernel: DHCPREQUEST on re0 to 255.255.255.255 port 67
Dec 30 14:09:18 mouri kernel: DHCPACK from 5.9.96.129
Dec 30 14:09:18 mouri kernel: bound to 5.9.96.165 -- renewal in 21600 seconds.
Dec 30 14:09:18 mouri kernel: Starting Network: lo0 re0 bridge0 tap0 tap1 tap2 tap3.
Dec 30 14:09:18 mouri kernel: lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
Dec 30 14:09:18 mouri kernel:   options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
Dec 30 14:09:18 mouri kernel:   inet6 ::1 prefixlen 128 
Dec 30 14:09:18 mouri kernel:   inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2 
Dec 30 14:09:18 mouri kernel:   inet 127.0.0.1 netmask 0xff000000 
Dec 30 14:09:18 mouri kernel:   groups: lo 
Dec 30 14:09:18 mouri kernel:   nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
Dec 30 14:09:18 mouri kernel: re0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
Dec 30 14:09:18 mouri kernel:   options=8209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC,LINKSTATE>
Dec 30 14:09:18 mouri kernel:   ether c8:60:00:dd:a5:96
Dec 30 14:09:18 mouri kernel:   inet 5.9.96.165 netmask 0xffffffe0 broadcast 5.9.96.191 
Dec 30 14:09:18 mouri kernel:   media: Ethernet autoselect (1000baseT <full-duplex>)
Dec 30 14:09:18 mouri kernel:   status: active
Dec 30 14:09:18 mouri kernel:   nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
Dec 30 14:09:18 mouri kernel: bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
Dec 30 14:09:18 mouri kernel:   ether 02:6c:86:91:90:00
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.1 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.11 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.12 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.13 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.14 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.15 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.16 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.17 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.18 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.19 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   inet 192.168.175.20 netmask 0xffffff00 broadcast 192.168.175.255 
Dec 30 14:09:18 mouri kernel:   id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
Dec 30 14:09:18 mouri kernel:   maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
Dec 30 14:09:18 mouri kernel:   root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
Dec 30 14:09:18 mouri kernel:   member: tap3 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
Dec 30 14:09:18 mouri kernel:           ifmaxaddr 0 port 7 priority 128 path cost 2000000
Dec 30 14:09:18 mouri kernel:   member: tap2 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
Dec 30 14:09:18 mouri kernel:           ifmaxaddr 0 port 6 priority 128 path cost 2000000
Dec 30 14:09:18 mouri kernel:   member: tap1 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
Dec 30 14:09:18 mouri kernel:           ifmaxaddr 0 port 5 priority 128 path cost 2000000
Dec 30 14:09:18 mouri kernel:   member: tap0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
Dec 30 14:09:18 mouri kernel:           ifmaxaddr 0 port 4 priority 128 path cost 2000000
Dec 30 14:09:18 mouri kernel:   groups: bridge 
Dec 30 14:09:18 mouri kernel:   nd6 options=9<PERFORMNUD,IFDISABLED>
Dec 30 14:09:18 mouri kernel: tap0: flags=8903<UP,BROADCAST,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
Dec 30 14:09:18 mouri kernel:   options=80000<LINKSTATE>
Dec 30 14:09:18 mouri kernel:   ether 00:bd:e2:f5:f6:00
Dec 30 14:09:18 mouri kernel:   groups: tap 
Dec 30 14:09:18 mouri kernel:   media: Ethernet autoselect
Dec 30 14:09:18 mouri kernel:   status: no carrier
Dec 30 14:09:18 mouri kernel:   nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
Dec 30 14:09:18 mouri kernel: tap1: flags=8903<UP,BROADCAST,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
Dec 30 14:09:18 mouri kernel:   options=80000<LINKSTATE>
Dec 30 14:09:18 mouri kernel:   ether 00:bd:e6:f5:f6:01
Dec 30 14:09:18 mouri kernel:   groups: tap 
Dec 30 14:09:18 mouri kernel:   media: Ethernet autoselect
Dec 30 14:09:18 mouri kernel:   status: no carrier
Dec 30 14:09:18 mouri kernel:   nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
Dec 30 14:09:18 mouri kernel: tap2: flags=8903<UP,BROADCAST,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
Dec 30 14:09:18 mouri kernel:   options=80000<LINKSTATE>
Dec 30 14:09:18 mouri kernel:   ether 00:bd:ea:f5:f6:02
Dec 30 14:09:18 mouri kernel:   groups: tap 
Dec 30 14:09:18 mouri kernel:   media: Ethernet autoselect
Dec 30 14:09:18 mouri kernel:   status: no carrier
Dec 30 14:09:18 mouri kernel:   nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
Dec 30 14:09:18 mouri kernel: tap3: flags=8903<UP,BROADCAST,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
Dec 30 14:09:18 mouri kernel:   options=80000<LINKSTATE>
Dec 30 14:09:18 mouri kernel:   ether 00:bd:ee:f5:f6:03
Dec 30 14:09:18 mouri kernel:   groups: tap 
Dec 30 14:09:18 mouri kernel:   media: Ethernet autoselect
Dec 30 14:09:18 mouri kernel:   status: no carrier
Dec 30 14:09:18 mouri kernel:   nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
Dec 30 14:09:18 mouri kernel: Starting devd.
Dec 30 14:09:18 mouri kernel: Starting pflog.
Dec 30 14:09:18 mouri kernel: 2018-12-30T14:09:18.623215+01:00 mouri pflogd 867 - - [priv]: msg PRIV_OPEN_LOG received
Dec 30 14:09:18 mouri kernel: Enabling pfno IP address found for tap0
Dec 30 14:09:18 mouri kernel: /etc/pf.conf:26: could not parse host specification
Dec 30 14:09:18 mouri kernel: no IP address found for tap0
Dec 30 14:09:18 mouri kernel: /etc/pf.conf:71: could not parse host specification
Dec 30 14:09:18 mouri kernel: pfctl: Syntax error in config file: pf rules not loaded
Dec 30 14:09:18 mouri kernel: .
Dec 30 14:09:18 mouri kernel: add host 127.0.0.1: gateway lo0 fib 0: route already in table
Dec 30 14:09:18 mouri kernel: Additional inet routing options: gateway=YES.
Dec 30 14:09:18 mouri kernel: add host ::1: gateway lo0 fib 0: route already in table
Dec 30 14:09:18 mouri kernel: add net fe80::: gateway ::1
Dec 30 14:09:18 mouri kernel: add net ff02::: gateway ::1
Dec 30 14:09:18 mouri kernel: add net ::ffff:0.0.0.0: gateway ::1
Dec 30 14:09:18 mouri kernel: add net ::0.0.0.0: gateway ::1
Dec 30 14:09:18 mouri kernel: Creating and/or trimming log files.
Dec 30 14:09:18 mouri kernel: Starting syslogd.
Dec 30 14:09:19 mouri kernel: Clearing /tmp.
Dec 30 14:09:19 mouri kernel: Starting local daemons:
Dec 30 14:09:19 mouri kernel: Updating motd:
Dec 30 14:09:19 mouri kernel: Mounting late filesystems:.
Dec 30 14:09:19 mouri kernel: Starting ntpd.
Dec 30 14:09:19 mouri kernel: Starting powerd.
Dec 30 14:09:20 mouri kernel: Starting smartd.
Dec 30 14:09:20 mouri kernel: Dec 30 14:09:20 mouri ntpd[1426]: pid file /var/db/ntp/ntpd.pid: Permission denied
Dec 30 14:09:21 mouri kernel: Starting openvpn.
Dec 30 14:09:21 mouri kernel: Configuring vt: keymap
Dec 30 14:09:21 mouri kernel:  blanktime.
Dec 30 14:09:21 mouri kernel: Performing sanity check on sshd configuration.
Dec 30 14:09:21 mouri kernel: Starting sshd.
Dec 30 14:09:21 mouri kernel: Starting cron.
Dec 30 14:09:21 mouri kernel: Starting jails:
 
Alle Vorkommen von tap0 (inkl. Makros) in Klammern einschließen, sollte helfen.

Edit: Sprich, überall wo du die Adresse von tap0 benutzt. Hier z.B.
Code:
rdr on $int_if inet proto tcp from any to $int_if  port postgresql  -> 192.168.175.21 port postgresql
 
Das wird daran liegen, dass du mehrere Interfaces im Makro nutzt. Ein Makro der Form foo = { a, b } führt ja dazu, dass zwei Regeln angelegt werden, einmal mit a und einmal mit b. Du müsstest das Makro derart gestalten, dass du sagst foo = { (a), (b) }. Dann hast du aber wieder das Problem, dass es an Stellen ungültig ist, wo du tatsächlich ein Interface angeben musst.

Mischen würde gehen, z.B.

Code:
foo_if = { a, b }
foo_addr = { (a), (b) }

... on $foo_if ... to $foo_addr ...

würde dazu führen, dass er _vier_ Regeln anlegt.

Code:
... on a ... to (a) ...
... on a ... to (b) ...
... on b ... to (a) ...
... on b ... to (b)...

wovon 2 zwar nicht ganz richtig sind, aber immerhin dürfte die Syntax passen.

Das eigtl. Problem sind mehrere Interfaces in Makros. Ich würde mit Interface-Gruppen arbeiten und die beiden Interfaces einer Gruppe zuordnen. Dann kannst du sagen
Code:
... on group ... to (group) ...
 
Zurück
Oben