FredericPerrin
Enthusiast
Enthusiast

Set-VMGuestNetworkInterface: bug(s) when setting DNS servers

Hello,

The Set-VMGuestNetworkInterface cmdlet seems to be only working on very specific instances. More specifically:

  • If their is only one or zero DNS server defined in the guest /etc/resolv.conf, then additionnal servers given as arguments to the cmdlet are defined with nameserver=a.b.c.d (with an equal sign, I don't know where it comes from) ;

  • If we provide only one DNS server, we find at the end of /etc/resolv.conf a spurious nameserver= line ;

  • If we provide more then two servers, the last ones are silently dropped (in its default configuration, glibc allows up to three name servers) ;

In short, it seems to work as expected only when two DNS servers are provided, and when the guest resolv.conf already contains exactly two DNS servers.

Fortunately, since most of the work is done by a Perl script, this is easily corrected by patching this script. The following trivial patch does this, by dropping the = sign, and adding "nameserver a.b.c.d" lines only when there is something to add. I haven't searched how to correct point 3 above, which in fact is rather minor (except that it seems to highlight the fact that the SetVMGuestNetworkInterface_XXX scripts have no way to report errors). Feel free to do whatever you want with this patch (of course, I'd like it to be included in the next release of PowerCLI Smiley Happy ).

--- SetVmGuestNetworkInterface_LinuxGuest~      2009-11-30 17:15:56.359182700 +0100
+++ SetVmGuestNetworkInterface_LinuxGuest       2009-12-11 14:03:12.494838300 +0100
@@ -55,29 +55,28 @@
       foreach $line (<LOGFILE>) {

          if($line =~ m/nameserver [http://\.\d|http://\.\d]*/
-            && ($dns1set==0 || $dns2set==0)){
-
-            if($dns1set==0){
+            && ($dns1set==0 || $dns2set==0)) {
+            if ($dns1set==0) {
                $dnsToSet=$dns1;
                $dns1set=1;
-            }else{
+            } else {
                $dnsToSet=$dns2;
                $dns2set=1;
             }
-
-
-            $line =~ s/nameserver [http://\.\d|http://\.\d]*/nameserver $dnsToSet/;
+            if ($dnsToSet) {
+               $line =~ s/nameserver [http://\.\d|http://\.\d]*/nameserver $dnsToSet/;
+            }
          }

          push(@dns_output, $line);
       }

-      if($dns1set == 0){
-         push(@dns_output, "nameserver=$dns1\n");
+      if (($dns1set == 0) && ($dns1)) {
+         push(@dns_output, "nameserver $dns1\n");
       }

-      if($dns2set == 0){
-         push(@dns_output, "nameserver=$dns2\n");
+      if (($dns2set == 0) && ($dns2)) {
+         push(@dns_output, "nameserver $dns2\n");
       }

       close(LOGFILE); 

0 Kudos
1 Reply
FredericPerrin
Enthusiast
Enthusiast

I was kind of hoping to start a discussion with other people who might have encountered the same issue... Am I the only one trying to configure Linux guests?

0 Kudos