[PATCH] Update /etc/hosts with hostname for loopback IP address (#506384)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Note: Compared to writing out of our own /etc/hosts which was removed in
bug 491808, we do not write line for localhosthost IP address.
---
 network.py |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/network.py b/network.py
index 5c08e18..1c06fb6 100644
--- a/network.py
+++ b/network.py
@@ -670,6 +670,29 @@ class Network:
             if domainname:
                 self.domains = [domainname]
 
+        # /etc/hosts
+        # update lines for 127.0.0.1 and ::1 with hostname if the file exists
+        if instPath and os.path.isfile(instPath + "/etc/hosts"):
+            of = open(instPath + "/etc/hosts", "r")
+            updatedlines = []
+            update = False
+            for line in of:
+                line = line.strip()
+                if line.startswith('127.0.0.1') or line.startswith('::1'):
+                    if self.hostname not in line.split():
+                        line += " %s" % self.hostname
+                        update = True
+                updatedlines.append(line)
+            of.close()
+
+            if update:
+                nf = open(instPath + "/etc/hosts", "w")
+                upd_comment = "# hostname %s added to /etc/hosts by anaconda\n" % self.hostname
+                nf.write(upd_comment + '\n'.join(updatedlines) + '\n')
+                nf.close()
+                log.info("/etc/hosts updated with hostname %s" % self.hostname) 
+
+
         # /etc/resolv.conf
         if (not instPath) or (not os.path.isfile(instPath + '/etc/resolv.conf')) or flags.livecdInstall:
             if os.path.isfile('/etc/resolv.conf') and instPath != '':
-- 
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux