FreeBSD与Windows下 配置Dummynet

来源:互联网 发布:音响软件 编辑:程序博客网 时间:2024/05/20 16:42

最近一直在配置Dummynet,发现了很多问题。首先我在Windows 8.1平台下配置后,发现无法打开ipfw.exe。 经过解决,需要Crgwin下打开ipfw.exe. 原因应该是ipfw是基于Linux源开发的,在Windows打开需要一个模拟Linux的软件,而Crgwin就是让你在Windows找到Linux的感觉。

具体操作如下,将所下载的ipfw文件复制到Crgwin文件夹,之后就可以按Linux 与 ipfw的操作方法进行了。

Shark@Lau ~
$ ls


Shark@Lau ~
$ cd ..


Shark@Lau /home
$ ls
Shark


Shark@Lau /home
$ touch xiaohe.txt


Shark@Lau /home
$ cd Xiaohe/


Shark@Lau /home/Xiaohe
$ ls
ipfw3-2012


Shark@Lau /home/Xiaohe
$ cd ipfw3-2012/


Shark@Lau /home/Xiaohe/ipfw3-2012
$ ls
~$README  binary64  ipfw   Makefile      README  tcc_glue.h
binary    glue.h    kipfw  Makefile.inc  sys


Shark@Lau /home/Xiaohe/ipfw3-2012
$ make
-bash: make: command not found


Shark@Lau /home/Xiaohe/ipfw3-2012
$ cd ipfw/


Shark@Lau /home/Xiaohe/ipfw3-2012/ipfw
$ ls
add_rules        glue.c             ipfw.8   ipv6.c    qsort.c       ws2_32.def
dummynet.c       humanize_number.c  ipfw2.c  main.c    qsort_r.c
expand_number.c  include            ipfw2.h  Makefile  rule_test.sh


Shark@Lau /home/Xiaohe/ipfw3-2012/ipfw
$ make
-bash: make: command not found


Shark@Lau /home/Xiaohe/ipfw3-2012/ipfw
$ locate make


Shark@Lau /home/Xiaohe/ipfw3-2012/ipfw
$ updatedb
/usr/bin/find: ‘/cygdrive/c/$Recycle.Bin/S-1-5-18’: Permission denied
/usr/bin/find: 探测到文件系统循环;‘/cygdrive/c/cygwin64’ 是与 ‘/’ 相同的文件系                                                                                                                统循环的一部分。
/usr/bin/find: ‘/cygdrive/c/inetpub/history’: Permission denied
/usr/bin/find: ‘/cygdrive/c/inetpub/logs/FailedReqLogFiles’: Permission denied
/usr/bin/find: ‘/cygdrive/c/inetpub/logs/LogFiles/W3SVC1’: Permission denied
/usr/bin/find: ‘/cygdrive/c/inetpub/temp/appPools’: Permission denied
/usr/bin/find: ‘/cygdrive/c/inetpub/temp/ASP Compiled Templates’: Permission den                                                                                                                ied
/usr/bin/find: ‘/cygdrive/c/inetpub/temp/IIS Temporary Compressed Files’: Permis                                                                                                                sion denied
/usr/bin/find: ‘/cygdrive/c/MSOCache’: Permission denied
/usr/bin/find: ‘/cygdrive/c/Program Files/WindowsApps’: Permission denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Crypto/PCPKSP/WindowsAIK’: Per                                                                                                                mission denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Network/Downloader’: Permissio                                                                                                                n denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Search/Data’: Permission denie                                                                                                                d
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Windows/AppRepository’: Permis                                                                                                                sion denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Windows/LocationProvider’: Per                                                                                                                mission denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Windows/Power Efficiency Diagn                                                                                                                ostics’: Permission denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Windows/Sqm’: Permission denie                                                                                                                d
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Windows/SystemData’: Permissio                                                                                                                n denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Windows/WER/ReportArchive’: Pe                                                                                                                rmission denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Windows/WER/ReportQueue’: Perm                                                                                                                ission denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Windows Defender’: Permission                                                                                                                 denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/Microsoft/Windows NT/MSFax’: Permission                                                                                                                 denied
/usr/bin/find: ‘/cygdrive/c/ProgramData/VMware/SSL’: Permission denied
/usr/bin/find: ‘/cygdrive/c/System Volume Information’: Permission denied
/usr/bin/find: ‘/cygdrive/c/Users/.NET v2.0’: Permission denied
/usr/bin/find: ‘/cygdrive/c/Users/.NET v2.0 Classic’: Permission denied
/usr/bin/find: ‘/cygdrive/c/Users/.NET v4.5’: Permission denied
/usr/bin/find: ‘/cygdrive/c/Users/.NET v4.5 Classic’: Permission denied
/usr/bin/find: ‘/cygdrive/c/Users/Classic .NET AppPool’: Permission denied
/usr/bin/find: ‘/cygdrive/c/Users/DefaultAppPool’: Permission denied
/usr/bin/find: ‘/cygdrive/c/Users/Shark/AppData/Local/ElevatedDiagnostics’: Perm                                                                                                                ission denied
/usr/bin/find: ‘/cygdrive/c/Users/UpdatusUser’: Permission denied
/usr/bin/find: ‘/cygdrive/c/Windows/AppCompat/Programs’: Permission denied




Shark@Lau /home/Xiaohe/ipfw3-2012/ipfw
$ ls
add_rules        glue.c             ipfw.8   ipv6.c    qsort.c       ws2_32.def
dummynet.c       humanize_number.c  ipfw2.c  main.c    qsort_r.c
expand_number.c  include            ipfw2.h  Makefile  rule_test.sh


Shark@Lau /home/Xiaohe/ipfw3-2012/ipfw
$ cd ../binary


Shark@Lau /home/Xiaohe/ipfw3-2012/binary
$ ls
cygwin1.dll  ipfw.exe  netipfw.inf    README.txt  wget.exe
ipfw.bat     ipfw.sys  netipfw_m.inf  testme.bat


Shark@Lau /home/Xiaohe/ipfw3-2012/binary
$ ./ipfw.exe
      0 [main] ipfw 5200 find_fast_cwd: WARNING: Couldn't compute FAST_CWD point                                                                                                                er.  Please report this problem to
the public mailing list cygwin@cygwin.com
ipfw: usage: ipfw [options]
do "ipfw -h" or "man ipfw" for details


Shark@Lau /home/Xiaohe/ipfw3-2012/binary
$ ipfw -h
-bash: ipfw: command not found


Shark@Lau /home/Xiaohe/ipfw3-2012/binary
$ ./ipfw.exe -h
      0 [main] ipfw 2612 find_fast_cwd: WARNING: Couldn't compute FAST_CWD point                                                                                                                er.  Please report this problem to
the public mailing list cygwin@cygwin.com
ipfw syntax summary (but please do read the ipfw(8) manpage):


        ipfw [-abcdefhnNqStTv] <command>


where <command> is one of the following:


add [num] [set N] [prob x] RULE-BODY
{pipe|queue} N config PIPE-BODY
[pipe|queue] {zero|delete|show} [N{,N}]
nat N config {ip IPADDR|if IFNAME|log|deny_in|same_ports|unreg_only|reset|
                reverse|proxy_only|redirect_addr linkspec|
                redirect_port linkspec|redirect_proto linkspec}
set [disable N... enable N...] | move [rule] X to Y | swap X Y | show
set N {show|list|zero|resetlog|delete} [N{,N}] | flush
table N {add ip[/bits] [value] | delete ip[/bits] | flush | list}
table all {flush | list}


RULE-BODY:      check-state [PARAMS] | ACTION [PARAMS] ADDR [OPTION_LIST]
ACTION: check-state | allow | count | deny | unreach{,6} CODE |
               skipto N | {divert|tee} PORT | forward ADDR |
               pipe N | queue N | nat N | setfib FIB | reass
PARAMS:         [log [logamount LOGLIMIT]] [altq QUEUE_NAME]
ADDR:           [ MAC dst src ether_type ]
                [ ip from IPADDR [ PORT ] to IPADDR [ PORTLIST ] ]
                [ ipv6|ip6 from IP6ADDR [ PORT ] to IP6ADDR [ PORTLIST ] ]
IPADDR: [not] { any | me | ip/bits{x,y,z} | table(t[,v]) | IPLIST }
IP6ADDR:        [not] { any | me | me6 | ip6/bits | IP6LIST }
IP6LIST:        { ip6 | ip6/bits }[,IP6LIST]
IPLIST: { ip | ip/bits | ip:mask }[,IPLIST]
OPTION_LIST:    OPTION [OPTION_LIST]
OPTION: bridged | diverted | diverted-loopback | diverted-output |
        {dst-ip|src-ip} IPADDR | {dst-ip6|src-ip6|dst-ipv6|src-ipv6} IP6ADDR |
        {dst-port|src-port} LIST |
        estab | frag | {gid|uid} N | icmptypes LIST | in | out | ipid LIST |
        iplen LIST | ipoptions SPEC | ipprecedence | ipsec | iptos SPEC |
        ipttl LIST | ipversion VER | keep-state | layer2 | limit ... |
        icmp6types LIST | ext6hdr LIST | flow-id N[,N] | fib FIB |
        mac ... | mac-type LIST | proto LIST | {recv|xmit|via} {IF|IPADDR} |
        setup | {tcpack|tcpseq|tcpwin} NN | tcpflags SPEC | tcpoptions SPEC |
        tcpdatalen LIST | verrevpath | versrcreach | antispoof


Shark@Lau /home/Xiaohe/ipfw3-2012/binary
$ ^C


Shark@Lau /home/Xiaohe/ipfw3-2012/binary
$

上述是我的使用过程,没有error,解决好 Couldn't compute FAST_CWD point   应该可以用配置网络。


至于在FreeBSD上配置Dummynet,比较复杂,首先需要安装FreeBSD,然后配置。具体方法如下,但我后来遇到些问题,没有配置成功。由于FreeBSD的版本间操作符有差异,而Dummynet的配置的具体资料又少的可怜,我找到的是基于FreeBSD 8.1的环境,我也用FreeBSD 10配置过,没成功。

1、FreeBSD系统的安装:

(1,2,3,……,系统的安装过程省略)

2、dummynet安装

我在FreeBSD8.1下面的安装最简单的方法是通过以 root 身份运行 sysinstall, 选择 Configure, 然后是 Distributionssrc,选中其中的 base 和 sys

 

3、接下来配置内核(因为要编译内核,过程比较慢very very )

内核文件默认路径 /usr/src/sys/i386/conf

A、在文件GENERIC中,所以需要先copy一份

# cd /usr/src/sys/i386/conf

# cp GENERIC dummynet-GENERIC

B、再编辑dummynet-GENERIC文件,添加以下几行

 options IPFIREWALL #在内核中添加防火墙支持
 options DUMMYNET #启用dummynet
 options IPFIREWALL_DEFAULT_TO_ACCEPT #把防火墙设置为默认接收包

C、配置内核

# config dummynet-GENERIC

D、编译内核

根据提示的路径进入,执行提示的相关命令

# cd ../compile/dummynet-GENERIC

# make cleandepend

# make depend

# make  (此时可以去休息了,过程灰常滴慢,俺在虚拟机编译了超过1个小时)

# make install

E、reboot重启系统,让新内核生效

检验内核中是否已经添加了防火墙,查看net.inet.ip.fw.enable的值

# sysctl net.inet.ip.fw.enable
net.inet.ip.fw.enable:1
#







这3天在实验室还是学到不少东西的,实验室气氛也不错,有好的Director对自己的进步会有很大的帮助。

0 0
原创粉丝点击