1.编释内核启用IPFIREWALL和IPFIVERT
编释内核启用DUMMYNET
2.cd /usr/src
make buildkernel KERNCONF=ConfigName
make installkernel KERNCONF=ConfigName
3.添加相应规则(此处添加的只为简单规则,末做安全设置)
ipfw -q add 00001 allow ip from 127.0.0.1 to 127.0.0.1 via lo0
ipfw -q add 00002 deny ip from 127.0.0.0/8 to any
ipfw -q add 00003 deny ip from any to 127.0.0.0/8
ipfw -q add 00004 deny ip from 1.1.1.0/24 to any in via rl0
ipfw -q add 20000 divert 8668 ip from any to any via rl0 (rl0为外网口,在rl0口上启用natd服务)
#创建相应相应通道。
ipfw -q add 30000 pipe 1 icmp from any to any
ipfw -q add 30101 pipe 4 tcp from any to any out
ipfw -q add 65535 allow ip from any to any
ipfw -q pipe 4 config mask dst-ip 0xffffffff bw 100KB/s queue 100Kbytes (匹配通道4里面的 每个目的地IP的带宽 《这儿的上的地IP。因为NAT过后,所以目的IP为内网的IP。》)
以下为ipfw pipe show (运行状态下面的通道显示)
00001: 1.000 Kbit/s 0 ms 10 sl. 1 queues (1 buckets) droptail
mask: 0×00 0×00000000/0×0000 -> 0×00000000/0×0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
0 icmp 1.1.1.3/0 221.5.203.98/0 16983 12286764 0 0 0
00002: 320.000 Kbit/s 0 ms 20 sl. 1 queues (1 buckets) droptail
mask: 0×00 0×00000000/0×0000 -> 0×00000000/0×0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
0 tcp 1.1.1.3/1035 207.46.193.254/80 386482 352842969 0 0 394
00003: 160.000 Kbit/s 0 ms 30 sl. 1 queues (1 buckets) droptail
mask: 0×00 0×00000000/0×0000 -> 0×00000000/0×0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
0 tcp 192.168.1.15/1236 192.168.1.4/81 42383 40705903 0 0 0
00004: 800.000 Kbit/s 0 ms 100 KB 6 queues (64 buckets) droptail
mask: 0×00 0×00000000/0×0000 -> 0xffffffff/0×0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
0 ip 0.0.0.0/0 1.1.1.2/0 45 5000 0 0 0
1 ip 0.0.0.0/0 1.1.1.3/0 6924 7229904 17 23793 0
5 ip 0.0.0.0/0 1.1.1.7/0 6978 9792770 14 19293 0
20 ip 0.0.0.0/0 192.168.1.4/0 9706 5759085 0 0 0
32 ip 192.168.1.4/0 0.0.0.0/0 4905 255108 0 0 0
54 ip 192.168.1.15/0 0.0.0.0/0 9804 14703104 0 0 0
运行结果:
Client1:
密户机2:
first: cd /usr/src/sys/i386/config
cp GENERIC MyKernel
and
vi MyKernel
add options or rm options
如果想要支持IPFirewall功能。需要添加以下一些options