设为首页 收藏本站
查看: 1382|回复: 0

[经验分享] Vmware中的虚拟网络 ( by quqi99 )

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-10-8 12:13:52 | 显示全部楼层 |阅读模式
  

Vmware中的虚拟网络 ( by quqi99 )

  
作者:张华  发表于:2013-03-27
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明

( http://blog.iyunv.com/quqi99 )
  
  导读:hyper-v需要安装上支持虚拟化的物理机上,但是没有物理机啊。怎么办呢?就是通过Vmware来虚拟,更难能可贵的是,虚出一虚机也能支持硬件虚拟化,这里可以在Vmware的虚机里来安装hyper-v。更一方面,想做vlan方面的实验,得把vmware的虚拟网络的原理搞明白。

  1 安装vmware workstation 9.0.2 for linux, 可参考:http://www.iyunv.com/Linux/2012-10/73141.htm
2 用vmware创建一个虚机用于安装windows 2012 server, 给了16G的硬盘空间, 并在此启用hyper-v角色。网络为vmware的NAT模式。
   2.1 因为是在虚拟机上又虚拟化,所以确保vmware虚拟机setting选项中的processors启用了Virtualize intel VT-x/EPT or ADM-V/RVT和Virtualize cpu performance counters这两个选项, 参见:http://hi.baidu.com/cjp19882009/item/a72f743636b42880f4e4ad6e  或http://communities.vmware.com/docs/DOC-8970/
   2.2 再修改配置文件/run/media/hua/E/vmwareimage/WindowsServer2012/WindowsServer2012.vmx,添加下面两行。
        hypervisor.cpuid.v0 = "FALSE"
        mce.enable = "TRUE"
   2.3 最后,关闭windows server 2012的防火墙。
   2.4 在hyper-v管理器中创建一网桥br-int, 它报错:The virtual machine's operating system has attempted to enable promiscuous mode on adapter Ethernet0. This is not allowed for security reasons. Please go to the Web page "http://vmware.com/info?id=161" for help enabling promiscuousmode in the virtual machine.
       所以需要人工将网卡vmnet8(NAT模式使用的是vmnet8)设置为混杂模式,因为vmnet8网卡是由root用户安装的,而vmware workstation是通过普通用户hua启动的。对于不使用udev而直接用/dev的linux的改动如下:
        http://blog.martinshouse.com/2011/05/vmware-on-linux-promiscuous-mode.html
    [hua@zhanghua WindowsServer2012]$ sudo groupadd vmwaregroup
    [hua@zhanghua WindowsServer2012]$ sudo usermod -a -G vmwaregroup hua
    [hua@zhanghua WindowsServer2012]$ id hua
        uid=1000(hua) gid=1000(hua) groups=1000(hua),1001(libvirtd),1002(vmwaregroup)
    [hua@zhanghua WindowsServer2012]$ sudo chgrp vmwaregroup /dev/vmnet8
    [hua@zhanghua WindowsServer2012]$ sudo chmod g+rw /dev/vmnet8
    [hua@zhanghua WindowsServer2012]$ ll /dev/vmnet8
    crw-rw---- 1 root vmwaregroup 119, 8 Mar 20 09:49 /dev/vmnet8
    [hua@zhanghua WindowsServer2012]$ sudo chmod a+rw /dev/vmnet8
    [hua@zhanghua WindowsServer2012]$ ll /dev/vmnet8
    crw-rw-rw- 1 root vmwaregroup 119, 8 Mar 20 09:49 /dev/vmnet8
        sudo service vmware restart

        上述方法在系统重启后会消失,A more permanent fix is to edit /etc/init.d/vmware on the Host, by adding the lines in red:
      # Start the virtual ethernet kernel service
       vmwareStartVmnet() {
          vmwareLoadModule $vnet
          "$BINDIR"/vmware-networks --start >> $VNETLIB_LOG 2>&1
          chgrp vmwaregroup  /dev/vmnet*
          chmod a+rw /dev/vmnet*

        在上面设置了之后,当客户机里使用像wireshark之类的抓包工具时,它会将客户机的网卡设置为混杂模式,这时候vmware也会将vmnet8自动设置成混杂模式(ifconfig vmnet8 promisc)。

        下面验证一下,netif5确实是IFF_PROMISC的了。netif5指内核的虚拟网卡设备, userif17是用户态实现的nat设备的字符设备接口, hub8.x是网桥中的一个端口
    [iyunv@zhanghua vmnet]# cat /proc/vmnet/hub8.0
    connected netif5 tx 23
    [iyunv@zhanghua vmnet]# cat /proc/vmnet/netif5
    connected hub8.0 mac 00:50:56:c0:00:08 ladrf 00:00:00:00:00:00:00:00 flags IFF_RUNNING,IFF_UP,IFF_PROMISC devvmnet8
    [iyunv@zhanghua vmnet]# cat /proc/vmnet/hub8.1
    connected userif17 tx 0
    [iyunv@zhanghua vmnet]# cat /proc/vmnet/userif17
    connected hub8.1 mac 00:50:56:e3:d1:e0 ladrf 00:00:00:00:00:00:00:00 flags IFF_RUNNING,IFF_UP,IFF_BROADCAST read 0 written 0 queued 0 dropped.down 0 dropped.mismatch 20 dropped.overflow 0 dropped.largePacket 0
    [iyunv@zhanghua vmnet]# cat /proc/vmnet/hub8.2
    connected userif18 tx 0
    [iyunv@zhanghua vmnet]# cat /proc/vmnet/userif18
    connected hub8.2 mac 00:50:56:f6:3a:6b ladrf 00:00:00:00:00:00:00:00 flags IFF_RUNNING,IFF_UP,IFF_BROADCAST,IFF_ALLMULTI read 19 written 0 queued 19 dropped.down 0 dropped.mismatch 0 dropped.overflow 0 dropped.largePacket 0
  
        说明一下,vmware并没有使用内核来实现nat, 因为ipforward=0, 它是由vmnet-natd来实转发的。
        [iyunv@zhanghua vmnet]# ps -ef|grep vmnet-natd
        root      9921     1  0 13:25 ?        00:00:00 /usr/bin/vmnet-natd -s 12 -m /etc/vmware/vmnet8/nat.mac -c /etc/vmware/vmnet8/nat/nat.conf
        例如,VM的IP为172.16.138.128,而/etc/vmware/vmnet8/nat/nat.conf文件定义了NAT gateway address是172.16.138.2,也可定义DNAT规则例:8080=172.16.3.128:80
        [host]
    # NAT gateway address
    ip = 172.16.138.2
    [incomingtcp]
    #8080 = 172.16.3.128:80
        很显然,vmware是natd与VM的虚拟网卡进程进行TCP通讯时进行的NAT转换,也就是从/dev/vmnet8 ( vmnet8 equals br-tun) 中读出以太帧取出目的IP和协议,然后自己和远程通信

       下面是命令演示如何创建vmware桥:
           vmnet-bridge -n 4 -i eth2 -d /var/run/vmnet-bridge-4.pid -1vmnet4
           mknod /dev/vmnet4  c  119 4
           vmnet-netifup -d /var/run/vmnet-netifup-vmnet4.pid /dev/vmnet4 vmnet4
           ifconfig eth2 0.0.0.0 proimsc up
   
     虚机中使用桥,将以下命令行内容添加到vmx文件:
           ethetnet0.connectionType = "custom"
           ethernet0.vnet = "vmnet4"


  这里老外有个建议,说是最好用bridge,而不是nat, 如下:
      you'll be able to boot your Guest VM, and use Wireshark or whatever in the Guest.  Just Remember!   Your VM Guest's Network Adapter must be set to BRIDGED (connected directly to the physical network), not NAT (used to share the host's IP address).
  
    2.5 关于vmware中的vlan
        vmware中的vlan有三种方式, 可参见Vmware ESX Server 3 802.1Q解决方案:http://wenku.baidu.com/view/90b76687ec3a87c24028c4b9.html
        1, VGT 即在虚机里就打了标签, 将端口组的vlan_id属性设为4095(相当于端口组就设为TRUCK了), 并且在虚拟机中运行802.1Q VLAN trunking驱动。
        2,EST 在外部交换机打标签, 默认行为,端口组的vlan_id属性为0,相当于disable掉了端口组的tag功能 。
        3,VST 在vmware的虚拟交换机上打标签, vmware用了端口组的概念,所以想定义一个vlan的话就要定义一个端口组,在端口组的vlan_id属性设值(1-4094)。然后虚机和端口组关联。
           To configure a VLAN on the portgroup using the VMware Infrastructure/vSphere Client:
        Click the ESXi/ESX host.
        Click the Configuration tab.
        Click the Networking link.
        Click Properties.
        Click the virtual switch / portgroups in the Ports tab and click Edit.
        Click the General tab.
        Assign a VLAN number in VLAN ID (optional).
        Click the NIC Teaming tab.
        From the Load Balancing dropdown, choose Route based on originating virtual port ID.
        Verify that there is at least one network adapter listed under Active Adapters.
        Verify the VST configuration using the ping command to confirm the connection between the ESXi/ESX host and the gateway interfaces and another host on the same VLAN.

        Note: For additional information on VLAN configuration of a VirtualSwitch (vSwitch) port group, see Configuring a VLAN on a portgroup (1003825).

    To configure via the command line:
        esxcfg-vswitch -p "portgroup_name" -v VLAN_ID virtual_switch_name
          参见文章:Sample configuration of virtual switch VLAN tagging (VST Mode) (1004074)
                   http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1004074
  

  所以想要把esx设置为trunk模式的话(VGT),需要做两件事:
  1)配置一个端口组, vlan_id关联为4095, 步骤如上。
  2)  这种VGT模式还需要特定的虚机网卡驱动 ( 802.1Q VLAN trunking driver is required inside the virtual machine. )
  见: Sample configuration of virtual machine (VM) VLAN Tagging (VGT Mode) in ESX (1004252)
  http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1004252
  3)将物理网卡配置成混杂模式promisc, 步骤是:
  

  • Log into the ESXi/ESX host or vCenter Server using the vSphere Client.
  • Select the ESXi/ESX host in the inventory.
  • Click the Configuration tab.
  • In the Hardware section, click Networking.
  • Click Properties of the virtual switch for which you want to enable promiscuous mode.
  • Select the virtual switch or portgroup you wish to modify and click Edit.
  • Click the Security tab.
  • From the Promiscuous Mode dropdown menu, click Accept.
  2013-04-05加:
  使用vmware的虚机来做vlan相关的网络实验时,注意使用e1000网卡,它默认用的是vmnet3是一个半虚拟化的网卡对vlan支持不好。包括两个层面,一是vmware处要设置虚机使用e1000网卡,二是虚机内部要安装e1000驱动(可用lspci |grep Eth命令查看网卡类型)。另外,使用VGT模式,即vmware的虚拟交换机要是trunk,端口组配置的vlan_id为4095

  

  

  2013-04-26,总结一下,这种VMware上的虚机做控制节点,一台物理机做计算节点的来做vlan实验时,要保证:
  在虚机里面打tag (这样虚机内部的网卡驱动得支持vlan最好用e1000,并且打开8021q模块 modprobe 8021q),这样的话,也即hypervisor (VMware)的虚拟网桥与虚机相连的端口要支持TRUNK。
  

  同理,如果是一个hyper-v上的虚机做控制节点,它自己这台物理机做计算节点来做vlan实验的话,原理同上。
  1,hyper-v中给一个虚拟网卡的所在虚拟交换机上的端口设置TRUNK,
  Get-VMNetworkAdapter  -VMName "scem1-hvsce_0415"
      Set-VMNetworkAdapterVlan -VMName "scem1-hvsce_0415" -Trunk -NativeVlanId 1 -AllowedVlanIdList 1-4094 -VMNetworkAdapterName "SCE_DATA_NIC2"
  见:HOWTO: Fully virtualized lab using Hyper-V 3.0 and GNS3 http://forum.gns3.net/topic5735.html
  2, modprobe 8021q
  3, 至于hyper-v中的网卡驱动问题,好像无法安装e1000,
  用命令(ethtool -i eth2 &&sudo modinfo hv_netvsc )你会发现hyper-v中的虚机使用的是windows自己的hv_netvsc网卡驱动。
  这个网址说(http://stackoverflow.com/questions/14389722/hyper-v-network-adapter-drivers)hyper-v中的网卡分为emulated和synthetic两类,我的理解是前者是半虚拟化网卡,后者才是正常网卡。但要安装正常网卡,还需要安装一个额外的驱动Integration Service, windows xp已经带了这个驱动,但对于Linux需要自己下载的安装,最新版本是3.4,下载地址: http://www.microsoft.com/en-gb/download/details.aspx?id=34603, 要支持vlan得安装这个驱动。ibm的一个网页也是这么说的,http://pic.dhe.ibm.com/infocenter/tivihelp/v48r1/index.jsp?topic=%2Fcom.ibm.scp.doc_2.1.0%2Finstalling%2Fr_limits_hyperv.html


  
         版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-124297-1-1.html 上篇帖子: VirtualBox 和 Vmware 的比较(转) 下篇帖子: VMWare安装Ubuntu装完之后安装VMtools
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表