MAC OSX dynamips bundle Loopback Port

在09年我总结过在linux上如何建立tap口,并连接dynampis,传送到《Linux Ubuntu dynamips bundle Loopback Port》,现在工作平台转到MAC上了,MAC如何绑定tap口呢?
首先去http://tuntaposx.sourceforge.net下载相应的driver并安装,安装后你就可以看到dev中已经有相应的设备了:

x-mac:dev yong$ ls /dev/tap*
/dev/tap0	/dev/tap11	/dev/tap14	/dev/tap3	/dev/tap6	/dev/tap9
/dev/tap1	/dev/tap12	/dev/tap15	/dev/tap4	/dev/tap7
/dev/tap10	/dev/tap13	/dev/tap2	/dev/tap5	/dev/tap8


但是如果你用ifconfig配置这些端口时会报错:

x-mac:dev yong$ sudo ifconfig tap0 10.10.10.1 netmask 255.255.255.0
ifconfig: interface tap0 does not exist

问题在于没有client调用这些tap端口,所以你不能配置,暂时先放下,去配置.net文件:

    [[router R4]]
    f2/0 = NIO_tap:/dev/tap0

开启dynamips并打开.net文件,此时再去配置tap0试试?是不是ok了~

x-mac:dev yong$ sudo ifconfig tap0 10.10.10.1 netmask 255.255.255.0
x-mac:dev yong$ ifconfig tap0
tap0: flags=8843<up,broadcast,running,simplex,multicast> mtu 1500
	ether fe:7c:3a:31:48:c2 
	inet 10.10.10.1 netmask 0xffffff00 broadcast 10.10.10.255
	open (pid 35722)
x-mac:dev yong$ ping 10.10.10.2
PING 10.10.10.2 (10.10.10.2): 56 data bytes
64 bytes from 10.10.10.2: icmp_seq=0 ttl=255 time=0.962 ms
64 bytes from 10.10.10.2: icmp_seq=1 ttl=255 time=2.880 ms
64 bytes from 10.10.10.2: icmp_seq=2 ttl=255 time=2.388 ms
64 bytes from 10.10.10.2: icmp_seq=3 ttl=255 time=0.798 ms
^C
--- 10.10.10.2 ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.798/1.757/2.880/0.896 ms

ok,接下来又有新问题了,我想拿台测试的VM跟router连,怎么连接?
首先选择Preferences -> 网络 -> 添加,如图所示:
dynamips-mac-01
然后通过命令把新建的vmnet和tap0桥接起来,由于MAC版的vmware Fusion没有这方面的GUI(没windows强大),所以只能通过命令行,不过很简单:

x-mac:dev yong$ sudo ifconfig bridge0 create
x-mac:dev yong$ sudo ifconfig bridge0 addm vmnet4
x-mac:dev yong$ sudo ifconfig bridge0 addm tap0
x-mac:dev yong$ sudo ifconfig bridge0 up

现在一切都ok了,但是如果你不是用tap连接VM和router,而是用tap连接MAC和router,那么对于MAC来说可能需要加条静态路由,加路由的命令行方法如下:

x-mac:dev yong$ sudo route -nv add -net 10.1.1.0 172.16.100.1
u: inet 10.1.1.0; u: inet 172.16.100.1; RTM_ADD: Add Route: len 132, pid: 0, seq 1, errno 0, flags:<up,gateway,static>
locks:  inits: 
sockaddrs: <dst,gateway,netmask>
 10.1.1.0 172.16.100.1 (0) 0 ffff ff
add net 10.1.1.0: gateway 172.16.100.1
x-mac:dev yong$ netstat -rn | egrep 'Use|10.1.1'
Destination        Gateway            Flags        Refs      Use   Netif Expire
10.1.1/24          172.16.100.1       UGSc            0        0     en0

2014-8-26 更新:
1. 扩展MAC bridge 命令,上面只说了加member,那么去member和如何去掉bridge呢?

sudo ifconfig bridge0 create
sudo ifconfig bridge0 up
sudo ifconfig bridge0 addm en0 addm en3
sudo ifconfig bridge0 down
sudo ifconfig bridge0 deletem en0 deletem en3
sudo ifconfig bridge0 destroy

2. 但直接连vmnet和dynamics时,报“206-unable to create generic ethernet NIO”
经查找,MAC上不支持直接绑定vmnet,但在linux上和windows上可以直接绑定,有人已经确认过这个问题了,看下面内容:

Quote: Why not direct connect via the vmnet? Simple. It doesn’t work on the Mac (unlike Windows and Linux).

That what I thought, I had tested on Windows and Linux, I remember it worked well. I just tested on OSX to at least understand what is wrong… First test was to attach to a vboxnet interface (created by VirtualBox), worked ok. Second test, tried to attach to a vmnet interface and I got exactly the same problem you have described. Third test, started Dynamips manually on port 7200, opened a Telnet connection to it and entered the following command:

Quote: unable to open device ‘vmnet2’ with PCAP

We can see the exact error message from libpcap: vmnet2: No such device exists (BIOCSETIF failed: Device not configured. I did some research and it appears the issue is with VMware fusion itself. Other software using libpcap have the exact same issue as Dynamips. The reason is that VMware Fusion vmnet interfaces have not implemented BPF (what is BPF? => http://en.wikipedia.org/wiki/Berkeley_Packet_Filter)

The issue exists since 2007 and VMware haven’t done anything about it. So, I think we have a dead end here… at least we know why we cannot use vmnet interfaces directly now 🙂

Quote: The only method that works for me is the [bridge:tap+vmnet] combo. Even if I direct connect via the bridge interface w/ only the vmnet as a member (omitting the tap interface), it will connect but fail to pass traffic between the connected devices.

I actually prefer the decoupled aspect to this type of configuration; it minimizes the dependency between the applications:

2013-12-29 更新:telnet issue for tcp connect
“telnet: connect to address 127.0.0.1: Operation timed out”

不管是dynamips还是GNS,有时telnet会莫名其妙的丢失,telnet后会报上面的错误,记得当年在linux上用时,只有从公网通过NAT访问内网时,TP-link的路由器为了保护自己,会中断不活动的tcp,导致问题出现,但本地登录不了的现象好像没遇到过,ok,那么看看tcp是否有问题:

x-mac:~ yong$ netstat -p "tcp"
Active Internet connections
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)    
tcp4       0      0  172.16.100.2.58691     198-57-242-168.u.http  CLOSE_WAIT 
tcp4       0      0  172.16.100.2.58690     nsa-rcdn-001p.ci.http  SYN_SENT   
tcp4       0      0  172.16.100.2.58689     mail-rcd.cisco.c.http  SYN_SENT 
......

x-mac:~ yong$ lsof -i -P | grep -i "listen"
TeamViewe   458 yong   12u  IPv4 0x921e2b32d2579349      0t0  TCP localhost:6040 (LISTEN)
RosettaSt   776 yong    3u  IPv4 0x921e2b32d49cb349      0t0  TCP localhost:55568 (LISTEN)
RosettaSt   776 yong    4u  IPv6 0x921e2b32b7397241      0t0  TCP localhost:55568 (LISTEN)
......

根据上面的命令,没有发现异常的tcp连接,下面是完整报错截图:

Last login: Sun Dec 29 08:27:19 on ttys003
x-mac:~ yong$ telnet localhost 2001 ; exit
Trying 127.0.0.1...

telnet: connect to address 127.0.0.1: Operation timed out
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
telnet: Unable to connect to remote host
logout

重启一台路由器试试,发现能解决……我试验用的路由器还没保存配置,不想重启……看看MAC OSX的路由状况,发现了一些异常:

x-mac:~ yong$ netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH             42 14427525     lo0

x-mac:~ yong$ ifconfig lo0
lo0: flags=8049<up,loopback,running,multicast> mtu 16384
        options=3<rxcsum,txcsum>
        inet6 ::1 prefixlen 128 
        inet 127.0.0.1 netmask 0xff000000 
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
        nd6 options=1

这个use不太正常,所有路由器都是连接127.0.0.1的,能否把这个lo0重启试试?

x-mac:~ yong$ sudo ifconfig lo0 down
x-mac:~ yong$ 
x-mac:~ yong$ netstat -rn |grep "127"
x-mac:~ yong$ sudo ifconfig lo0 up
x-mac:~ yong$ netstat -rn |grep "127"
127.0.0.1          127.0.0.1          UH             18     4714     lo0
172.16.100.2       127.0.0.1          UHS             0        0     lo0

问题解决了,下面是在正常情况下show出来的信息:

x-mac:~ yong$ lsof -i -P | grep -i "Secure"
SecureCRT 67500 yong   17u  IPv4 0x921e2b32ba287b61      0t0  TCP localhost:59000->localhost:2003 (ESTABLISHED)
SecureCRT 67500 yong   22u  IPv4 0x921e2b32dbabb349      0t0  TCP localhost:59001->localhost:2000 (ESTABLISHED)
SecureCRT 67500 yong   24u  IPv4 0x921e2b32da359b61      0t0  TCP localhost:59175->localhost:2005 (ESTABLISHED)
SecureCRT 67500 yong   28u  IPv4 0x921e2b32ba982349      0t0  TCP localhost:59003->localhost:2002 (ESTABLISHED)
SecureCRT 67500 yong   30u  IPv4 0x921e2b32d4b4fb61      0t0  TCP localhost:59173->localhost:2001 (ESTABLISHED)
SecureCRT 67500 yong   35u  IPv4 0x921e2b32da356b61      0t0  TCP localhost:59171->localhost:2004 (ESTABLISHED)

x-mac:~ yong$ netstat -nv |egrep "127.0.0.1.200" | awk '$4 ~"127.0.0.1.200.*"'
tcp4       0      0  127.0.0.1.2005         127.0.0.1.59175        ESTABLISHED
tcp4       0      0  127.0.0.1.2001         127.0.0.1.59173        ESTABLISHED
tcp4       0      0  127.0.0.1.2004         127.0.0.1.59171        ESTABLISHED
tcp4       0      0  127.0.0.1.2002         127.0.0.1.59003        ESTABLISHED
tcp4       0      0  127.0.0.1.2000         127.0.0.1.59001        ESTABLISHED
tcp4       0      0  127.0.0.1.2003         127.0.0.1.59000        ESTABLISHED

注:<、<=、==、!=、>=、~匹配正则表达式、!~不匹配正则表达式

参考文章:
Integrate VMware Fusion with GNS3 on your Mac

本文出自 Frank's Blog

版权声明:


本文链接:MAC OSX dynamips bundle Loopback Port
版权声明:本文为原创文章,仅代表个人观点,版权归 Frank Zhao 所有,转载时请注明本文出处及文章链接
你可以留言,或者trackback 从你的网站

留言哦

blonde teen swallows load.xxx videos