unable to change hostname

Issues related to configuring your network
Nileshkumar
Posts: 10
Joined: 2014/04/13 07:09:46

unable to change hostname

Post by Nileshkumar » 2014/04/13 07:38:28

Hi friends,
I have trying to change hostname of my machine by changing the contents of /etc/sysconfig/network and /etc/hosts file. Currently my files are like this

/etc/hosts
127.0.0.1 NileshDB
#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

/etc/sysconfig/network
HOSTNAME=NileshDB
NETWORKING=yes
GATEWAY=8.8.8.8

even the hostname command gives the correct hostname as like this
~]$ hostname
NileshDB

But the problem is that the starting prompt of the terminal, as you can in the attached file the prompt says " ~]$ sh@NileshDB"
where as prior to modifying /etc/sysconfig/network file (when it dosn't had the hostname entry) the prompt was
"nilesh@localhost$"
Also, after changing the /etc/sysconfig/network file while starting the system, the service "postfix" is not getting starting up, and it shows fail, for this perticullar service.

One thing I would like to mention here that, I have Atheros Ethernet control on my mother board, which it seems that Linux is still not supporting nativelly, so when I installed the system the networking components were not installed, and after installing Atheros Ethernet controller from here viewtopic.php?t=7269, I manually created these files , /etc/sysconfig/network and /etc/sysconfig/network-scripts/ifcfg-eth0.
Attachments
Look at the prompt
Look at the prompt
hostname.png (60.09 KiB) Viewed 7009 times

User avatar
avij
Retired Moderator
Posts: 3046
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: unable to change hostname

Post by avij » 2014/04/13 07:54:42

Changing /etc/sysconfig/network to have HOSTNAME=NileshDB should be sufficient.

There will need to be a localhost entry in /etc/hosts for your system to function properly, so remove the # from 127.0.0.1 and reboot.

Your GATEWAY line in /etc/sysconfig/network is incorrect, you can't use Google's DNS as your default gateway.

Nileshkumar
Posts: 10
Joined: 2014/04/13 07:09:46

Re: unable to change hostname

Post by Nileshkumar » 2014/04/13 08:15:04

I know changing /etc/sysconfig/network should be enough, that's what I have done.
I even removed # from /etc/hosts file.
And deleted googls DNS from /etc/sysconfig/network

But the problem is same, also while booting the system, if I have hostname entry in /etc/sysconfig/network file postfix service fails to start, if I delete hostname entry from the file, postfix service starts normally.

Also I have to run apache service and this is the o/p I am getting while starting httpd service
~]$ sudo service httpd start
[sudo] password for nilesh:
Starting httpd: httpd: apr_sockaddr_info_get() failed for NileshDB\r
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]

here the service httpd has started but the hostname is set to 127.0.0.1 rather then NileshDB

Nileshkumar
Posts: 10
Joined: 2014/04/13 07:09:46

Re: unable to change hostname

Post by Nileshkumar » 2014/04/13 08:28:01

OK half of the problem is solved, this seems some kind of special character problem. Because as I said that I had manually created /etc/sysconfig/network file, and this file was created in windows, and we know that in windows, their is a special character for Return, where as in Linux this is not their, but for some reason this was not visible either in Vi or gedit (text editors I was using), so just to verify this I created a new file, and now the postfix service is also getting started and the prompt at terminal is also giving me correct prompt as
[nilesh@NileshDB ~]$

but still, second problem is not solved, that is while starting httpd service same message is coming
[nilesh@NileshDB ~]$ sudo service httpd start
[sudo] password for nilesh:
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
[ OK ]

service is starting but, hostname is not resolved.

User avatar
avij
Retired Moderator
Posts: 3046
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: unable to change hostname

Post by avij » 2014/04/13 08:43:48

Find "ServerName" in /etc/httpd/conf/httpd.conf, uncomment the line and set it to something you prefer, like NileshDB

Nileshkumar
Posts: 10
Joined: 2014/04/13 07:09:46

Re: unable to change hostname

Post by Nileshkumar » 2014/04/13 09:03:01

This is OK, I am by this way we set the hostname in httpd.conf, but then apache should detect hostname automatically. And I need to know why is that not happening.

User avatar
avij
Retired Moderator
Posts: 3046
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: unable to change hostname

Post by avij » 2014/04/13 09:16:09

Time to read the documentation: http://httpd.apache.org/docs/2.2/mod/co ... servername
If no ServerName is specified, then the server attempts to deduce the hostname by performing a reverse lookup on the IP address. [...] For optimal reliability and predictability, you should specify an explicit hostname and port using the ServerName directive.
If you run "host 127.0.0.1", the response will likely be "localhost", not NileshDB. This is how it's supposed to work. So, set the ServerName to your liking and you should be all set.

Nileshkumar
Posts: 10
Joined: 2014/04/13 07:09:46

Re: unable to change hostname

Post by Nileshkumar » 2014/04/13 09:25:40

One more thing, when I have NileshDB in /etc/hosts like this
[nilesh@NileshDB ~]$ cat /etc/hosts
127.0.0.1 NileshDB localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 NileshDB localhost localhost.localdomain localhost6 localhost6.localdomain6

then I get this message while starting httpd
[nilesh@NileshDB ~]$ sudo service httpd start
[sudo] password for nilesh:
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
[ OK ]

but if I remove my hostname and modify /etc/hosts like this
[nilesh@NileshDB ~]$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

then when starting httpd service I get this message
[nilesh@NileshDB ~]$ sudo service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for NileshDB
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]

Can you please tell, whould I have "NileshDB" in my /etc/hosts file or not.

User avatar
avij
Retired Moderator
Posts: 3046
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: unable to change hostname

Post by avij » 2014/04/13 09:52:46

You will get rid of the "Could not reliably determine the server's fully qualified domain name" messages if you set the ServerName manually, like I've said a few times already. Have you tried?

Nileshkumar
Posts: 10
Joined: 2014/04/13 07:09:46

Re: unable to change hostname

Post by Nileshkumar » 2014/04/13 10:28:26

Yes, I have tried that, and that problem is solved also, but please comment on /etc/hosts content also

Post Reply