kvm 安装 虚拟机 default所在的网段被eth0占用[忘关防火墙惹的祸]
1 | https://www.it610.com/article/1963128.htm |
今天在虚拟机 192.168.122.175 上再装kvm,进入二层虚拟机.
1. 安装虚拟机
1 | virt-install --name kvm11 --ram 1024 --vcpus=1 --file=/home/images/kvm11.qcow2 --file-size=10 --autostart --vnc --vncport=5911 --video=vga --vnclisten=0.0.0.0 --network network=default --cdrom=/home/iso/CentOS-7.iso |
2. 出现报错
1 2 | error: Failed to start network default error: internal error Network is already in use by interface eth0 |
1 | virsh net-list --all |
会输出如下信息:
1 2 3 | Name State Autostart Persistent ---------------------------------------------------------- default inactive yes yes |
1. 分析原因.
1层虚拟机 默认是:192.168.122.x
2层虚拟机 默认是:192.168.122.x
1层虚拟机 与 2层虚拟机IP段相冲突.
2. 解决办法:
2-1. ONBOOT先改为NO,以免相冲突,virbr0启动不了.
1 | vi /etc/sysconfig/network-scripts/ifcfg-eth0 |
1 | ONBOOT=yes //改回 ONBOOT=no |
1 | reboot //重启服务器 |
2-2. 查看virtual network default NAT 是否正常.
1 | virsh net-list --all |
如果输出信息如下.则表明正常.
1 2 3 | Name State Autostart Persistent ---------------------------------------------------------- default active yes yes |
2-3. 把二层虚拟改成 192.168.123.x
1 | find / -name 'default.xml' //查找default.xml文件 |
2-3-1. 会输出如下信息
1 2 3 4 5 6 7 8 9 | /run/libvirt/network/default.xml /etc/libvirt/qemu/networks/autostart/default.xml /etc/libvirt/qemu/networks/default.xml /etc/libvirt/storage/autostart/default.xml /etc/libvirt/storage/default.xml /usr/share/backgrounds/default.xml /usr/share/libvirt/networks/default.xml /usr/share/gutenprint/5.2/xml/escp2/inputslots/default.xml /usr/share/ibus-m17n/default.xml |
2-3-2. 文件一个一个修改,修改后马上重启,再用ifconfig 查看ip是否变回192.168.123.x.
2-3-3. 我找到 /etc/libvirt/qemu/networks/autostart/default.xml 这个文件修改完 – 重启 ,IP会变.估计就是它了
1 | vi /etc/libvirt/qemu/networks/autostart/default.xml |
修改之前的文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <!-- 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 default or other application using the libvirt API. --> <network> <name>default</name> <uuid>db5d628c-8208-4d28-a84e-b787816980e3</uuid> <forward mode='nat'/> <bridge name='virbr0' stp='on' delay='0'/> <mac address='52:54:00:4c:a1:4c'/> <ip address='192.168.122.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.122.2' end='192.168.122.254'/> </dhcp> </ip> </network> |
改成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <!-- 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 default or other application using the libvirt API. --> <network> <name>default</name> <uuid>db5d628c-8208-4d28-a84e-b787816980e3</uuid> <forward mode='nat'/> <bridge name='virbr0' stp='on' delay='0'/> <mac address='52:54:00:4c:a1:4c'/> <ip address='192.168.123.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.123.2' end='192.168.123.254'/> </dhcp> </ip> </network> |
1 | reboot //重启 |
重启后ip就变回192.168.123.xxx开头了.
2-4. ONBOOT可以改为Yes了.
1 | vi /etc/sysconfig/network-scripts/ifcfg-eth0 |
1 | ONBOOT=no //改回 ONBOOT=yes |
1 | reboot //重启服务器 |
2-5-1. 重启后查看ip
1 | ifconfig |
可以看到两张网卡都已经启动成功
2-5-2. 查看virtual network default NAT 发现也已经正常
1 | virsh net-list --all |
1 2 3 | Name State Autostart Persistent ---------------------------------------------------------- default active yes yes |
2-5-3. ping www.baidu.com 也已经正常
1 | ping www.baidu.com |
备注:
通过多次重装虚拟机.总算找到原因.
1. 开启了firewalld. 导致192.168.122.3 的IP消失.
2. 虚拟机找不到主服务器IP,导致nat用默认192.168.122.xxx, 变成开了NAT就eth0启动不了,开了eth0就NAT启动不了
通过多次重装虚拟机.总算找到原因.
1. 开启了firewalld. 导致192.168.122.3 的IP消失.
2. 虚拟机找不到主服务器IP,导致nat用默认192.168.122.xxx, 变成开了NAT就eth0启动不了,开了eth0就NAT启动不了
特别注意.
1. 安装虚拟机时不要开firewalld
1 2 | systemctl stop firewalld.service //关闭firewalld firewall-cmd --state //查看是否已成功关闭 |
2. 安装过程千万记得network这边要改成ON,否则遍地都是坑!!!又浪费半天时间!!!
1 2 | virsh net-start default 激活virtual network default NAT virsh net-list --all 查看virtual network default NAT |