summaryrefslogtreecommitdiffstats
path: root/network.py
diff options
context:
space:
mode:
authorRadek Vykydal <rvykydal@redhat.com>2009-07-02 15:20:11 +0200
committerRadek Vykydal <rvykydal@redhat.com>2009-07-07 16:10:15 +0200
commit1aa67d5a2cdacd45f92ba15aa9392ba7191a49c7 (patch)
tree18571894d47d4e1ba26f3e52102042bda5a8b7df /network.py
parent9caaca40bcaffb502dc58659e828f97d78a2d0f8 (diff)
downloadanaconda-1aa67d5a2cdacd45f92ba15aa9392ba7191a49c7.tar.gz
anaconda-1aa67d5a2cdacd45f92ba15aa9392ba7191a49c7.tar.xz
anaconda-1aa67d5a2cdacd45f92ba15aa9392ba7191a49c7.zip
Update /etc/hosts with hostname for loopback IP address (#506384)
Note: Compared to writing out of our own /etc/hosts which was removed in bug 491808, we do not write line for host's IP address.
Diffstat (limited to 'network.py')
-rw-r--r--network.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/network.py b/network.py
index 5c08e182b..1c06fb6b8 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 != '':