在 redhat 主机上,virbr0
已启动,并且 libvirt 的网络配置为nat
(192.168.122.2-254
并且最近添加了专门用于分配的规则192.168.122.2
)。但是却dhclient
得到了 ubuntu VM 10.0.2.15
。
这可能是虚拟机-得到-10-0-xx或者更改虚拟盒 dhcp 为问题 192-168-xx,但我不知道如何转换VBoxManage modifyvm "NameOfVM" --natnet1 "192.168/16"
为 qemu/virsh,我认为配置已经正确 NAT
brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.52540024cafa yes virbr0-nic
ip addr show virbr0|grep inet
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
virsh list --all
Id Name State
---------------------------------------------------
2 fw-core running
sudo virsh net-dumpxml default
<network>
<name>default</name>
<uuid>b270007c-ada2-4c16-9b34-3abecc1c4b94</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:24:ca:fa'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
<host mac='52:54:00:6d:e4:ae' name='fw-core' ip='192.168.122.2'/>
</dhcp>
</ip>
</network>
我可以使用从主机连接到客户机,virsh console fw-core
但不能ssh 10.0.2.15
VM 直接跳过桥接并从企业网络 (?) 获取 IP。从 而不是dhclient
获取 IP 。我无法使用主机为其分配的 IP 连接到 VM。10.0.2.2
192.168.122.1
sudo dhclient -v ens3
Listening on LPF/ens3/52:54:00:6d:e4:ae
Sending on LPF/ens3/52:54:00:6d:e4:ae
Sending on Socket/fallback
DHCPDISCOVER on ens3 to 255.255.255.255 port 67 interval 3 (xid=0xf27cb27a)
DHCPOFFER of 10.0.2.15 from 10.0.2.2
DHCPREQUEST for 10.0.2.15 on ens3 to 255.255.255.255 port 67 (xid=0x7ab27cf2)
DHCPACK of 10.0.2.15 from 10.0.2.2 (xid=0xf27cb27a)
bound to 10.0.2.15 -- renewal in 32873 seconds.
并尝试强制192.168.122.1
使用 dhcp 服务器地址失败
sudo dhclient -v ens3 -s 192.168.122.1
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/ens3/52:54:00:6d:e4:ae
Sending on LPF/ens3/52:54:00:6d:e4:ae
Sending on Socket/fallback
DHCPREQUEST for 10.0.2.15 on ens3 to 192.168.122.1 port 67 (xid=0x1557fbe4)
DHCPREQU
值得一提的是,客户虚拟机可以连接到外部世界和主机 ssh 服务器
curl -s google.com|sed 1q
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
sleep 1 | telnet 192.168.122.1 22
Trying 192.168.122.1...
Connected to 192.168.122.1.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4
Connection closed by foreign host
并且 ssh 正在虚拟机中运行
sleep 1|telnet localhost 22
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.4
Connection closed by foreign host.
我的另一个想法是主机上的防火墙问题。但我已将网桥添加为内部区域
sudo firewall-cmd --zone=internal --list-all
internal (active)
target: default
icmp-block-inversion: no
interfaces: virbr0
sources:
services: dhcp dhcpv6-client mdns samba-client ssh
ports: 67/tcp 67/udp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
编辑:主机上的所有接口
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether 0a:6c:8e:88:52:62 brd ff:ff:ff:ff:ff:ff
3: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 3c:ec:ef:d1:18:54 brd ff:ff:ff:ff:ff:ff
inet 10.48.86.33/24 brd 10.48.86.255 scope global noprefixroute eno1
valid_lft forever preferred_lft forever
inet6 fe80::310c:bed0:9e4f:f53d/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether 3c:ec:ef:d1:18:55 brd ff:ff:ff:ff:ff:ff
13: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:24:ca:fa 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
14: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:24:ca:fa brd ff:ff:ff:ff:ff:ff
brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.52540024cafa yes virbr0-nic
编辑 2:虚拟机创建如下
virt-install --name core --ram $((1024*4)) --file=fw-core.img --file=ubuntu-22.04.3-live-server-amd64.iso
答案1
问题评论中的调试功劳归功于 Tom Yan:Qemu 使用 slirp 用户模式网络,因为我以非特权用户身份创建并运行。将虚拟机从 迁移qemu:///session
到并更新客户网络配置后,客户机通过 dhcpcqemu:///server
进入。192.168.122.2
事后看来,这一点很明显。virsh net-list --all
是空的,但sudo virsh net-list --all
显示了default
nat 设置。
为了减少混乱,我添加了~/.config/libvirt/libvirt.conf
uri_default = "qemu:///system"
迁移看起来像
virsh -c qemu:///session dumpxml fw-core > fw-core.xml
virsh -c qemu:///session shutdown fw-core
virsh -c qemu:///session undefine fw-core
sudo virsh -c qemu:///system define fw-core.xml
并将网络更改为nat
(的相关部分fw-core.xml
):
<interface type='network'>
<mac address='52:54:00:6d:e4:ae'/>
<source network='default' bridge='virbr0'/>
<target dev='vnet0'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
以下是截图
git difftool --tool=vimdiff
突出显示从接口类型 = 用户到类型 = 网络的变化,以及virt-manager
显示相同的内容:“NIC”的“虚拟硬件详细信息”现在设置为“虚拟网络‘默认’”