2

I was setting the hostname on my Linux machine with below steps:

  1. echo "ABCD" > /etc/hostname
  2. hostname -F /etc/hostname
  3. Exit from terminal or reboot system
  4. Now I can see the new hostname.

Now my question is: What I did here, is that enough for setting the hostname or do I additionally have to change other configuration files, if any?

1
  • Different distributions provide different ways. What distribution are you referring to? Linux is just the kernel...
    – Daniel B
    Commented Apr 25, 2014 at 11:35

2 Answers 2

2

You don't need to do anything, since you've already changed the hostname by editing /etc/hostname. If you're trying to do something other than change the hostname as the host knows it, please elaborate.

/etc/hosts just lists symbolic names for IPs, so that for example ping localhost does the same as ping 127.0.0.1 if you have a line starting with 127.0.0.1 and localhost somewhere else on the line (whitespace separated). You can of course add abcd to that line, but that has nothing to do with the hostname in /etc/hostname, other than that they coincidentally are the same string. You can't for example enter localhost abcd in the file and expect that to resolve abcd → localhost → 127.0.0.1.

PS: DNS names are not case sensitive, but are conventionally written in lowercase.

-2

As far as I know, you need to change both /etc/hostname and /etc/hosts.

5
  • Ok then what changes i need to do in /etc/hosts file can you please tell me. Commented Apr 25, 2014 at 9:07
  • There is a map from hostname to 127.0.1.1 Commented Apr 25, 2014 at 9:11
  • If you have a reference to the old host name in /etc/hosts and didn't change it, you wouldn't be able to resolve the new host name. Some server apps don't work if your host name does not resolve to an IP address
    – michel-slm
    Commented Apr 25, 2014 at 9:12
  • Ok thank you for explanation. My current hosts file display as "127.0.0.1 localhost.localdomain localhost". Now i need to add one new line "127.0.1.1 localhost.localdomain abcd". RIGHT? Commented Apr 25, 2014 at 9:15
  • 1
    You don't need to do this.
    – l0b0
    Commented Apr 25, 2014 at 11:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .