VR: fix data-server if shared network has multiple ip ranges (#5530)

* VR: fix data-server if shared network has multiple ip ranges

This fixes #5518

* Update PR #5530: fix nameserver in vm with IP in additional IP ranges

without this change
```
root@r-757-VM:~# cat /etc/dnsmasq.d/cloud.conf
listen-address=127.0.0.1,10.10.12.31,10.10.13.19
dhcp-range=set:interface-eth0-0,10.10.12.31,static
dhcp-option=tag:interface-eth0-0,15,cs1cloud.internal
dhcp-option=tag:interface-eth0-0,6,10.10.12.31,10.0.32.1,8.8.8.8
dhcp-option=tag:interface-eth0-0,3,10.10.12.254
dhcp-option=tag:interface-eth0-0,1,255.255.255.0
dhcp-range=set:interface-eth0-1,10.10.13.19,static
dhcp-option=tag:interface-eth0-1,15,cs1cloud.internal
dhcp-option=tag:interface-eth0-1,6,10.10.12.31,10.0.32.1,8.8.8.8 <<< nameserver 10.10.12.31
dhcp-option=tag:interface-eth0-1,3,10.10.13.254
dhcp-option=tag:interface-eth0-1,1,255.255.255.0
```

with this change
```
root@r-757-VM:~# cat /etc/dnsmasq.d/cloud.conf
listen-address=127.0.0.1,10.10.12.31,10.10.13.19
dhcp-range=set:interface-eth0-0,10.10.12.31,static
dhcp-option=tag:interface-eth0-0,15,cs1cloud.internal
dhcp-option=tag:interface-eth0-0,6,10.10.12.31,10.0.32.1,8.8.8.8
dhcp-option=tag:interface-eth0-0,3,10.10.12.254
dhcp-option=tag:interface-eth0-0,1,255.255.255.0
dhcp-range=set:interface-eth0-1,10.10.13.19,static
dhcp-option=tag:interface-eth0-1,15,cs1cloud.internal
dhcp-option=tag:interface-eth0-1,6,10.10.13.19,10.0.32.1,8.8.8.8 <<< nameserver 10.10.13.19
dhcp-option=tag:interface-eth0-1,3,10.10.13.254
dhcp-option=tag:interface-eth0-1,1,255.255.255.0
```

* Update #5530: add 'localise-queries' to /etc/dnsmasq.conf
This commit is contained in:
Wei Zhou 2021-10-04 11:40:25 +02:00 committed by GitHub
parent 72a1c0e7f1
commit 9f5ac89c9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -636,3 +636,4 @@ log-facility=/var/log/dnsmasq.log
conf-dir=/etc/dnsmasq.d
dhcp-optsfile=/etc/dhcpopts.txt
localise-queries

View File

@ -108,6 +108,12 @@ class CsDhcp(CsDataBag):
if gn.get_dns() and device:
sline = "dhcp-option=tag:interface-%s-%s,6" % (device, idx)
dns_list = [x for x in gn.get_dns() if x]
if self.config.is_dhcp() and not self.config.use_extdns():
guest_ip = self.config.address().get_guest_ip()
if guest_ip and guest_ip in dns_list and ip not in dns_list:
## Replace the default guest IP in VR with the ip in additional IP ranges, if shared network has multiple IP ranges.
dns_list.remove(guest_ip)
dns_list.insert(0, ip)
line = "dhcp-option=tag:interface-%s-%s,6,%s" % (device, idx, ','.join(dns_list))
self.conf.search(sline, line)
if gateway != '0.0.0.0':
@ -129,8 +135,10 @@ class CsDhcp(CsDataBag):
else:
listen_address.append(ip)
# Add localized "data-server" records in /etc/hosts for VPC routers
if self.config.is_vpc():
if self.config.is_vpc() or self.config.is_router():
self.add_host(gateway, "%s data-server" % CsHelper.get_hostname())
elif self.config.is_dhcp():
self.add_host(ip, "%s data-server" % CsHelper.get_hostname())
idx += 1
# Listen Address
@ -166,8 +174,6 @@ class CsDhcp(CsDataBag):
self.add_host("::1", "localhost ip6-localhost ip6-loopback")
self.add_host("ff02::1", "ip6-allnodes")
self.add_host("ff02::2", "ip6-allrouters")
if self.config.is_router() or self.config.is_dhcp():
self.add_host(self.config.address().get_guest_ip(), "%s data-server" % CsHelper.get_hostname())
def write_hosts(self):
file = CsFile("/etc/hosts")