Код:
#-------------------------
# Variables and Macros
#-------------------------
# interfaces
inet_if = "tun0"
ext_if = "em0"
int_if = "xl0"
# Block connections
connblk = "synproxy state ( max-src-conn-rate 5/60, overload <BRUTEFORCERS> flush global )"
icmp_types="{ echoreq, unreach }"
#-------------------------
# ip addresses
#-------------------------
extnet = "{ 10.0.0.0/8, 192.168.252.0/24 }"
lannet = "{ 192.168.0.0/24, 192.168.2.0/24 }"
ext_ip = "xxxxxxxxxx"
server = "192.168.0.1"
private_nets = "{ 127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 169.254.0.0/16, 192.0.2.0/24, 0.0.0.0/8, 224.0.0.0/4 }"
#--------------------------
# Tables
#--------------------------
table <uaix> persist file "/etc/pf/prefixes.txt"
table <BRUTEFORCERS> persist
#-------------------------
# Ports
#-------------------------
sshlhc = "22"
sshserver = "222"
tcp_ports = "{ smtp, http, pop3, ftp, ftp-data, domain, 8089, 8090, 6688, 3784 }"
udp_ports = "{ domain, smtp, http, ftp, ftp-data, 6688, 3784 }"
#-------------------------
# Options
#-------------------------
# Default policy
set block-policy return
# Type of optimization
#set optimization normal
# State-policy
#set state-policy floating
# skip pf on lo0 interface
set skip on lo0
#timeout to tcp packets
set timeout { frag 10, tcp.established 3600 }
# Normaliztion for all interfaces
scrub in all
#-------------------------
# Queue & Speed Control
#-------------------------
# altqs
altq on $int_if cbq bandwidth 1000Mb queue { def_download }
altq on $inet_if cbq bandwidth 1000Mb queue { def_upload }
queue def_download on $int_if bandwidth 100% cbq(default) { 192.168.0.2_ii, 192.168.0.2_ui }
queue def_upload on $inet_if bandwidth 100% cbq(default) { 192.168.0.2_io, 192.168.0.2_uo }
# users1 queues
queue 192.168.0.2_ii bandwidth 20240Kb cbq(ecn)
queue 192.168.0.2_io bandwidth 1024Kb cbq(ecn)
queue 192.168.0.2_ui bandwidth 20240Kb cbq(ecn)
queue 192.168.0.2_uo bandwidth 1024Kb cbq(ecn)
#--------------------------
# NAT & Redirect
#--------------------------
# Nat from local net to inet
nat on $inet_if from $lannet to any -> $ext_ip
# Nat from local net to ext_net
nat on $ext_if from $lannet to $extnet -> ($ext_if)
# Redirect ports
# For Active FTP sessions
nat-anchor "ftp-proxy/*"
rdr-anchor "ftp-proxy/*"
rdr on $int_if proto tcp from any to ! (self) port 21 -> 127.0.0.1 port 8021
# to server ssh
rdr proto tcp from any to $ext_ip port $sshserver -> $server port ssh
#--------------------------
# Filter Rules
#--------------------------
# Block all
block all
# IGMP IPTV
pass in quick proto igmp from $lannet to any allow-opts no state
pass quick on { $ext_if $int_if } proto igmp allow-opts no state
pass quick proto udp from 192.168.252.0/24 to any allow-opts no state
# Antispoof
antispoof quick for { lo0, $int_if, $ext_if, $inet_if }
# Block all from inet to private networks via internet interface
block drop in quick on $inet_if from $private_nets to any
# Block all spammers
block drop quick from <BRUTEFORCERS>
#-----------------------
# In Connections
#-----------------------
# pass all connections from our lan to server
pass in on $int_if from $lannet to $int_if keep state
# pass tcp ports from inet
pass in proto tcp to $inet_if port $tcp_ports keep state
# pass for ssh lhc
pass in proto tcp to $inet_if port $sshlhc $connblk
# pass udp ports from inet
pass in proto udp to $inet_if port $udp_ports keep state
# for ftp
pass in on $inet_if proto tcp from any to any port > 49151 keep state
# allow from lannet to extnet
pass in from $lannet to $extnet keep state
# allow pings from inet
pass in on $inet_if inet proto icmp from any to $inet_if icmp-type $icmp_types keep state
# block smtp connections to inet
block in quick on $int_if proto tcp from $lannet to ! $int_if port 25
#--------------------------
# Out Connections
#--------------------------
#for lan
pass out from $int_if to $lannet keep state
#for tenet
pass out from $ext_if to $extnet keep state
#for inet
pass out from $inet_if keep state
#--------------------------
# Rules for rdr
#--------------------------
# Allow rpd to 192.168.0.1 ssh
pass in on $inet_if proto tcp from any to 192.168.0.1 port ssh $connblk
# For FTP PROXY
anchor "ftp-proxy/*"
#--------------------------
# Inet to Users
#--------------------------
# users1 filters
pass in on $int_if from 192.168.0.2 to any queue 192.168.0.2_io no state
pass out on $int_if from any to 192.168.0.2 queue 192.168.0.2_ii no state
pass in on $int_if from 192.168.0.2 to <uaix> queue 192.168.0.2_uo no state
pass out on $int_if from <uaix> to 192.168.0.2 queue 192.168.0.2_ui no state
Социальные закладки