Set fully qualified domain name on EC2 instance

9,090

hostname -f will return the first name after 127.0.0.1

So simply switching localhost and your fqdn will give you a correct return address while the localhost alias will still work.

Share:
9,090

Related videos on Youtube

Richard Knop
Author by

Richard Knop

Updated on September 18, 2022

Comments

  • Richard Knop
    Richard Knop about 1 year

    I am trying to set a fully qualified domain name on EC2 instance. I have set CNAME entry in Route53, so when I go to sync1.staging1.mycompany.net, it resolves to the correct instance.

    What I have done so far without success, I have edited /etc/hostname (so it stays the same after restarting):

    sync1.staging1.mycompany.net
    

    I have then used hostname command to set the hostname:

    sudo hostname sync1.staging1.mycompany.net
    

    I have then edited /etc/hosts and made sure this line is there:

    127.0.0.1 localhost sync1.staging1.mycompany.net sync1
    

    The problem is, when I run hostname -f, I get:

    localhost
    

    When I run hostname -s, I get correctly:

    sync1
    

    When I run just hostname without parameters, I get:

    sync1.staging1.mycompany.net sync1
    

    The problem is I am trying to run a Puppet manifests which needs the fully qualified domain name to be set, otherwise I am getting an error when I run puppet apply manifests/site.pp:

    Error: Could not find default node or by name with 'sync1.eu-west-1.compute.internal, sync1.eu-west-1.compute, sync1.eu-west-1, sync1' on node sync1.eu-west-1.compute.internal
    Error: Could not find default node or by name with 'sync1.eu-west-1.compute.internal, sync1.eu-west-1.compute, sync1.eu-west-1, sync1' on node sync1.eu-west-1.compute.internal
    

    This is EC2 instance running on Ubuntu 12.04 LTS.

    Any ideas? Do I need to set and elastic IP address for the instance in order for it to have the fully qualified domain name?

  • odigity
    odigity over 9 years
    I just tried adding 'foo' as the first token after 127.0.0.1 in /etc/hosts then ran hostname -f, it did not affect anything.
  • odigity
    odigity over 9 years
    Same with modifying /etc/hostname. Keep in mind I did not reboot or force a hostname reload with hostname -F, so I wouldn't expect a change in /etc/hostname to affect anything.
  • Requist
    Requist over 9 years
    I think Ubuntu changed the default internal address, it uses here now 127.0.1.1 The trick will be the same but now you add foo as first name in the 127.0.1.1 line, no restart of anything required.