I'm having several ec2 independent instances(staging and production). They do not talk to each other in any way.

Is is safe to modify /etc/hostname for better clarity of what instance you've logged in?


Short answer: Yes.

Long answer:

Whenever you need to resolve a hostname to an IP address, you use one of a group of options. This is configurable through /etc/nsswitch.conf, but the defaults that are probably relevant for you are to check files (/etc/hosts), then dns.

The only name in /etc/hosts is usually the local hostname with associated fully qualified domain name (FQDN). If one of your hosts contacts any other host, whether it be on the internet or locally within the EC2 cloud, it checks DNS to find the appropriate name-to-number mapping.

If you change the hostname on a machine, all you can do is change what name it thinks it has. Every other host will still get the same name-to-IP mapping. You can't change Amazon's DNS entries.

This is why if you want a valid name, you'll need to set up a CNAME in a DNS zone you control.

If you don't mind that you'll only see the change on the local host, go ahead and change that hostname. The only reason to make a machine's 'personal' hostname (what it thinks it's called) match its 'real' hostname (what everyone else thinks) is to reduce cases of sysadmin insanity.

The single-hostname thing breaks down somewhat when you get more complex setups, too: since a hostname corresponds to an IP, what do you do when you have load balancing or multihomed servers? In the end the whole concept of a local hostname is mainly for convenience and easy of administration.

P.S. You should probably change the hostname and FQDN through the distro's provided mechanism for doing so, as samarudge's linked question mentions. That'd be different for each distro, but happens to be /etc/sysconfig/network for Amazon AMI, Red Hat, or CentOS.

  • P.P.S. If you do need things to talk to each other, it may become an issue if the reverse-IP mapping (output of dig -x xx.xx.xx.xx) doesn't match up with the forward. If that's the case you can either spend way more time figuring out how host lookups work than you'd like or just leave the names as is – Michael Lowman Jun 23 '11 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.