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

后端 未结 11 1103
一向
一向 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:40

    From this site:

    Change the hostname on a running system

    On any Linux system you can change its hostname with the command hostname (surprised?)… Here are some quick usages of the command line hostname:

    $> hostname
    

    without any parameter it will output the current hostname of the system.

    $> hostname --fqd
    

    it will output the fully qualified domain name (or FQDN) of the system.

    $> hostname NEW_NAME
    

    will set the hostname of the system to NEW_NAME.

    You can also edit /etc/hostname (at least on Ubuntu).

    To make sure it stays after a reboot in AWS, either add the command in /etc/rc.local so it runs when the machine starts.

    There's also a way to set the hostname dynamically via USER_DATA :

    USER_DATA=`/usr/bin/curl -s http://169.254.169.254/latest/user-data`
    HOSTNAME=`echo $USER_DATA`
    IPV4=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
    hostname $HOSTNAME
    echo $HOSTNAME > /etc/hostname
    

提交回复
热议问题