大网数据广告活动
服务器运维问答

Libvirt networking: Set default gateway for guest VMs via DHCP

· 52CE 我爱测

Is it possible to set a default gateway for the guest VMs via DHCP in libvirt? I have the following config <ip address='192.168.123.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.123.10' end='192.168.123.254'/> <host ma…

问题原文

原帖链接 · BluesSolo · CC BY-SA 4.0

Is it possible to set a default gateway for the guest VMs via DHCP in libvirt?

I have the following config

<ip address='192.168.123.1' netmask='255.255.255.0'>
  <dhcp>
    <range start='192.168.123.10' end='192.168.123.254'/>
    <host mac="00:16:3e:45:e2:ed" ip="192.168.123.10"/>
    <host mac="00:16:3e:53:a9:1a" ip="192.168.123.11"/>
    ...
  </dhcp>
</ip>

and now it would be nice to somehow add a **gateway** to the guest VMs like that:

<ip address='192.168.123.1' netmask='255.255.255.0'>
  <dhcp>
    <range start='192.168.123.10' end='192.168.123.254'/>
    <host mac="00:16:3e:45:e2:ed" ip="192.168.123.10" **gateway=192.168.123.1**/>
    <host mac="00:16:3e:53:a9:1a" ip="192.168.123.11" **gateway=192.168.123.1**/>
    ...
  </dhcp>
</ip>

How can I do that? I have only found this source, saying that it is not possible. However, this is from 2016. Has anything changed yet or is there another solution that I could use?

已采纳解答

原帖链接 · zymhan · CC BY-SA 4.0

By default, the libvirt DHCP "server" is the gateway for the libvirt guests. If you want to specify a different setup, then you cannot use libvirt's built-in NAT. You need to create a custom virtual network, probably using brctl, and run a DHCP service on that interface that hands out whatever custom DHCP lease you want.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。