最新消息:

virsh 创建虚拟交换机

virsh admin 581浏览 0评论

新建 ihh.xml

# cat /etc/libvirt/qemu/networks/ihh.xml
<network>
  <name>ihh</name>   # 名称
  <forward mode='nat'/
  <bridge name='ihh0' stp='on' delay='0'/>    # 新桥接接口
  <mac address='52:54:00:cb:ac:6e'/>  # 网关mac
  <ip address='192.168.166.1' netmask='255.255.255.0'>  # 网关ip
    <dhcp>
      <range start='192.168.166.10' end='192.168.166.254'/>   # dhcp 
    </dhcp>
  </ip>
</network>

dhcp 默认会启动 dnsmasq 进行分配, 也可以不添加手动分配

启动 ihh 接口

 # virsh net-define /etc/libvirt/qemu/networks/ihh.xml
 # virsh net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 ihh                  inactive   no            yes
 # virsh net-start ihh
Network ihh started
 #  ifconfig ihh0
 ihh0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.166.1  netmask 255.255.255.0  broadcast 192.168.166.255
        ether 52:54:00:cb:ac:6e  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 # virsh net-autostart ihh
 # virsh net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 ihh                  active     yes           yes

修改虚拟机 xml 桥接到 ihh0 接口

    <interface type='bridge'>
      <source bridge='ihh0'/>
      <mac address='fa:16:fb:16:a9:cb' />
      <model type='virtio'/>
    </interface>

iptables 配置 双向nat

  • dnat
-A PREROUTING -d 5.5.5.5/32 -j DNAT --to-destination 192.168.166.10
  • snat
-A POSTROUTING -s 192.168.166.10/32 -o eth0 -j SNAT --to-source 5.5.5.5

Iptables处理数据包详细流程图

转发:

virsh 创建虚拟交换机

转载请注明:爱开源 » virsh 创建虚拟交换机

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址