5

I know that changing my DNS records to point to my IP address is how I get my server accessible, so that a request for myDomain.com points to my IP address. With that said, why does a machine need to have a hostname? Why does it care what it's hostname is if the DNS system will route requests to it anyway?

Also, if I'm running a simple personal webserver, is it okay to just leave my hostname "local"? Should I change it to the FQDN?

EDIT I just found an excellent answer on another SO site here: https://unix.stackexchange.com/a/50529/32623

4 Answers 4

8

Best practices dictate that you set your hostname to something meaningful - usually the FQDN of the server (if the system has a role where it's associated with multiple FQDNs -- like a shared web hosting server -- you would typically set a hostname like webhosting001.provider.com for its local hostname, with a corresponding DNS entry).

This is done for a number of reasons, but there are two main ones:

  • As Nathan mentioned, some programs use the hostname for various purposes.
    Having an unresolvable hostname can cause unpredictable behavior.

  • When you are logged in to a machine its local hostname provides a convenient way to identify it.
    This is a good way to sanity check yourself before rebooting a host.
    It is also important in an environment with multiple machines -- 100 systems all called local will get very confusing, but 100 machines named web##, mail##, etc. (or some other naming scheme you select and stick to) makes them easy to tell apart.

6

Some applications (apache, I'm looking at you) uses the hostname to look up the server's FQDN. Also, a hostname makes identifying the box you're on easier.

2
  • At least Apache is graceful about this. There are some other programs (Hello there sendmail!) that completely lose their mind if the local hostname doesn't resolve...
    – voretaq7
    Oct 17, 2013 at 22:11
  • "Oh god, where am I?!?! segfault"
    – Nathan C
    Oct 17, 2013 at 23:27
4

Adding a hostname is the best practice for any server. If you leave your host name to local, and you try to contact it's hostname via another computer, you might ping yourself as a result.

3 Weeks ago i was called for server troubleshooting at a sister compagny and their main Active Directory server name was : WIN7740f-TMFYG. Let me tell you, it made my life way harder than it should have been

3
  • Thanks for the answer. I don't understand how a hostname like WIN7740f-TMFYG would make it harder for you, though. Seems pretty unique to me! Are you saying that it would have been easier if it had been a FQDN?
    – loneboat
    Oct 17, 2013 at 14:37
  • Im just saying that pinging a complicated name is harder than just pinging an actual name. For instance at my current office, our Active Directory server is called Alpha. So i can go in command line and type : ping alpha, wich will return me it's IP and whatnot. Just a question of optimisation :)
    – Dexirian
    Oct 17, 2013 at 14:39
  • 6
    The whole point of having hostnames, FQDN's and DNS entries are so that you dont have to remember complicated IP numbers. Having very complicated computer names kinda defeat that purpose
    – Dexirian
    Oct 17, 2013 at 14:41
2

Reasons include:

  • Actually identifying the server to YOURSELF (no different from naming your dog, rather than just calling it "the dog" -- the advantages are obvious)

  • Reverse lookup / authentication: mail servers for example, put their hostname into email, and the receiving server will do a reverse lookup on the name to check that it matches the IP making the claim. If you don't do these right, your email will be marked as spam. Which matters, even for "simple" web servers (that send mail).

  • Non-unique names are confusing, as others mentioned. local is a symbolic name, for the CURRENT machine. It is NOT an absolute name for a machine. It's like remembering your date of birth as "yesterday": that will only work for so long, and then you'll run into problems.

  • Abstraction. IPs are very fixed things, that don't cater well for change -- ESPECIALLY in the modern internet, where most users don't own the address range they're on. For example, if you set up scripts to contact your server via it's IP (112.134.23.14, say), and that IP belongs to your current hosting provider, "A Hosting"... then what happens when they become to expensive, and you move to "B hosting"? You need to change your scripts! That's silly. If you give your server a meaningful, unique name, then your scripts will always be able to use that name to find the right server, even if it moves.

You must log in to answer this question.

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