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?
Best Answer
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.