security/B. Linux Server

[Linux] hostname 변경 (server name 초기 설정 변경)

xudegloss 2024. 3. 14. 00:36

※ ubuntu server 설치 시 초기 sever name 변경 목적

1) 현재 설정 확인

nojeans@xudeglossserver:~$ hostnamectl
 Static hostname: xudeglossserver # 아까 설정한 server name
       Icon name: computer-vm
         Chassis: vm
      Machine ID: 788c7e2bdc4b4f6da5df69dc56328135
         Boot ID: 208ba343819d444b95267e18f84c9208
  Virtualization: vmware
Operating System: Ubuntu 22.04.4 LTS
          Kernel: Linux 5.15.0-100-generic
    Architecture: x86-64
 Hardware Vendor: VMware, Inc.
  Hardware Model: VMware Virtual Platform

 

2) man 이용하여 hostnamectl 사용 방법 확인

nojeans@xudeglossserver:~$ man hostnamectl
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, including manpages, you can run the 'unminimize'
command. You will still need to ensure the 'man-db' package is installed.
nojeans@xudeglossserver:~$ sudo apt-get install man-db
nojeans@xudeglossserver:~$ sudo apt-get install unminimize

 

3) 명령어 man 이용

hostname 명령어 사용법을 확인하니, 직접 경로에 들어가서 변경하고 재부팅 진행

 

4) hostnamectl 명령어 이용하여 재부팅없이 변경

1) /etc/hostname에서 직접 변경 후 재부팅
2) hostnamectl set-hostname [호스트명] 명령어를 이용하여 재부팅 없이 변경
root@xudeglossserver:/home/nojeans# hostnamectl set-hostname [변경하고자 하는 서버 이름]
root@xudeglossserver:/home/nojeans# hostnamectl set-hostname xudegloss
root@xudegloss:/home/nojeans# hostnamectl
 Static hostname: xudegloss
       Icon name: computer-vm
         Chassis: vm
      Machine ID: 788c7e2bdc4b4f6da5df69dc56328135
         Boot ID: 208ba343819d444b95267e18f84c9208
  Virtualization: vmware
Operating System: Ubuntu 22.04.4 LTS
          Kernel: Linux 5.15.0-100-generic
    Architecture: x86-64
    
    
root@xudegloss:/home/nojeans# exit
exit
nojeans@xudegloss:~$ # [user name]@[server name]