1

I know that to update the hostname of an AWS EC2 instance, I have to update /etc/sysconfig/network and then do a reboot.

But I need to do it without the reboot, is there a way to do this? I know that in some Linux distributions, you just need to source certain files to do this, but I cannot find what needs to be sourced in case of Amazon Linux.

Also, the updated hostname should be persistent, as in it should stay after restarts.

Thanks.

Bhushan
  • 151
  • 9

2 Answers2

3

You can also edit /etc/hostname to have the desired hostname, and then run

hostname -F /etc/hostname 

to apply the hostname from that file to the system.

See hostname --help for more options.

zymhan
  • 1,371
  • 1
  • 17
  • 30
  • 1
    There's no `/etc/hostname` file in Amazon Linux AMI. You need to create it manually. But still, your command ran successfully. Upvoted as well – Hussain7 Jun 13 '18 at 08:25
0

you can run hostname foo.bar.com then relogin and it'll be set to foo.bar.com

Mike
  • 22,310
  • 7
  • 56
  • 79