为什么要创建私有网络?

当然是为了隔离一些服务,用这种环境来测试某些服务了!

准备工作

查看 kvm 现有的网络:

1
2
3
4
$ virsh net-list --all
Name State Autostart Persistent
--------------------------------------------
default active yes yes

新建网络

1.复制默认的网桥配置文件:

1
$ sudo cp /etc/libvirt/qemu/networks/default.xml /etc/libvirt/qemu/networks/mynet.xml

2.编辑新的网络配置文件,修改如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh net-edit mynet
or other application using the libvirt API.
-->

<network>
<name>mynet</name>
<uuid>9c8eca23-2268-4aa8-b754-a8d4d131d826</uuid>
<bridge name='virbr1' stp='on' delay='0'/>
<mac address='52:54:00:7d:f5:2d'/>
<ip address='192.168.137.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.137.2' end='192.168.137.254'/>
</dhcp>
</ip>
</network>

3.加载私有网络:

1
2
$ sudo virsh net-define /etc/libvirt/qemu/networks/mynet.xml
Network mynet defined from /etc/libvirt/qemu/networks/mynet.xml

4.再次查看网络:

1
2
3
4
5
$ sudo virsh net-list --all
Name State Autostart Persistent
----------------------------------------------
default active yes yes
mynet inactive no yes