Skip to contentSkip to conversation

ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry

PATCH In review Ian Campbell 2 participants 3 messages Sep 7, 2015 – Sep 9, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry

Debian creates an entry such as:
127.0.1.1 lace-bug.xs.citrite.net lace-bug

This causes local lookups of the FQDN to get 127.0.1.1, which is unhelpful if you are looking for an address to bind to and were hoping to get the public IP address, as libvirt does on the target host for migration.

Here we remove (actually, comment) any 127.0.1.1 line in /etc/hosts. This means that lookups of a hosts own name (fqdn or just dn) now rely on DNS, which may not be ideal. However for a host which uses DHCP I'm not aware of a way to keep /etc/hosts up to date with the actual IP address the machine has. In our infra the test host IP addresses are all static, but I don't think we want to rely on at any more that we already do.

---
 ts-xen-install | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
ts-xen-install +19 -0
index e039173..7c80a13 100755
@@ -229,6 +229,24 @@ END
     target_cmd_root($ho, $cmd);
 }
 
+sub hosts () {
+    # Debian installer generates a line like:
+    #
+    # 127.0.1.1             lace-bug.xs.citrite.net         lace-bug
+    #
+    # Where xs.citrite.net is $c{TestHostDomain} and lace-bug is the
+    # hostname, this causes lookups of the hosts FQDN to result in
+    # 127.0.1.1 which is not useful if the reason for the lookup was
+    # to be able to bind to the externally accessible IP address.
+    target_editfile_root($ho, "/etc/hosts", "etc-hosts", sub {
+        my $hn = $ho->{Name};
+        while (<EI>) {
+	    s|^127.0.1.1|#$&|;
+	    print EO;
+        }
+    });
+}
+
 sub nodhcp () {
     target_editfile_root($ho, "/etc/network/interfaces",
                          "etc-network-interfaces", sub {
@@ -350,4 +368,5 @@ if ($checkmode) {
     setupboot();
     setupinitd();
     nodhcp();
+    hosts();
 }
Signature · 1 line
2.5.1
Acked-by on v1 1/1
#1 lore raw

Ian Campbell writes ("[PATCH OSSTEST] ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry"):

ts-xen-install END · line 244

Quoted 1 line
ts-xen-install +1 -0
+	    s|^127.0.1.1|#$&|;

I think you mean

    s|^\Q127.0.1.1\E\b|#$&|;

or

    s|^127\.0\.1\.1\b|#$&|;

(I have tested both of these ad-hoc.)

Also

Quoted 1 line

+ my $hn = $ho->{Name};

This seems unused ?

With those two this corrected.

Ian.

author Acked-by Ian Jackson
#2 lore raw
Quoted 6 lines · Ian Jackson

Ian Campbell writes ("[PATCH OSSTEST] ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry"):

Review

Quoted 1 line
(quoted diff) +1 -0
+	    s|^127.0.1.1|#$&|;

I think you mean

Quoted 7 lines
    s|^\Q127.0.1.1\E\b|#$&|;

or

    s|^127\.0\.1\.1\b|#$&|;

(I have tested both of these ad-hoc.)

Yes, I went with the former.

Quoted 5 lines

Also

Quoted 1 line

+ my $hn = $ho->{Name};

This seems unused ?

Right, it was a remnant of a previous attempt.

Quoted 3 lines

With those two this corrected.

Thanks, I've added the following to pretest.

Ian.

commit e1adb8b552dda5c653958083c9c7457f0398ad09

Author: Ian Campbell <[email protected]>
Date:   Mon Sep 7 13:58:29 2015 +0100

ts-xen-install: Rewrite /etc/hosts to comment out 127.0.1.1 entry

Debian creates an entry such as:
127.0.1.1 lace-bug.xs.citrite.net lace-bug

This causes local lookups of the FQDN to get 127.0.1.1, which is unhelpful if you are looking for an address to bind to and were hoping to get the public IP address, as libvirt does on the target host for migration.

Here we remove (actually, comment) any 127.0.1.1 line in /etc/hosts. This means that lookups of a hosts own name (fqdn or just dn) now rely on DNS, which may not be ideal. However for a host which uses DHCP I'm not aware of a way to keep /etc/hosts up to date with the actual IP address the machine has. In our infra the test host IP addresses are all static, but I don't think we want to rely on at any more that we already do.

ts-xen-install +18 -0
index 070e74d..b511e2b 100755
@@ -230,6 +230,23 @@ END
     target_cmd_root($ho, $cmd);
 }
 
+sub hosts () {
+    # Debian installer generates a line like:
+    #
+    # 127.0.1.1             lace-bug.xs.citrite.net         lace-bug
+    #
+    # Where xs.citrite.net is $c{TestHostDomain} and lace-bug is the
+    # hostname, this causes lookups of the hosts FQDN to result in
+    # 127.0.1.1 which is not useful if the reason for the lookup was
+    # to be able to bind to the externally accessible IP address.
+    target_editfile_root($ho, "/etc/hosts", "etc-hosts", sub {
+        while (<EI>) {
+           s|^\Q127.0.1.1\E\b|#$&|;
+           print EO;
+        }
+    });
+}
+
 sub nodhcp () {
     target_editfile_root($ho, "/etc/network/interfaces",
                          "etc-network-interfaces", sub {
@@ -351,4 +368,5 @@ if ($checkmode) {
     setupboot();
     setupinitd();
     nodhcp();
+    hosts();
 }