DHCP - namerservers not defined to expected ones when initializing a VM.
dcdh opened this issue · 1 comments
I am struggling when setting up nameservers at server boot time.
Setup
My setup is a virtual machine (CentOS8 - qemu version) managed by libvirt.
Cloud init version in CentOS8 vm
[root@services log]# cloud-init -v
/bin/cloud-init 18.5
Network setup:
<network xmlns:dnsmasq='http://libvirt.org/schemas/network/dnsmasq/1.0'>
<name>okd_network</name>
<bridge name="virbr1" />
<forward mode="nat">
<nat>
<port start='0' end='65535'/>
</nat>
</forward>
<ip address='10.0.5.1' netmask='255.255.255.0'>
<dhcp>
<host mac="52:54:10:00:05:57" name="services.sandbox.okd.local" ip="10.0.5.57"/>
<host mac="52:54:10:00:05:58" name="bootstrap.sandbox.okd.local" ip="10.0.5.58"/>
<host mac="52:54:10:00:05:59" name="control-plane-0.sandbox.okd.local" ip="10.0.5.59"/>
</dhcp>
</ip>
<dnsmasq:options>
<dnsmasq:option value="dhcp-option=option:dns-server,10.0.5.57,8.8.8.8"/>
<dnsmasq:option value="log-dhcp"/>
</dnsmasq:options>
</network>
By running this command under my host dhcping -s 10.0.5.1 -c 10.0.5.57 -h 52:54:10:00:05:57
I obtain this in my log journalctl -f -u libvirtd
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 available DHCP subnet: 10.0.5.1/255.255.255.0
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 DHCPREQUEST(virbr1) 10.0.5.57 52:54:10:00:05:57
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 tags: known, virbr1
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: Ignoring domain sandbox.okd.local for DHCP host name services
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 DHCPACK(virbr1) 10.0.5.57 52:54:10:00:05:57 services
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 next server: 10.0.5.1
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 sent size: 1 option: 53 message-type 5
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 sent size: 4 option: 54 server-identifier 10.0.5.1
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 sent size: 4 option: 51 lease-time 1h
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 sent size: 4 option: 58 T1 30m
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 sent size: 4 option: 59 T2 52m30s
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 sent size: 4 option: 1 netmask 255.255.255.0
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 sent size: 4 option: 28 broadcast 10.0.5.255
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 sent size: 4 option: 3 router 10.0.5.1
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 sent size: 8 option: 12 hostname services
déc. 25 21:46:52 linux-4.home dnsmasq-dhcp[746134]: 3159352927 sent size: 8 option: 6 dns-server 10.0.5.57, 8.8.8.8
=> the dns-server returned by the netmasq dhcp is well defined to 10.0.5.57
and 8.8.8.8
.
After the VM has booted I've got this log cloud-init.log
2020-12-25 15:12:41,143 - stages.py[DEBUG]: applying net config names for {'version': 2, 'ethernets': {'eth0': {'match': {'mac_address': '52:54:10:00:05:57'}, 'addresses': ['10.0.5.57'], 'gateway4': '10.0.5.1', 'nameservers': {'addresses': ['127.0.0.1', '8.8.8.8']}}}}
IP and gateway addresses are well defined, however I expect to have 10.0.5.57
and 8.8.8.8
for nameservers.
Checking the network /etc/sysconfig/network-scripts/ifcfg-eth0
I've got this:
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
DNS1=127.0.0.1
DNS2=8.8.8.8
GATEWAY=10.0.5.1
IPADDR=10.0.5.57
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
DNS1 and DNS2 do not match my expected value from dhcp setup.
If I check the /etc/resolv.conf
content I have got :
[root@services log]# cat /etc/resolv.conf
# Generated by NetworkManager
search sandbox.okd.local
nameserver 127.0.0.1
nameserver 8.8.8.8
Which correspond to the DNS1 and DNS2 values unwanted values.
If I ran dhclient
my resolv.conf is defined with expected nameservers
[root@services log]# cat /etc/resolv.conf
; generated by /usr/sbin/dhclient-script
nameserver 10.0.5.57
nameserver 8.8.8.8
So the dhcp is well defined.
What can I do to ensure that DNS1 and DNS2 will correspond to the nameservers defined in DHCP libvirt network setup ?
I have keep using an old configuration while launching my instance. Tried again and it works. Sorry for filling that issue (which is not one).