xref: /freebsd/share/examples/pf/faq-example3 (revision 42a227f8baec1d2627cec5c2010aedb78f7e9b28)
19d7ccc0fSMax Laier# $FreeBSD$
242a227f8SMax Laier# $OpenBSD: faq-example3,v 1.4 2006/10/07 04:48:01 mcbride Exp $
39d7ccc0fSMax Laier
49d7ccc0fSMax Laier#
59d7ccc0fSMax Laier# Company Network
69d7ccc0fSMax Laier# http://www.openbsd.org/faq/pf/queueing.html#example2
79d7ccc0fSMax Laier#
89d7ccc0fSMax Laier
99d7ccc0fSMax Laier
109d7ccc0fSMax Laier# enable queueing on the external interface to queue packets going out
119d7ccc0fSMax Laier# to the Internet. use the cbq scheduler so that the bandwidth use of
129d7ccc0fSMax Laier# each queue can be controlled. the max outgoing bandwidth is 1.5Mbps.
139d7ccc0fSMax Laier
149d7ccc0fSMax Laieraltq on fxp0 cbq bandwidth 1.5Mb queue { std_ext, www_ext, boss_ext }
159d7ccc0fSMax Laier
169d7ccc0fSMax Laier# define the parameters for the child queues.
179d7ccc0fSMax Laier# std_ext        - the standard queue. also the default queue for
189d7ccc0fSMax Laier#                  outgoing traffic on fxp0.
199d7ccc0fSMax Laier# www_ext        - container queue for WWW server queues. limit to
209d7ccc0fSMax Laier#                  500Kbps.
2142a227f8SMax Laier#   www_ext_http - http traffic from the WWW server; higher priority.
2242a227f8SMax Laier#   www_ext_misc - all non-http traffic from the WWW server.
2342a227f8SMax Laier# boss_ext       - traffic coming from the boss's computer.
249d7ccc0fSMax Laier
2542a227f8SMax Laierqueue std_ext        bandwidth 500Kb cbq(default borrow)
269d7ccc0fSMax Laierqueue www_ext        bandwidth 500Kb { www_ext_http, www_ext_misc }
2742a227f8SMax Laier  queue www_ext_http bandwidth 50% priority 3 cbq(red borrow)
2842a227f8SMax Laier  queue www_ext_misc bandwidth 50% priority 1 cbq(borrow)
2942a227f8SMax Laierqueue boss_ext       bandwidth 500Kb priority 3 cbq(borrow)
309d7ccc0fSMax Laier
319d7ccc0fSMax Laier# enable queueing on the internal interface to control traffic coming
329d7ccc0fSMax Laier# from the Internet or the DMZ. use the cbq scheduler to control the
339d7ccc0fSMax Laier# bandwidth of each queue. bandwidth on this interface is set to the
349d7ccc0fSMax Laier# maximum. traffic coming from the DMZ will be able to use all of this
359d7ccc0fSMax Laier# bandwidth while traffic coming from the Internet will be limited to
369d7ccc0fSMax Laier# 1.0Mbps (because 0.5Mbps (500Kbps) is being allocated to fxp1).
379d7ccc0fSMax Laier
389d7ccc0fSMax Laieraltq on dc0 cbq bandwidth 100% queue { net_int, www_int }
399d7ccc0fSMax Laier
409d7ccc0fSMax Laier# define the parameters for the child queues.
419d7ccc0fSMax Laier# net_int    - container queue for traffic from the Internet. bandwidth
429d7ccc0fSMax Laier#              is 1.0Mbps.
439d7ccc0fSMax Laier#   std_int  - the standard queue. also the default queue for outgoing
449d7ccc0fSMax Laier#              traffic on dc0.
4542a227f8SMax Laier#   it_int   - traffic to the IT Dept network; reserve them 500Kbps.
4642a227f8SMax Laier#   boss_int - traffic to the boss's PC; assign a higher priority.
4742a227f8SMax Laier# www_int    - traffic from the WWW server in the DMZ; full speed.
489d7ccc0fSMax Laier
499d7ccc0fSMax Laierqueue net_int    bandwidth 1.0Mb { std_int, it_int, boss_int }
5042a227f8SMax Laier  queue std_int  bandwidth 250Kb cbq(default borrow)
519d7ccc0fSMax Laier  queue it_int   bandwidth 500Kb cbq(borrow)
5242a227f8SMax Laier  queue boss_int bandwidth 250Kb priority 3 cbq(borrow)
5342a227f8SMax Laierqueue www_int    bandwidth 99Mb cbq(red borrow)
549d7ccc0fSMax Laier
559d7ccc0fSMax Laier# enable queueing on the DMZ interface to control traffic destined for
569d7ccc0fSMax Laier# the WWW server. cbq will be used on this interface since detailed
579d7ccc0fSMax Laier# control of bandwidth is necessary. bandwidth on this interface is set
589d7ccc0fSMax Laier# to the maximum. traffic from the internal network will be able to use
599d7ccc0fSMax Laier# all of this bandwidth while traffic from the Internet will be limited
609d7ccc0fSMax Laier# to 500Kbps.
619d7ccc0fSMax Laier
629d7ccc0fSMax Laieraltq on fxp1 cbq bandwidth 100% queue { internal_dmz, net_dmz }
639d7ccc0fSMax Laier
649d7ccc0fSMax Laier# define the parameters for the child queues.
659d7ccc0fSMax Laier# internal_dmz   - traffic from the internal network.
669d7ccc0fSMax Laier# net_dmz        - container queue for traffic from the Internet.
6742a227f8SMax Laier#   net_dmz_http - http traffic; higher priority.
689d7ccc0fSMax Laier#   net_dmz_misc - all non-http traffic. this is also the default queue.
699d7ccc0fSMax Laier
7042a227f8SMax Laierqueue internal_dmz   bandwidth 99Mb cbq(borrow)
719d7ccc0fSMax Laierqueue net_dmz        bandwidth 500Kb { net_dmz_http, net_dmz_misc }
7242a227f8SMax Laier  queue net_dmz_http bandwidth 50% priority 3 cbq(red borrow)
7342a227f8SMax Laier  queue net_dmz_misc bandwidth 50% priority 1 cbq(default borrow)
749d7ccc0fSMax Laier
759d7ccc0fSMax Laier
769d7ccc0fSMax Laier# ... in the filtering section of pf.conf ...
779d7ccc0fSMax Laier
789d7ccc0fSMax Laiermain_net  = "192.168.0.0/24"
799d7ccc0fSMax Laierit_net    = "192.168.1.0/24"
809d7ccc0fSMax Laierint_nets  = "{ 192.168.0.0/24, 192.168.1.0/24 }"
819d7ccc0fSMax Laierdmz_net   = "10.0.0.0/24"
829d7ccc0fSMax Laier
839d7ccc0fSMax Laierboss      = "192.168.0.200"
849d7ccc0fSMax Laierwwwserv   = "10.0.0.100"
859d7ccc0fSMax Laier
869d7ccc0fSMax Laier# default deny
879d7ccc0fSMax Laierblock on { fxp0, fxp1, dc0 } all
889d7ccc0fSMax Laier
899d7ccc0fSMax Laier# filter rules for fxp0 inbound
909d7ccc0fSMax Laierpass in on fxp0 proto tcp from any to $wwwserv port { 21, \
9142a227f8SMax Laier        > 49151 } queue www_ext_misc
929d7ccc0fSMax Laierpass in on fxp0 proto tcp from any to $wwwserv port 80 \
9342a227f8SMax Laier        queue www_ext_http
949d7ccc0fSMax Laier
959d7ccc0fSMax Laier# filter rules for fxp0 outbound
9642a227f8SMax Laierpass out on fxp0 from $int_nets to any
9742a227f8SMax Laierpass out on fxp0 from $boss to any queue boss_ext
989d7ccc0fSMax Laier
999d7ccc0fSMax Laier# filter rules for dc0 inbound
10042a227f8SMax Laierpass in on dc0 from $int_nets to any
1019d7ccc0fSMax Laierpass in on dc0 from $it_net to any queue it_int
1029d7ccc0fSMax Laierpass in on dc0 from $boss to any queue boss_int
1039d7ccc0fSMax Laierpass in on dc0 proto tcp from $int_nets to $wwwserv port { 21, 80, \
10442a227f8SMax Laier        > 49151 } queue www_int
1059d7ccc0fSMax Laier
1069d7ccc0fSMax Laier# filter rules for dc0 outbound
1079d7ccc0fSMax Laierpass out on dc0 from dc0 to $int_nets
1089d7ccc0fSMax Laier
1099d7ccc0fSMax Laier# filter rules for fxp1 inbound
11042a227f8SMax Laierpass in on fxp1 proto { tcp, udp } from $wwwserv to any port 53
1119d7ccc0fSMax Laier
1129d7ccc0fSMax Laier# filter rules for fxp1 outbound
1139d7ccc0fSMax Laierpass out on fxp1 proto tcp from any to $wwwserv port { 21, \
11442a227f8SMax Laier        > 49151 } queue net_dmz_misc
11542a227f8SMax Laierpass out on fxp1 proto tcp from any to $wwwserv port 80 queue net_dmz_http
1169d7ccc0fSMax Laierpass out on fxp1 proto tcp from $int_nets to $wwwserv port { 80, \
11742a227f8SMax Laier        21, > 49151 } queue internal_dmz
118