2

Fedora 30 Workstation Host, Fedora 30 Server (netinstall) Guests. I am not an expert in all this super-crazy Linux networking stuff and reading a ton of materials there and there. So I have libvirt virtual network interface:

<network>
  <name>ocp-cluster</name>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr-ocpc' stp='on' delay='0'/>
  <mac address='52:54:00:2c:01:00'/>
  <domain name='ocp.domain.local' localOnly='no'/>
  <dns>
    <forwarder addr='192.168.130.10'/>
  </dns>
  <ip address='192.168.131.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.131.50' end='192.168.131.254'/>
      <host mac='52:54:00:2c:01:10' name='lb-1.ocp.domain.local' ip='192.168.131.10'/>
      <host mac='52:54:00:2c:01:11' name='bootstrap.ocp.domain.local' ip='192.168.131.11'/>
      <host mac='52:54:00:2c:01:12' name='master-1.ocp.domain.local' ip='192.168.131.12'/>
      <host mac='52:54:00:2c:01:13' name='worker-1.ocp.domain.local' ip='192.168.131.13'/>
    </dhcp>
  </ip>
</network>

but when i create new VMs and assign correct MAC address to network interface (manually or in kickstart --mac 52:54:00:2c:01:10 \), hostname assigned to that MAC address is no set for VM. But if I understood right from libvirt documentation - it should be assigned. Is it related to <dns><forwarder ardr...>? In my case 192.168.130.10 is a address of DNSmasq VM which uses separate NAT bridge. Sure, I can assign hostname in kickstart file network --hostname=lb-1.ocp.domain.local, but i want to understand, how this <host name...> thing works. IP address for VM is assigned correctly.

Dzintars
  • 181
  • 1
  • 1
  • 7
  • What Linux distribution is your guest running? Did you install anything on it that might set the hostname? – Michael Hampton Jul 21 '19 at 17:39
  • Hi. I added distros. Sorry. My fault. I did not install anything on those guests. They are just blank OSes. But i imagine, that hostname should be picked automatically (mby im wrong in my assumptions). I am using regular netinstall versions. In cloud versions there is this thing called `preserve_hostname: true` but not sure is it somehow related there. – Dzintars Jul 21 '19 at 19:37
  • I found similar Q. - https://serverfault.com/questions/778218/libvirt-set-hostname-using-dhcp-in-virtual-network And by reading https://libvirt.org/formatnetwork.html#elementsAddress about ` -> ` element and especially ipv6 section it turns out that name attribute is used to match the name of launched VM because "since a MAC address has no defined meaning in IPv6". So... it could mean that in ipv4 name attribute is more like optional or probably could be used to assign IP to VM instead of mac. Basically there is no relation between name attribute and VMs hostname. – Dzintars Jul 22 '19 at 22:44

1 Answers1

3

The name attribute on the host members is not what you want. Confusingly, the right way to do this is to use the DNS section instead of the IP section. Adding the name attribute makes the match too restrictive (though I haven't dug into why exactly this happens), which is why it didn't apply to your machines. Try something like this instead:

<network>
  ...
  <dns>
    <host ip='192.168.131.10'>
      <hostname>lb-1.ocp.domain.local</hostname>
    </host>
    <host ip='192.168.131.11'>
      <hostname>bootstrap.ocp.domain.local</hostname>
    </host>
    <host ip='192.168.131.12'>
      <hostname>master-1.ocp.domain.local</hostname>
    </host>
    <host ip='192.168.131.13'>
      <hostname>worker-1.ocp.domain.local</hostname>
    </host>
  </dns>
  <ip address='192.168.131.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.131.50' end='192.168.131.254'/>
      <host mac='52:54:00:2c:01:10' ip='192.168.131.10'/>
      <host mac='52:54:00:2c:01:11' ip='192.168.131.11'/>
      <host mac='52:54:00:2c:01:12' ip='192.168.131.12'/>
      <host mac='52:54:00:2c:01:13' ip='192.168.131.13'/>
    </dhcp>
  </ip>
</network>

And since I can see that you are trying to install OpenShift, I'll also throw in that you don't need to do this setup manually. The installer supports libvirt - you just have to compile it from source with the right flag. This is covered in the docs (that link is to a specific commit in the history - future readers will want to look at the latest revision of those docs).

Alex
  • 31
  • 2