Can we set easy-to-remember hostnames for EC2 instances?

后端 未结 11 978
一向
一向 2021-01-29 19:42

I\'m running a couple of standard Fedora instances on EC2. I feel the public hostnames of the instances assigned by Amazon are too weird and hard to remember. I\'d like to chang

相关标签:
11条回答
  • 2021-01-29 20:14

    Edit /etc/sysconfig/network as root.

    Replace

    HOSTNAME=localhost.localdomain
    

    with

    HOSTNAME=hostname.DOMAIN_NAME
    

    Then, either reboot or run /etc/init.d/network restart The server then should report its name as a FQDN.

    0 讨论(0)
  • 2021-01-29 20:16

    The /etc/rc.local solution worked for me for a basic hostname but does not give me a FQDN.

    0 讨论(0)
  • 2021-01-29 20:16

    In my Linux AMI (a snapshot of other instance).. none of the above formula worked. Then, I simply changed HOSTNAME field in file: /etc/init.d/modifyhostname and did a normal reboot.

    0 讨论(0)
  • 2021-01-29 20:18

    Sure, you can do that if you have your own domain (setup a CNAME to point to the Amazon hostname). Otherwise, you're pretty much stuck with the one they give you (or an Elastic IP, if you set one of those up).

    0 讨论(0)
  • 2021-01-29 20:20

    If you don't want to mess with your DNS provider, you could use aliases for your instances. I was really surprised that Amazon didn't provide a way to give an alias for an EC2 instance when they came out with the AWS Management Console, but in the meantime, you could use the free RightScale service if you want the alias feature - much easier than remembering those Amazon instance IDs.

    0 讨论(0)
  • 2021-01-29 20:26

    Another way is to simply edit ~/.bashrc and prepend PS1 with the nickname of the machine.

    Edit: perhaps more correctly, machine-wide, e.g. on the AWS Linux AMI (an example) (paste this into console or add to your arbitrary install .sh):

    cat << EOF | sudo tee /etc/profile.d/ps1.sh
    if [ "$PS1" ]; then
      PS1="[\u@myinst1:\l \t \! \W]\\$ "
    fi
    EOF
    
    0 讨论(0)
提交回复
热议问题