Changes between Initial Version and Version 1 of FreeBSD PF Firewall Examples


Ignore:
Timestamp:
03/09/21 08:45:33 (4 years ago)
Author:
Paul Kulda
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FreeBSD PF Firewall Examples

    v1 v1  
     1= FreeBSD PF Firewall Examples =
     2
     3PF Example for VPN / OPENVPN / NAT :
     4
     5{{{
     6### Interfaces ###
     7ExtIf ="em0"
     8BackIf ="em1"
     9TunIf ="tun0"
     10
     11### Services ###
     12my_ssh_services = "{ 22, 53, 2222, 2525 }"
     13my_web_services = "{ 80, 443 }"
     14
     15### Hosts / Networks / Groups ###
     16outside_ip ="111.22.33.44"
     17outside_ip6 ="111:222:333:44::5"
     18back_ip ="192.168.19.1"
     19remote_net = "192.168.1.0/24"
     20back_net = "192.168.19.0/24"
     21vpn_net = "192.168.20.0/24"
     22
     23### Options ###
     24set block-policy drop
     25set fingerprints "/etc/pf.os"
     26set ruleset-optimization none
     27
     28### Timeouts ###
     29set optimization normal
     30set timeout { tcp.closing 60, tcp.established 7200 }
     31
     32### Queues, States and Types ###
     33TcpState ="flags S/SA modulate state"
     34PlainState ="flags S/SA keep state"
     35UdpState ="keep state"
     36
     37### Stateful Tracking Options (STO) ###
     38OpenSTO = "(max 90000, source-track rule, max-src-conn 1000, max-src-nodes 256)"
     39SmtpSTO = "(max   200, source-track rule, max-src-conn   10, max-src-nodes 256, max-src-conn-rate 200/30)"
     40SshSTO  = "(max   100, source-track rule, max-src-conn   64, max-src-nodes 100, max-src-conn-rate 100/30,  overload <childrens> flush global)"
     41WebSTO  = "(max  4096, source-track rule, max-src-conn 256, max-src-nodes 512, max-src-conn-rate 500/100, overload <childrens> flush global)"
     42
     43scrub log on $ExtIf all reassemble tcp fragment reassemble
     44scrub out on $ExtIf no-df random-id
     45
     46set skip on lo0
     47
     48nat on $ExtIf from $vpn_net to any -> $outside_ip static-port
     49nat on $ExtIf from $back_net to any -> $outside_ip static-port
     50
     51no rdr
     52
     53# Final rule - goes first.
     54block in log all
     55
     56# Inbound
     57# SSH
     58pass in on $ExtIf proto tcp from any to { $outside_ip, $outside_ip6 } \
     59port $my_ssh_services $TcpState $SshSTO
     60
     61# Web
     62pass in on $ExtIf proto tcp from any to { $outside_ip, $outside_ip6 } \
     63port $my_web_services $TcpState $WebSTO
     64
     65# Allow anything from remote network to backend network
     66pass in quick on $TunIf reply-to $TunIf from $remote_net to $back_net $UdpState
     67pass in quick on $TunIf reply-to $TunIf proto tcp from $remote_net to $back_net $TcpState
     68pass in quick on $TunIf reply-to $TunIf inet proto icmp from $remote_net to $back_net
     69
     70# This server outbound
     71pass out on $ExtIf from $outside_ip to any $UdpState
     72pass out on $ExtIf proto tcp from $outside_ip to any $TcpState
     73pass out on $ExtIf inet proto icmp from $outside_ip to any
     74pass out on $ExtIf inet6 proto ipv6-icmp from $outside_ip6 to any
     75
     76pass out on $BackIf from $back_ip to any $UdpState
     77pass out on $BackIf proto tcp from $back_ip to any $TcpState
     78pass out on $BackIf inet proto icmp from $back_ip to any
     79
     80# Allow outbound from VPN clients
     81pass in on $TunIf from $vpn_net to any $UdpState
     82pass in on $TunIf proto tcp from $vpn_net to any $TcpState
     83pass in on $TunIf inet proto icmp from $vpn_net to any
     84
     85# All outbound from backend network
     86pass in on $BackIf from $back_net to !$remote_net $UdpState
     87pass in on $BackIf proto tcp from $back_net to !$remote_net $TcpState
     88pass in on $BackIf inet proto icmp from $back_net to !$remote_net
     89
     90# End of config
     91}}}