Skip to main content

hostnamectl로 hostname 변경

hostnamectl 명령어로 hostname 변경하기 명령어) ``hostnamectl set-hostname 호스트명


```bash
예시)
[root@amazonlinux ~]# hostname
amazonlinux.onprem
[root@amazonlinux ~]# hostnamectl set-hostname MinhangK8S-01
[root@amazonlinux ~]# hostname
minhangk8s-01
[root@amazonlinux ~]#
  • 프롬프트 상의 호스트명 amazonlinux는 바로 바뀌지 않았는데, 프롬프트명은 터미널 연결되는 순간에 환경변수를 읽어다 지정되기 때문이다.
  • exit했다가 ssh를 재접속하거나, 쉘 환경변수들을 다시 읽어들이면 되는데, 깔끔하게 ssh 재접하는 것이 편할 것이다..
예시)
[root@amazonlinux ~]# exit
logout
Connection to 192.168.100.52 closed.
[root@Minhang9 ~]# ssh 192.168.100.52
root@192.168.100.52's password: 
Last login: Tue Oct 24 06:16:15 2023 from 192.168.100.100
   ,     #_
   ~\_  ####_        Amazon Linux 2
  ~~  \_#####\
  ~~     \###|       AL2 End of Life is 2025-06-30.
  ~~       \#/ ___
   ~~       V~' '->
    ~~~         /    A newer version of Amazon Linux is available!
      ~~._.   _/
         _/ _/       Amazon Linux 2023, GA and supported until 2028-03-15.
       _/m/'           https://aws.amazon.com/linux/amazon-linux-2023/

3 package(s) needed for security, out of 6 available
Run "sudo yum update" to apply all updates.
[root@minhangk8s-01 ~]#       => 프롬프트명의 hostname도 바뀌어 있음