KVM (虚拟化网络管理)

时间:2022-12-24 10:04:57

vlan:https://www.cnblogs.com/du-z/p/10802786.html
trunk:https://www.cnblogs.com/du-z/p/10804773.html
vmware虚拟机网络详解:https://note.youdao.com/ynoteshare1/index.html?id=236896997b6ffbaa8e0d92eacd13abbf&type=note

KVM网络模式--Bridge网桥

网桥架构图

KVM (虚拟化网络管理)

Linux Bridge : 基本原理就是创建一个桥接接口 br0 ,在物理网卡和虚拟网络接口之间传递数据,此种方式host却可以和vm联通。

vim /etc/sysconfig/network-scripts/ifcfg-eth0 

...
TYPE=Ethernet
NAME=eth0
DEVICE=eth0
ONBOOT=yes
BRIDGE=br0
...
vim /etc/sysconfig/network-scripts/ifcfg-br0 

...
TYPE=Bridge
NAME=br0
DEVICE=br0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.137.134
PREFIX=24
GATEWAY=192.168.137.2
DNS=8.8.8.8
DNS2=114.114.114.114
...

brchl 网桥管理命令

拓展:图形化管理网卡命令:nmtui 依靠于NetworkManager服务

##brctl show 查看网桥配置

[root@localhost ~]# brctl show
bridge name bridge id       STP enabled interfaces
br0     8000.000c294ea15a   no      ens33
virbr0      8000.525400eb441b   yes     virbr0-nic


##brctl 命令帮助手册

[root@localhost ~]# brctl --help
Usage: brctl [commands]
commands:
    addbr       <bridge>        add bridge  #添加网桥
    delbr       <bridge>        delete bridge  #删除网桥
    addif       <bridge> <device>   add interface to bridge  #向网桥添加接口
    delif       <bridge> <device>   delete interface from bridge   #删除网桥上接口
    hairpin     <bridge> <port> {on|off}    turn hairpin on/off
    setageing   <bridge> <time>     set ageing time
    setbridgeprio   <bridge> <prio>     set bridge priority
    setfd       <bridge> <time>     set bridge forward delay
    sethello    <bridge> <time>     set hello time
    setmaxage   <bridge> <time>     set max message age
    setpathcost <bridge> <port> <cost>  set path cost
    setportprio <bridge> <port> <prio>  set port priority
    show        [ <bridge> ]        show a list of bridges  #查看网桥列表
    showmacs    <bridge>        show a list of mac addrs #查看物理地址列表
    showstp     <bridge>        show bridge stp info
    stp         <bridge> {on|off}   turn stp on/off

Linux Bridge实现Vlan

KVM (虚拟化网络管理)

第一步:查看核心是否提供vlan功能,并载入8021q模块

[root@localhost ~]# lsmod |grep 8021q
[root@localhost ~]# modprobe 8021q
[root@localhost ~]# lsmod |grep 8021q
8021q                  33104  0 
garp                   14384  1 8021q
mrp                    18542  1 8021q

第二步:设置开机载入8021q模块(可选)

# 在/etc/sysconfig/modules下增加一个8021q.modules文件

[root@localhost ~]# vim /etc/sysconfig/modules/8021q.modules
...
modprobe 8021q
...

第三步:安装vlan配置工具--vconfig

[root@localhost ~]# rpm -ivh vconfig-1.9-16.el7.x86_64.rpm   #需用网络源

[root@localhost ~]# rpm -qa |grep vconfig
vconfig-1.9-16.el7.x86_64

第四步:在设备器上再添加一块网卡ens38


[root@localhost ~]# ifconfig

ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.137.137  netmask 255.255.255.0  broadcast 192.168.137.255
        inet6 fe80::f34c:437:4b83:f0b4  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:30:5c:f9  txqueuelen 1000  (Ethernet)
        RX packets 12004  bytes 915163 (893.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1195  bytes 233853 (228.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

## 注意:修改网卡配置文件中:BOOTPROTO=static

第五步:用vlan管理工具vconfig添加vlan

# vconfig add ens38 10
# vconfig add ens38 10

第六步:撰写vlan接口文件,vlan网桥文件

vlan接口文件:

# vim ifcfg-ens38.10

VLAN=yes    #启用vlan
TYPE=vlan    #类型vlan
PHYSDEV=ens38vlan     #物理设备网卡
VLAN_ID=10       #vlan_id
ONBOOT=yes    # 自启
ZONE=trusted       #开启作用域
DEVICE=ens38.10    #设备名
BRIDGE=brvlan10    #网桥

# vim ifcfg-ens38.20

VLAN=yes
TYPE=vlan
PHYSDEV=ens38
VLAN_ID=20
ONBOOT=yes
ZONE=trusted
DEVICE=ens38.20
BRIDGE=brvlan20

vlan网桥文件:

## vim ifcfg-brvlan-10

YPE=bridge
BOOTPROTO=static
NAME=brvlan-10
DEVICE=brvlan-10
ONBOOT=yes

## vim ifcfg-brvlan-20

TYPE=bridge
BOOTPROTO=static
NAME=brvlan-20
DEVICE=brvlan-20
ONBOOT=yes

第七步:给vlan网桥添加接口

# brctl addif brvlan-10 ens38.10
# brctl addif brvlan-20 ens38.20

第八步:重启网卡

# systemctl restart network

KVM (虚拟化网络管理)