186d7f5d3SJohn Marino# $OpenBSD: faq-example2,v 1.3 2005/07/02 16:16:39 joel Exp $ 286d7f5d3SJohn Marino# $DragonFly: src/share/examples/pf/faq-example2,v 1.1 2005/12/13 01:58:27 corecode Exp $ 386d7f5d3SJohn Marino 486d7f5d3SJohn Marino# 586d7f5d3SJohn Marino# Small, Home Network 686d7f5d3SJohn Marino# http://www.openbsd.org/faq/pf/queueing.html#example1 786d7f5d3SJohn Marino# 886d7f5d3SJohn Marino 986d7f5d3SJohn Marino 1086d7f5d3SJohn Marino# enable queueing on the external interface to control traffic going to 1186d7f5d3SJohn Marino# the Internet. use the priq scheduler to control only priorities. set 1286d7f5d3SJohn Marino# the bandwidth to 610Kbps to get the best performance out of the TCP 1386d7f5d3SJohn Marino# ACK queue. 1486d7f5d3SJohn Marino 1586d7f5d3SJohn Marinoaltq on fxp0 priq bandwidth 610Kb queue { std_out, ssh_im_out, dns_out, \ 1686d7f5d3SJohn Marino tcp_ack_out } 1786d7f5d3SJohn Marino 1886d7f5d3SJohn Marino# define the parameters for the child queues. 1986d7f5d3SJohn Marino# std_out - the standard queue. any filter rule below that does not 2086d7f5d3SJohn Marino# explicitly specify a queue will have its traffic added 2186d7f5d3SJohn Marino# to this queue. 2286d7f5d3SJohn Marino# ssh_im_out - interactive SSH and various instant message traffic. 2386d7f5d3SJohn Marino# dns_out - DNS queries. 2486d7f5d3SJohn Marino# tcp_ack_out - TCP ACK packets with no data payload. 2586d7f5d3SJohn Marino 2686d7f5d3SJohn Marinoqueue std_out priq(default) 2786d7f5d3SJohn Marinoqueue ssh_im_out priority 4 priq(red) 2886d7f5d3SJohn Marinoqueue dns_out priority 5 2986d7f5d3SJohn Marinoqueue tcp_ack_out priority 6 3086d7f5d3SJohn Marino 3186d7f5d3SJohn Marino# enable queueing on the internal interface to control traffic coming in 3286d7f5d3SJohn Marino# from the Internet. use the cbq scheduler to control bandwidth. max 3386d7f5d3SJohn Marino# bandwidth is 2Mbps. 3486d7f5d3SJohn Marino 3586d7f5d3SJohn Marinoaltq on dc0 cbq bandwidth 2Mb queue { std_in, ssh_im_in, dns_in, bob_in } 3686d7f5d3SJohn Marino 3786d7f5d3SJohn Marino# define the parameters for the child queues. 3886d7f5d3SJohn Marino# std_in - the standard queue. any filter rule below that does not 3986d7f5d3SJohn Marino# explicitly specify a queue will have its traffic added 4086d7f5d3SJohn Marino# to this queue. 4186d7f5d3SJohn Marino# ssh_im_in - interactive SSH and various instant message traffic. 4286d7f5d3SJohn Marino# dns_in - DNS replies. 4386d7f5d3SJohn Marino# bob_in - bandwidth reserved for Bob's workstation. allow him to 4486d7f5d3SJohn Marino# borrow. 4586d7f5d3SJohn Marino 4686d7f5d3SJohn Marinoqueue std_in bandwidth 1.6Mb cbq(default) 4786d7f5d3SJohn Marinoqueue ssh_im_in bandwidth 200Kb priority 4 4886d7f5d3SJohn Marinoqueue dns_in bandwidth 120Kb priority 5 4986d7f5d3SJohn Marinoqueue bob_in bandwidth 80Kb cbq(borrow) 5086d7f5d3SJohn Marino 5186d7f5d3SJohn Marino 5286d7f5d3SJohn Marino# ... in the filtering section of pf.conf ... 5386d7f5d3SJohn Marino 5486d7f5d3SJohn Marinoalice = "192.168.0.2" 5586d7f5d3SJohn Marinobob = "192.168.0.3" 5686d7f5d3SJohn Marinocharlie = "192.168.0.4" 5786d7f5d3SJohn Marinolocal_net = "192.168.0.0/24" 5886d7f5d3SJohn Marinossh_ports = "{ 22 2022 }" 5986d7f5d3SJohn Marinoim_ports = "{ 1863 5190 5222 }" 6086d7f5d3SJohn Marino 6186d7f5d3SJohn Marino# filter rules for fxp0 inbound 6286d7f5d3SJohn Marinoblock in on fxp0 all 6386d7f5d3SJohn Marino 6486d7f5d3SJohn Marino# filter rules for fxp0 outbound 6586d7f5d3SJohn Marinoblock out on fxp0 all 6686d7f5d3SJohn Marinopass out on fxp0 inet proto tcp from (fxp0) to any flags S/SA \ 6786d7f5d3SJohn Marino keep state queue(std_out, tcp_ack_out) 6886d7f5d3SJohn Marinopass out on fxp0 inet proto { udp icmp } from (fxp0) to any keep state 6986d7f5d3SJohn Marinopass out on fxp0 inet proto { tcp udp } from (fxp0) to any port domain \ 7086d7f5d3SJohn Marino keep state queue dns_out 7186d7f5d3SJohn Marinopass out on fxp0 inet proto tcp from (fxp0) to any port $ssh_ports \ 7286d7f5d3SJohn Marino flags S/SA keep state queue(std_out, ssh_im_out) 7386d7f5d3SJohn Marinopass out on fxp0 inet proto tcp from (fxp0) to any port $im_ports \ 7486d7f5d3SJohn Marino flags S/SA keep state queue(ssh_im_out, tcp_ack_out) 7586d7f5d3SJohn Marino 7686d7f5d3SJohn Marino# filter rules for dc0 inbound 7786d7f5d3SJohn Marinoblock in on dc0 all 7886d7f5d3SJohn Marinopass in on dc0 from $local_net 7986d7f5d3SJohn Marino 8086d7f5d3SJohn Marino# filter rules for dc0 outbound 8186d7f5d3SJohn Marinoblock out on dc0 all 8286d7f5d3SJohn Marinopass out on dc0 from any to $local_net 8386d7f5d3SJohn Marinopass out on dc0 proto { tcp udp } from any port domain to $local_net \ 8486d7f5d3SJohn Marino queue dns_in 8586d7f5d3SJohn Marinopass out on dc0 proto tcp from any port $ssh_ports to $local_net \ 8686d7f5d3SJohn Marino queue(std_in, ssh_im_in) 8786d7f5d3SJohn Marinopass out on dc0 proto tcp from any port $im_ports to $local_net \ 8886d7f5d3SJohn Marino queue ssh_im_in 8986d7f5d3SJohn Marinopass out on dc0 from any to $bob queue bob_in 90