xref: /freebsd/share/examples/pf/faq-example3 (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
142a227f8SMax Laier# $OpenBSD: faq-example3,v 1.4 2006/10/07 04:48:01 mcbride Exp $
29d7ccc0fSMax Laier
39d7ccc0fSMax Laier#
49d7ccc0fSMax Laier# Company Network
59d7ccc0fSMax Laier# http://www.openbsd.org/faq/pf/queueing.html#example2
69d7ccc0fSMax Laier#
79d7ccc0fSMax Laier
89d7ccc0fSMax Laier
99d7ccc0fSMax Laier# enable queueing on the external interface to queue packets going out
109d7ccc0fSMax Laier# to the Internet. use the cbq scheduler so that the bandwidth use of
119d7ccc0fSMax Laier# each queue can be controlled. the max outgoing bandwidth is 1.5Mbps.
129d7ccc0fSMax Laier
139d7ccc0fSMax Laieraltq on fxp0 cbq bandwidth 1.5Mb queue { std_ext, www_ext, boss_ext }
149d7ccc0fSMax Laier
159d7ccc0fSMax Laier# define the parameters for the child queues.
169d7ccc0fSMax Laier# std_ext        - the standard queue. also the default queue for
179d7ccc0fSMax Laier#                  outgoing traffic on fxp0.
189d7ccc0fSMax Laier# www_ext        - container queue for WWW server queues. limit to
199d7ccc0fSMax Laier#                  500Kbps.
2042a227f8SMax Laier#   www_ext_http - http traffic from the WWW server; higher priority.
2142a227f8SMax Laier#   www_ext_misc - all non-http traffic from the WWW server.
2242a227f8SMax Laier# boss_ext       - traffic coming from the boss's computer.
239d7ccc0fSMax Laier
2442a227f8SMax Laierqueue std_ext        bandwidth 500Kb cbq(default borrow)
259d7ccc0fSMax Laierqueue www_ext        bandwidth 500Kb { www_ext_http, www_ext_misc }
2642a227f8SMax Laier  queue www_ext_http bandwidth 50% priority 3 cbq(red borrow)
2742a227f8SMax Laier  queue www_ext_misc bandwidth 50% priority 1 cbq(borrow)
2842a227f8SMax Laierqueue boss_ext       bandwidth 500Kb priority 3 cbq(borrow)
299d7ccc0fSMax Laier
309d7ccc0fSMax Laier# enable queueing on the internal interface to control traffic coming
319d7ccc0fSMax Laier# from the Internet or the DMZ. use the cbq scheduler to control the
329d7ccc0fSMax Laier# bandwidth of each queue. bandwidth on this interface is set to the
339d7ccc0fSMax Laier# maximum. traffic coming from the DMZ will be able to use all of this
349d7ccc0fSMax Laier# bandwidth while traffic coming from the Internet will be limited to
359d7ccc0fSMax Laier# 1.0Mbps (because 0.5Mbps (500Kbps) is being allocated to fxp1).
369d7ccc0fSMax Laier
379d7ccc0fSMax Laieraltq on dc0 cbq bandwidth 100% queue { net_int, www_int }
389d7ccc0fSMax Laier
399d7ccc0fSMax Laier# define the parameters for the child queues.
409d7ccc0fSMax Laier# net_int    - container queue for traffic from the Internet. bandwidth
419d7ccc0fSMax Laier#              is 1.0Mbps.
429d7ccc0fSMax Laier#   std_int  - the standard queue. also the default queue for outgoing
439d7ccc0fSMax Laier#              traffic on dc0.
4442a227f8SMax Laier#   it_int   - traffic to the IT Dept network; reserve them 500Kbps.
4542a227f8SMax Laier#   boss_int - traffic to the boss's PC; assign a higher priority.
4642a227f8SMax Laier# www_int    - traffic from the WWW server in the DMZ; full speed.
479d7ccc0fSMax Laier
489d7ccc0fSMax Laierqueue net_int    bandwidth 1.0Mb { std_int, it_int, boss_int }
4942a227f8SMax Laier  queue std_int  bandwidth 250Kb cbq(default borrow)
509d7ccc0fSMax Laier  queue it_int   bandwidth 500Kb cbq(borrow)
5142a227f8SMax Laier  queue boss_int bandwidth 250Kb priority 3 cbq(borrow)
5242a227f8SMax Laierqueue www_int    bandwidth 99Mb cbq(red borrow)
539d7ccc0fSMax Laier
549d7ccc0fSMax Laier# enable queueing on the DMZ interface to control traffic destined for
559d7ccc0fSMax Laier# the WWW server. cbq will be used on this interface since detailed
569d7ccc0fSMax Laier# control of bandwidth is necessary. bandwidth on this interface is set
579d7ccc0fSMax Laier# to the maximum. traffic from the internal network will be able to use
589d7ccc0fSMax Laier# all of this bandwidth while traffic from the Internet will be limited
599d7ccc0fSMax Laier# to 500Kbps.
609d7ccc0fSMax Laier
619d7ccc0fSMax Laieraltq on fxp1 cbq bandwidth 100% queue { internal_dmz, net_dmz }
629d7ccc0fSMax Laier
639d7ccc0fSMax Laier# define the parameters for the child queues.
649d7ccc0fSMax Laier# internal_dmz   - traffic from the internal network.
659d7ccc0fSMax Laier# net_dmz        - container queue for traffic from the Internet.
6642a227f8SMax Laier#   net_dmz_http - http traffic; higher priority.
679d7ccc0fSMax Laier#   net_dmz_misc - all non-http traffic. this is also the default queue.
689d7ccc0fSMax Laier
6942a227f8SMax Laierqueue internal_dmz   bandwidth 99Mb cbq(borrow)
709d7ccc0fSMax Laierqueue net_dmz        bandwidth 500Kb { net_dmz_http, net_dmz_misc }
7142a227f8SMax Laier  queue net_dmz_http bandwidth 50% priority 3 cbq(red borrow)
7242a227f8SMax Laier  queue net_dmz_misc bandwidth 50% priority 1 cbq(default borrow)
739d7ccc0fSMax Laier
749d7ccc0fSMax Laier
759d7ccc0fSMax Laier# ... in the filtering section of pf.conf ...
769d7ccc0fSMax Laier
779d7ccc0fSMax Laiermain_net  = "192.168.0.0/24"
789d7ccc0fSMax Laierit_net    = "192.168.1.0/24"
799d7ccc0fSMax Laierint_nets  = "{ 192.168.0.0/24, 192.168.1.0/24 }"
809d7ccc0fSMax Laierdmz_net   = "10.0.0.0/24"
819d7ccc0fSMax Laier
829d7ccc0fSMax Laierboss      = "192.168.0.200"
839d7ccc0fSMax Laierwwwserv   = "10.0.0.100"
849d7ccc0fSMax Laier
859d7ccc0fSMax Laier# default deny
869d7ccc0fSMax Laierblock on { fxp0, fxp1, dc0 } all
879d7ccc0fSMax Laier
889d7ccc0fSMax Laier# filter rules for fxp0 inbound
899d7ccc0fSMax Laierpass in on fxp0 proto tcp from any to $wwwserv port { 21, \
9042a227f8SMax Laier        > 49151 } queue www_ext_misc
919d7ccc0fSMax Laierpass in on fxp0 proto tcp from any to $wwwserv port 80 \
9242a227f8SMax Laier        queue www_ext_http
939d7ccc0fSMax Laier
949d7ccc0fSMax Laier# filter rules for fxp0 outbound
9542a227f8SMax Laierpass out on fxp0 from $int_nets to any
9642a227f8SMax Laierpass out on fxp0 from $boss to any queue boss_ext
979d7ccc0fSMax Laier
989d7ccc0fSMax Laier# filter rules for dc0 inbound
9942a227f8SMax Laierpass in on dc0 from $int_nets to any
1009d7ccc0fSMax Laierpass in on dc0 from $it_net to any queue it_int
1019d7ccc0fSMax Laierpass in on dc0 from $boss to any queue boss_int
1029d7ccc0fSMax Laierpass in on dc0 proto tcp from $int_nets to $wwwserv port { 21, 80, \
10342a227f8SMax Laier        > 49151 } queue www_int
1049d7ccc0fSMax Laier
1059d7ccc0fSMax Laier# filter rules for dc0 outbound
1069d7ccc0fSMax Laierpass out on dc0 from dc0 to $int_nets
1079d7ccc0fSMax Laier
1089d7ccc0fSMax Laier# filter rules for fxp1 inbound
10942a227f8SMax Laierpass in on fxp1 proto { tcp, udp } from $wwwserv to any port 53
1109d7ccc0fSMax Laier
1119d7ccc0fSMax Laier# filter rules for fxp1 outbound
1129d7ccc0fSMax Laierpass out on fxp1 proto tcp from any to $wwwserv port { 21, \
11342a227f8SMax Laier        > 49151 } queue net_dmz_misc
11442a227f8SMax Laierpass out on fxp1 proto tcp from any to $wwwserv port 80 queue net_dmz_http
1159d7ccc0fSMax Laierpass out on fxp1 proto tcp from $int_nets to $wwwserv port { 80, \
11642a227f8SMax Laier        21, > 49151 } queue internal_dmz
117