使用FreeBSD构建流量控制防火墙(2) # config # cd ../../compile/BRGFW # make depend all install # reboot -------------------------------------------------------------------------------- 重新启动计算机以后,使用以下命令激活桥接流量控制防火墙选项: sysctl -w net.link.ether.bridge_ipfw=1 sysctl -w net.link.ether.bridge_cfg="" sysctl -w net.link.ether.bridge=1 其中bridge_cfg参数用于设置多组桥接设备,如果仅考虑单组桥接,可以忽略。实例使用集成的Intel 82557网络适配器作为管理网络,其他3Com 3C905B网络适配器分为两组网桥使用。 -------------------------------------------------------------------------------- 实例 # sysctl -w net.link.ether.bridge_ipfw=1 # sysctl -w net.link.ether.bridge_cfg="xl0:0,xl1:0,xl2:1,xl3:1" # sysctl -w net.link.ether.bridge=1 -------------------------------------------------------------------------------- 使用 使用ipfw命令来控制流量和防火墙策略。其中流量控制是作为一条防火墙策略实现的,因此ipfw是唯一的管理界面。通过实例来说明ipfw的使用。 在实例中,网段192.168.254.0/24经过第一组网桥,网段192.168.250.0/24经过第二组网桥,并建立以下策略: 允许所有的ICMP连接,限制总流量为10Kbit/s 允许所有的UDP链接,限制总流量为100Kbit/s 允许TCP到网段192.168.254.0/24的所有连接,限制流量为5Mbit/s 允许TCP到主机192.168.250.222的HTTP连接,限制流量为2Mbit/s 允许TCP到主机192.168.250.0/24的所有其他连接,限制流量为1Mbit/s 禁止其他所有连接 -------------------------------------------------------------------------------- 实例 # ipfw -flush # ipfw add 100 pipe 1 icmp from any to any # ipfw pipe 1 config bw 10Kbit/s # ipfw add 200 pipe 2 udp from any to any # ipfw pipe 2 config bw 100Kbit/s # ipfw add 300 pipe 3 tcp from 192.168.254.0/24 to any # ipfw pipe 3 config bw 5Mbit/s # ipfw add 400 pipe 4 tcp from any to 192.168.254.0/24 # ipfw pipe 4 config bw 5Mbit/s # ipfw add 500 pipe 5 tcp from any to 192.168.250.222 80 # ipfw pipe 5 config bw 2Mbit/s # ipfw add 600 pipe 6 tcp from 192.168.250.222 80 to any # ipfw pipe 6 config bw 2Mbit/s # ipfw add 700 pipe 7 tcp from 192.168.250.0/24 to any # ipfw pipe 7 config bw 1Mbit/s # ipfw add 800 pipe 8 tcp from any to 192.168.250.0/24