KVM简介,安装及常见使用详解 (4)

Bridge方式即虚拟网桥的网络连接方式,是客户机和子网里面的机器能够互相通信。可以使虚拟机成为网络中具有独立IP的主机。桥接网络(也叫 物理设备共享)被用作把一个物理设备复制到一台虚拟机。网桥多用作高级设置,特别是主机多个网络接口的情况。

┌─────────────────────────┐ ┌─────────────────┐ │ HOST │ │Virtual Machine 1│ │ ┌──────┐ ┌───────┐ │ │ ┌──────┐ │ │ │ br0 │──┬───│ vnet0 │─│─ ─ ─ │ │ br0 │ │ │ └──────┘ │ └───────┘ │ │ └──────┘ │ │ │ │ │ └─────────────────┘ │ │ │ ┌───────┐ │ ┌─────────────────┐ │ ┌──────┐ └───│ vnet1 │─│─ │Virtual Machine 2│ │ │ eno0 │ └───────┘ │ │ │ ┌──────┐ │ │ └──────┘ │ ─ ─ │ │ br0 │ │ │ ┌──────┐ │ │ └──────┘ │ │ │ eno1 │ │ └─────────────────┘ │ └──────┘ │ └─────────────────────────┘

通过ip命令查看宿主机配置文件的名字

ip addr 6: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 38:63:bb:44:cf:6c brd ff:ff:ff:ff:ff:ff inet 192.168.188.132/24 brd 192.168.188.255 scope global dynamic eno1 valid_lft 2822sec preferred_lft 2822sec inet6 fe80::3a63:bbff:fe44:cf6c/64 scope link valid_lft forever preferred_lft forever

可以看到上面eno1是有获取到ip地址的,相对应的文件在/etc/sysconfig/network-scripts/目录中,ifcfg-eno1 宿主机的物理网卡配置文件

# cat ifcfg-eno1 TYPE=Ethernet BOOTPROTO=static NAME=eno1 DEVICE=eno1 UUID=242b3d4d-37a5-4f46-b072-55554c185ecf ONBOOT=yes BRIDGE="br0" # 指定桥接网卡的名称

ifcfg-br0 桥接网卡配置在同一个目录中。

# cat ifcfg-br0 BOOTPROTO=static DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=br0 UUID=242b3d4d-37a5-4f46-b072-55554c185ecf DEVICE=br0 ONBOOT=yes TYPE=bridge # 将制定为桥接类型 IPADDR=192.168.188.133 # 设置IP地址 PREFIX=24 # 设置子网掩码 GATEWAY=192.168.188.1 # 设置网关

配置好之后,通过systemctl 命令重启网卡。

ifup eno1 # 激活网卡 ifup br0 # 激活桥接网卡 # 两种重启网络的方法 systemctl restart network.service service network restart # 校验桥接接口 brctl show bridge name bridge id STP enabled interfaces br0 8000.3863bb44cf6c no eno1 vnet0 virbr0 8000.525400193f0f yes virbr0-nic NAT模式

NAT(Network Address Translation网络地址翻译),NAT方式是kvm安装后的默认方式。它支持主机与虚拟机的互访,同时也支持虚拟机访问互联网,但不支持外界访问虚拟机。

virsh net-edit default # 如果要创建或者修改NAT网络,要先编辑default.xml: virsh net-list --all Name State Autostart Persistent ---------------------------------------------------------- default active no no

default是宿主机安装虚拟机支持模块的时候自动安装的。

ip a l 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens1f0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 2c:44:fd:8c:43:44 brd ff:ff:ff:ff:ff:ff 3: ens1f1: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 2c:44:fd:8c:43:45 brd ff:ff:ff:ff:ff:ff 4: ens1f2: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 2c:44:fd:8c:43:46 brd ff:ff:ff:ff:ff:ff 5: ens1f3: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 2c:44:fd:8c:43:47 brd ff:ff:ff:ff:ff:ff 6: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP qlen 1000 link/ether 38:63:bb:44:cf:6c brd ff:ff:ff:ff:ff:ff 7: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 38:63:bb:44:cf:6d brd ff:ff:ff:ff:ff:ff 8: eno3: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 38:63:bb:44:cf:6e brd ff:ff:ff:ff:ff:ff 9: eno4: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000 link/ether 38:63:bb:44:cf:6f brd ff:ff:ff:ff:ff:ff 10: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN link/ether 52:54:00:19:3f:0f brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 11: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500 link/ether 52:54:00:19:3f:0f brd ff:ff:ff:ff:ff:ff 12: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether 38:63:bb:44:cf:6c brd ff:ff:ff:ff:ff:ff inet 192.168.188.132/24 brd 192.168.188.255 scope global dynamic br0 valid_lft 3397sec preferred_lft 3397sec inet 192.168.188.133/24 brd 192.168.188.255 scope global secondary br0 valid_lft forever preferred_lft forever inet6 fe80::3a63:bbff:fe44:cf6c/64 scope link valid_lft forever preferred_lft forever 19: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 500 link/ether fe:54:00:72:12:a8 brd ff:ff:ff:ff:ff:ff inet6 fe80::fc54:ff:fe72:12a8/64 scope link valid_lft forever preferred_lft forever

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpwgxj.html