From 7a2fe5e647942cc9e80065906f683c73647ef08c Mon Sep 17 00:00:00 2001 From: Rohan Garg Date: Fri, 7 Nov 2014 15:18:45 +0100 Subject: [PATCH] Make sure we also write to the /etc/hosts file --- src/modules/users/SetHostNameJob.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/modules/users/SetHostNameJob.cpp b/src/modules/users/SetHostNameJob.cpp index 5b04de1ac..a24b69c5c 100644 --- a/src/modules/users/SetHostNameJob.cpp +++ b/src/modules/users/SetHostNameJob.cpp @@ -64,5 +64,22 @@ Calamares::JobResult SetHostNameJob::exec() out << m_hostname << "\n"; hostfile.close(); + QFile hostsfile( destDir + "/etc/hosts" ); + if ( !hostfile.open( QFile::WriteOnly ) ) + { + cLog() << "Can't write to hosts file"; + return Calamares::JobResult::error( tr( "Cannot write hostname to target system" ) ); + } + + // We also need to write the appropriate entries for /etc/hosts + QTextStream out( &hostsfile ); + // ipv4 support + out << "127.0.0.1" << "\t" << "localhost" << "\n"; + out << "127.0.1.1" << "\t" << m_hostname << "\n"; + // ipv6 support + out << "::1" << "\t" << "localhost ip6-localhost ip6-loopback" << "\n"; + out << "ff02::1 ip6-allnodes" << "\n" << "ff02::2 ip6-allrouters" << "\n"; + hostsfile.close(); + return Calamares::JobResult::ok(); }