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

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

    To change the system hostname to a public DNS name

    Follow this procedure if you already have a public DNS name registered

    1. Open the /etc/sysconfig/network configuration file in your favorite text editor and change the HOSTNAME entry to reflect the fully qualified domain name (such as webserver.mydomain.com).

      HOSTNAME=webserver.mydomain.com
      
    2. Reboot the instance to pick up the new hostname.

      [ec2-user ~]$ sudo reboot
      
    3. Log into your instance and verify that the hostname has been updated. Your prompt should show the new hostname (up to the first ".") and the hostname command should show the fully qualified domain name.

      [ec2-user@webserver ~]$ hostname
      webserver.mydomain.com
      

    To change the system hostname without a public DNS name

    1. Open the /etc/sysconfig/network configuration file in your favorite text editor and change the HOSTNAME entry to reflect the desired system hostname (such as webserver).

      HOSTNAME=webserver.localdomain
      
    2. Open the /etc/hosts file in your favorite text editor and add an entry beginning with 127.0.1.1 (on DHCP systems) or eth0's address (on static IP systems) to match the example below, substituting your own hostname. (127.0.0.1 should be left as the localhost line.)

      127.0.0.1   localhost localhost.localdomain
      127.0.1.1   webserver.example.com webserver
      
    3. Reboot the instance to pick up the new hostname.

      [ec2-user ~]$ sudo reboot
      
    4. Log into your instance and verify that the hostname has been updated. Your prompt should show the new hostname (up to the first ".") and the hostname command should show the fully qualified domain name.

      [ec2-user@webserver ~]$ hostname
      webserver.localdomain
      

    Note: You can also change the shell prompt without affecting the hostname. Refer to this AWS documentation.

提交回复
热议问题