elmore
May 11th, 2003, 00:40
I took some time today to update my extremely old OBSD firewall at home from 3.0 to 3.3
I wanted to use all the new pf features. The following is what I came up with. Anyone done this yet?
[code:1:579742dfab]
# Macros: define common values, so they can be referenced and changed easily.
ext_if="xl0" # replace with actual external interface name i.e., dc0
int_if="xl1" # replace with actual internal interface name i.e., dc1
internal_net="10.26.1.0/24"
sshhost="any"
NoRouteIP="{ 127.0.0.1/8, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12 }"
# Options: tune the behavior of pf, default values are given.
set timeout { interval 30, frag 10 }
set timeout { tcp.first 120, tcp.opening 30, tcp.established 86400 }
set timeout { tcp.closing 900, tcp.finwait 45, tcp.closed 90 }
set timeout { udp.first 60, udp.single 30, udp.multiple 60 }
set timeout { icmp.first 20, icmp.error 10 }
set timeout { other.first 60, other.single 30, other.multiple 60 }
set limit { states 10000, frags 5000 }
set loginterface $ext_if
set optimization aggressive
set block-policy drop
set require-order yes
#Normalization: reassemble fragments and resolve or reduce traffic #ambiguities.
scrub in on $ext_if all fragment reassemble
scrub out on $ext_if all random-id max-mss 1440
#Queueing: rule-based bandwidth control.
altq on $ext_if priq bandwidth 256Kb queue \
{ www_out, ssh_out, dns_out, ftp_out, std_out, tcp_ack_out }
#Parameters for the Child outgoing Queues
#www_out - Outgoing www requests
#ssh_out - Outgoing ssh connections
#dns_out - Outgoing dns requests
#ftp_out - Outgoing ftp requests
#std_out - The standard queue all other traffic
queue tcp_ack_out priority 6 priq(red)
queue www_out priority 5 priq(red)
queue dns_out priority 4 priq(red)
queue ssh_out priority 3 priq(red)
queue ftp_out priority 2 priq(red)
queue std_out priq(red default)
altq on $int_if priq bandwidth 2Mb queue \
{ www_in, ssh_in, dns_in, ftp_in, std_in }
#Parameters for the Child incoming Queues
#www_in - incoming www traffic
#ssh_in - incoming ssh traffic
#dns_in - incoming dns traffic
#ftp_in - incoming ftp traffic
#std_in - standard queue for all other traffic
queue www_in priority 5 priq(red)
queue dns_in priority 4 priq(red)
queue ssh_in priority 3 priq(red)
queue ftp_in priority 2 priq(red)
queue std_in priq(red default)
#NAT to the internal network
nat on $ext_if from $internal_net to any -> ($ext_if)
#Don't allow anyone to spoof unroutable addresses
block in quick on $ext_if from $NoRouteIP to any
block out quick on $ext_if from any to $NoRouteIP
#Block all ipopts to fool NMAP attempts
block in log quick on $ext_if inet proto tcp from any to any flags FUP/FUP
block in log quick on $ext_if inet proto tcp from any to any flags SF/SFRA
block in log quick on $ext_if inet proto tcp from any to any flags /SFRA
block in log quick on $ext_if inet proto tcp from any to any flags F/SFRA
block in log quick on $ext_if inet proto tcp from any to any flags U/SFRAU
#Block in Everything by default
block in on $ext_if all
#Let outgoing traffic out and assign it to a queue
block out on $ext_if all
pass out on $ext_if inet proto tcp from any to any port { 80, 443 } flags \
S/SA modulate state queue (www_out, tcp_ack_out)
pass out on $ext_if inet proto udp from any to any port 53 keep state \
queue dns_out
pass out on $ext_if inet proto tcp from any to any port 22 flags S/SA \
modulate state queue (ssh_out, tcp_ack_out)
pass out on $ext_if inet proto tcp from any to any flags S/SA modulate \
state queue (std_out, tcp_ack_out)
pass out on $ext_if inet proto udp from any to any flags S/SA keep state \
queue std_out
pass out on $ext_if inet proto tcp from any to any port 21 flags S/SA \
modulate state queue (ftp_out, tcp_ack_out)
pass out on $ext_if inet proto icmp all keep state
#Let incoming traffic that needs to come in in and assign it to a queue.
pass in on $int_if from any to $internal_net
pass in on $int_if proto tcp from any port { 80, 443 } to $internal_net \
queue www_in
pass in on $int_if proto { tcp, udp } from any port 53 to $internal_net \
queue dns_in
pass in on $int_if proto tcp from any port 22 to $internal_net queue ssh_in
pass in on $int_if proto tcp from any to $internal_net queue std_in
pass in on $int_if proto tcp from any port 21 to $internal_net queue ftp_in
[/code:1:579742dfab]
I've noticed a significant improvement in performance over my cable modem with this ruleset. Obviously as this is my first attempt at an altq ruleset I'm interested to see how others are doing this.
I wanted to use all the new pf features. The following is what I came up with. Anyone done this yet?
[code:1:579742dfab]
# Macros: define common values, so they can be referenced and changed easily.
ext_if="xl0" # replace with actual external interface name i.e., dc0
int_if="xl1" # replace with actual internal interface name i.e., dc1
internal_net="10.26.1.0/24"
sshhost="any"
NoRouteIP="{ 127.0.0.1/8, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12 }"
# Options: tune the behavior of pf, default values are given.
set timeout { interval 30, frag 10 }
set timeout { tcp.first 120, tcp.opening 30, tcp.established 86400 }
set timeout { tcp.closing 900, tcp.finwait 45, tcp.closed 90 }
set timeout { udp.first 60, udp.single 30, udp.multiple 60 }
set timeout { icmp.first 20, icmp.error 10 }
set timeout { other.first 60, other.single 30, other.multiple 60 }
set limit { states 10000, frags 5000 }
set loginterface $ext_if
set optimization aggressive
set block-policy drop
set require-order yes
#Normalization: reassemble fragments and resolve or reduce traffic #ambiguities.
scrub in on $ext_if all fragment reassemble
scrub out on $ext_if all random-id max-mss 1440
#Queueing: rule-based bandwidth control.
altq on $ext_if priq bandwidth 256Kb queue \
{ www_out, ssh_out, dns_out, ftp_out, std_out, tcp_ack_out }
#Parameters for the Child outgoing Queues
#www_out - Outgoing www requests
#ssh_out - Outgoing ssh connections
#dns_out - Outgoing dns requests
#ftp_out - Outgoing ftp requests
#std_out - The standard queue all other traffic
queue tcp_ack_out priority 6 priq(red)
queue www_out priority 5 priq(red)
queue dns_out priority 4 priq(red)
queue ssh_out priority 3 priq(red)
queue ftp_out priority 2 priq(red)
queue std_out priq(red default)
altq on $int_if priq bandwidth 2Mb queue \
{ www_in, ssh_in, dns_in, ftp_in, std_in }
#Parameters for the Child incoming Queues
#www_in - incoming www traffic
#ssh_in - incoming ssh traffic
#dns_in - incoming dns traffic
#ftp_in - incoming ftp traffic
#std_in - standard queue for all other traffic
queue www_in priority 5 priq(red)
queue dns_in priority 4 priq(red)
queue ssh_in priority 3 priq(red)
queue ftp_in priority 2 priq(red)
queue std_in priq(red default)
#NAT to the internal network
nat on $ext_if from $internal_net to any -> ($ext_if)
#Don't allow anyone to spoof unroutable addresses
block in quick on $ext_if from $NoRouteIP to any
block out quick on $ext_if from any to $NoRouteIP
#Block all ipopts to fool NMAP attempts
block in log quick on $ext_if inet proto tcp from any to any flags FUP/FUP
block in log quick on $ext_if inet proto tcp from any to any flags SF/SFRA
block in log quick on $ext_if inet proto tcp from any to any flags /SFRA
block in log quick on $ext_if inet proto tcp from any to any flags F/SFRA
block in log quick on $ext_if inet proto tcp from any to any flags U/SFRAU
#Block in Everything by default
block in on $ext_if all
#Let outgoing traffic out and assign it to a queue
block out on $ext_if all
pass out on $ext_if inet proto tcp from any to any port { 80, 443 } flags \
S/SA modulate state queue (www_out, tcp_ack_out)
pass out on $ext_if inet proto udp from any to any port 53 keep state \
queue dns_out
pass out on $ext_if inet proto tcp from any to any port 22 flags S/SA \
modulate state queue (ssh_out, tcp_ack_out)
pass out on $ext_if inet proto tcp from any to any flags S/SA modulate \
state queue (std_out, tcp_ack_out)
pass out on $ext_if inet proto udp from any to any flags S/SA keep state \
queue std_out
pass out on $ext_if inet proto tcp from any to any port 21 flags S/SA \
modulate state queue (ftp_out, tcp_ack_out)
pass out on $ext_if inet proto icmp all keep state
#Let incoming traffic that needs to come in in and assign it to a queue.
pass in on $int_if from any to $internal_net
pass in on $int_if proto tcp from any port { 80, 443 } to $internal_net \
queue www_in
pass in on $int_if proto { tcp, udp } from any port 53 to $internal_net \
queue dns_in
pass in on $int_if proto tcp from any port 22 to $internal_net queue ssh_in
pass in on $int_if proto tcp from any to $internal_net queue std_in
pass in on $int_if proto tcp from any port 21 to $internal_net queue ftp_in
[/code:1:579742dfab]
I've noticed a significant improvement in performance over my cable modem with this ruleset. Obviously as this is my first attempt at an altq ruleset I'm interested to see how others are doing this.