set optimization normalset timeout { adaptive.start 0, adaptive.end 0 }set limit states 201000set limit src-nodes 201000# System aliasesloopback = "{ lo0 }"IPsec = "{ enc0 }"LAN = "{ vtnet1 }"WAN = "{ vtnet0 }"# SSH Lockout Tabletable <sshlockout> persisttable <webConfiguratorlockout> persist# Other tablestable <virusprot>table <bogons> persist file "/usr/local/etc/bogons"# User Aliases table <ipsec_net> { 10.10.1.0/24 } ipsec_net = "<ipsec_net>" # GatewaysGWWAN_DHCP = " route-to ( vtnet0 192.168.0.1 ) "GWNull4 = " route-to ( lo0 127.0.0.1 ) "GWNull6 = " route-to ( lo0 ::1 ) " set loginterface vtnet1set skip on pfsync0scrub on $LAN all scrub on $WAN all no nat proto carpno rdr proto carp# Outbound NAT rules (automatic)# Subnets to NAT tonatsubnets = "{ 127.0.0.0/8 192.168.2.1/32 10.10.1.0/24 }"nat on $WAN from $tonatsubnets to any port 500 -> 192.168.0.49/32 static-portnat on $WAN from $tonatsubnets to any -> 192.168.0.49/32 port 1024:65535 # Anti lockout, prevent redirects for protected ports to this interface ip no rdr on vtnet1 proto tcp from any to ( vtnet1 ) port { 443 80 }#---------------------------------------------------------------------------# default deny rules#---------------------------------------------------------------------------block in log inet all label "Default deny rule IPv4"block out log inet all label "Default deny rule IPv4"block in log inet6 all label "Default deny rule IPv6"block out log inet6 all label "Default deny rule IPv6"# IPv6 ICMP is not auxilary, it is required for operation# See man icmp6(4)# 1 unreach Destination unreachable# 2 toobig Packet too big# 128 echoreq Echo service request# 129 echorep Echo service reply# 133 routersol Router solicitation# 134 routeradv Router advertisement# 135 neighbrsol Neighbor solicitation# 136 neighbradv Neighbor advertisementpass log quick inet6 proto ipv6-icmp from any to any icmp6-type {1,2,135,136} keep state# Allow only bare essential icmpv6 packets (NS, NA, and RA, echoreq, echorep)pass out log quick inet6 proto ipv6-icmp from fe80::/10 to fe80::/10 icmp6-type {129,133,134,135,136} keep statepass out log quick inet6 proto ipv6-icmp from fe80::/10 to ff02::/16 icmp6-type {129,133,134,135,136} keep statepass in log quick inet6 proto ipv6-icmp from fe80::/10 to fe80::/10 icmp6-type {128,133,134,135,136} keep statepass in log quick inet6 proto ipv6-icmp from ff02::/16 to fe80::/10 icmp6-type {128,133,134,135,136} keep statepass in log quick inet6 proto ipv6-icmp from fe80::/10 to ff02::/16 icmp6-type {128,133,134,135,136} keep state# We use the mighty pf, we cannot be fooled.block log quick inet proto { tcp, udp } from any port = 0 to anyblock log quick inet proto { tcp, udp } from any to any port = 0block log quick inet6 proto { tcp, udp } from any port = 0 to anyblock log quick inet6 proto { tcp, udp } from any to any port = 0# SSH lockoutblock in log quick proto tcp from <sshlockout> to (self) port 22 label "sshlockout"# webConfigurator lockoutblock in log quick proto tcp from <webConfiguratorlockout> to (self) port 443 label "webConfiguratorlockout"block in log quick from <virusprot> to any label "virusprot overload table"antispoof log for $LAN antispoof log for $WAN # allow our DHCP client out to the WANpass in log on $WAN proto udp from any port = 67 to any port = 68 label "allow dhcp client out WAN"pass out log on $WAN proto udp from any port = 68 to any port = 67 label "allow dhcp client out WAN"# Not installing DHCP server firewall rules for WAN which is configured for DHCP.# loopbackpass in log on $loopback inet all label "pass IPv4 loopback"pass out log on $loopback inet all label "pass IPv4 loopback"pass in log on $loopback inet6 all label "pass IPv6 loopback"pass out log on $loopback inet6 all label "pass IPv6 loopback"# let out anything from the firewall host itself and decrypted IPsec trafficpass out log inet all keep state allow-opts label "let out anything IPv4 from firewall host itself"pass out log inet6 all keep state allow-opts label "let out anything IPv6 from firewall host itself"pass out log route-to ( vtnet0 192.168.0.1 ) from 192.168.0.49 to !192.168.0.0/24 keep state allow-opts label "let out anything from firewall host itself"pass out log on $IPsec all keep state label "IPsec internal host to host"# make sure the user cannot lock himself out of the webConfigurator or SSHpass in log quick on vtnet1 proto tcp from any to (vtnet1) port { 443 80 } keep state label "anti-lockout rule"# User-defined rules followpass in log quick on $IPsec inet from $ipsec_net to 192.168.2.1/32 keep state label "USER_RULE: Allow IPsec traffic to LAN net"pass in quick on $WAN inet proto tcp from any to 192.168.0.49 port 443 allow-opts flags S/SA keep state label "USER_RULE"pass in quick on $WAN reply-to ( vtnet0 192.168.0.1 ) inet proto esp from any to 192.168.0.49 keep state label "USER_RULE: IPSec ESP"pass in quick on $WAN reply-to ( vtnet0 192.168.0.1 ) inet proto { tcp udp } from any to 192.168.0.49 port 500 keep state label "USER_RULE: IPSec ISAKMP"pass in quick on $WAN reply-to ( vtnet0 192.168.0.1 ) inet proto { tcp udp } from any to 192.168.0.49 port 4500 keep state label "USER_RULE: IPSec NAT-T"# VPN Rulespass out log on $WAN proto udp from any to any port = 500 keep state label "IPsec: MobileIPsec - outbound isakmp"pass in log on $WAN proto udp from any to any port = 500 keep state label "IPsec: MobileIPsec - inbound isakmp"pass out log on $WAN proto udp from any to any port = 4500 keep state label "IPsec: MobileIPsec - outbound nat-t"pass in log on $WAN proto udp from any to any port = 4500 keep state label "IPsec: MobileIPsec - inbound nat-t"pass out log on $WAN proto esp from any to any keep state label "IPsec: MobileIPsec - outbound esp proto"pass in log on $WAN proto esp from any to any keep state label "IPsec: MobileIPsec - inbound esp proto"
set ruleset-optimization basicset optimization normalset timeout { adaptive.start 0, adaptive.end 0 }set limit states 201000set limit src-nodes 201000# System aliasesloopback = "{ lo0 }"IPsec = "{ enc0 }"LAN = "{ vtnet1 }"WAN = "{ vtnet0 }"# SSH Lockout Tabletable <sshlockout> persisttable <webConfiguratorlockout> persist# Other tablestable <virusprot>table <bogons> persist file "/usr/local/etc/bogons"# User Aliases table <ipsec_net> { 10.10.1.0/24 } ipsec_net = "<ipsec_net>"### define internal aliasestable <internal-enc0> { } table <internal-enc0ip> { } table <internal-lan> { 192.168.2.1 } table <internal-lanip> { 192.168.2.1 } table <internal-wan> { 192.168.0.0 } table <internal-wanip> { 192.168.0.49 } # GatewaysGWWAN_DHCP = " route-to ( vtnet0 192.168.0.1 ) "GWNull4 = " route-to ( lo0 127.0.0.1 ) "GWNull6 = " route-to ( lo0 ::1 ) " set loginterface vtnet1set skip on pfsync0scrub on $LAN all scrub on $WAN all no nat proto carpno rdr proto carp# Outbound NAT rules (automatic)# Subnets to NAT tonatsubnets = "{ 127.0.0.0/8 192.168.2.1/32 10.10.1.0/24 }"nat on $WAN from $tonatsubnets to any port 500 -> 192.168.0.49/32 static-portnat on $WAN from $tonatsubnets to any -> 192.168.0.49/32 port 1024:65535 # Anti lockout, prevent redirects for protected ports to this interface ip no rdr on vtnet1 proto tcp from any to ( vtnet1 ) port { 443 80 }antispoof log for vtnet1 antispoof log for vtnet0 #pass in log quick on lo0 inet6 from {any} to {any} label "Pass all loopback IPv6" #block in log quick inet6 from {any} to {any} label "Block all IPv6" block in log inet from {any} to {any} label "Default deny rule" block in log inet6 from {any} to {any} label "Default deny rule" pass in log quick inet6 proto ipv6-icmp from {any} to {any} icmp6-type {1,2,135,136} keep state label "IPv6 requirements (ICMP)" pass out log quick inet6 proto ipv6-icmp from {fe80::/10} to {fe80::/10,ff02::/16} icmp6-type {129,133,134,135,136} keep state label "IPv6 requirements (ICMP)" pass in log quick inet6 proto ipv6-icmp from {fe80::/10} to {fe80::/10,ff02::/16} icmp6-type {128,133,134,135,136} keep state label "IPv6 requirements (ICMP)" pass in log quick inet6 proto ipv6-icmp from {ff02::/16} to {fe80::/10} icmp6-type {128,133,134,135,136} keep state label "IPv6 requirements (ICMP)" block in log quick inet proto {tcp udp} from {any} port {0} to {any} block in log quick inet6 proto {tcp udp} from {any} port {0} to {any} block in log quick inet proto {tcp udp} from {any} to {any} port {0} block in log quick inet6 proto {tcp udp} from {any} to {any} port {0} #block in log quick proto carp from {(self)} to {any} pass in log quick proto carp from {any} to {any} block in log quick proto tcp from {<sshlockout>} to {(self)} port {22} label "sshlockout" block in log quick proto tcp from {<webConfiguratorlockout>} to {(self)} port {443} label "webConfiguratorlockout" block in log quick from {<virusprot>} to {any} label "virusprot overload table" #block in log quick on lo0 from {<bogons>} to {any} label "block bogon IPv4 networks from loopback" #block in log quick on lo0 from {<bogonsv6>} to {any} label "block bogon IPv6 networks from loopback" #block in log quick on lo0 from {10.0.0.0/8,127.0.0.0/8,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16,fc00::/7} to {any} label "Block private networks from loopback" #block in log quick on enc0 from {<bogons>} to {any} label "block bogon IPv4 networks from IPsec" #block in log quick on enc0 from {<bogonsv6>} to {any} label "block bogon IPv6 networks from IPsec" #block in log quick on enc0 from {10.0.0.0/8,127.0.0.0/8,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16,fc00::/7} to {any} label "Block private networks from IPsec" #block in log quick on vtnet1 from {<bogons>} to {any} label "block bogon IPv4 networks from LAN" #block in log quick on vtnet1 from {<bogonsv6>} to {any} label "block bogon IPv6 networks from LAN" #block in log quick on vtnet1 from {10.0.0.0/8,127.0.0.0/8,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16,fc00::/7} to {any} label "Block private networks from LAN" #block in log quick on vtnet0 from {<bogons>} to {any} label "block bogon IPv4 networks from WAN" #block in log quick on vtnet0 from {<bogonsv6>} to {any} label "block bogon IPv6 networks from WAN" #block in log quick on vtnet0 from {10.0.0.0/8,127.0.0.0/8,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16,fc00::/7} to {any} label "Block private networks from WAN" pass in log on vtnet0 proto udp from {any} port {67} to {any} port {68} label "allow DHCP client on WAN" pass out log on vtnet0 proto udp from {any} port {68} to {any} port {67} label "allow DHCP client on WAN" pass in log quick on lo0 from {any} to {any} label "pass loopback" pass out log from {any} to {any} keep state allow-opts label "let out anything from firewall host itself" pass out log on enc0 from {any} to {any} keep state label "IPsec internal host to host" pass in log quick on vtnet1 proto tcp from {any} to {(self)} port {443 80} keep state label "anti-lockout rule" pass out log route-to ( vtnet0 192.168.0.1 ) from 192.168.0.49 to !192.168.0.0/24 keep state allow-opts label "let out anything from firewall host itself"# User-defined rules followpass in log quick on $IPsec inet from $ipsec_net to 192.168.2.1/32 keep state label "USER_RULE: Allow IPsec traffic to LAN net"pass in quick on $WAN inet proto tcp from any to 192.168.0.49 port 443 allow-opts flags S/SA keep state label "USER_RULE"pass in quick on $WAN reply-to ( vtnet0 192.168.0.1 ) inet proto esp from any to 192.168.0.49 keep state label "USER_RULE: IPSec ESP"pass in quick on $WAN reply-to ( vtnet0 192.168.0.1 ) inet proto { tcp udp } from any to 192.168.0.49 port 500 keep state label "USER_RULE: IPSec ISAKMP"pass in quick on $WAN reply-to ( vtnet0 192.168.0.1 ) inet proto { tcp udp } from any to 192.168.0.49 port 4500 keep state label "USER_RULE: IPSec NAT-T"# VPN Rulespass out log on $WAN proto udp from any to any port = 500 keep state label "IPsec: MobileIPsec - outbound isakmp"pass in log on $WAN proto udp from any to any port = 500 keep state label "IPsec: MobileIPsec - inbound isakmp"pass out log on $WAN proto udp from any to any port = 4500 keep state label "IPsec: MobileIPsec - outbound nat-t"pass in log on $WAN proto udp from any to any port = 4500 keep state label "IPsec: MobileIPsec - inbound nat-t"pass out log on $WAN proto esp from any to any keep state label "IPsec: MobileIPsec - outbound esp proto"pass in log on $WAN proto esp from any to any keep state label "IPsec: MobileIPsec - inbound esp proto"