꿈꾸는 개발자

Linux hostname 변경 (Debian) 본문

기타

Linux hostname 변경 (Debian)

Anssony 2022. 1. 13. 13:14

환경

 - raspberry pi 3 B+

 - Ubuntu 18.04 LTS

 

영구적으로 hostname을 변경하기 위해선 1번과 2번 둘 다 실행하면 된다.

1. hostname 변경

 

먼저 관리자 권한이 필요하다. (/etc 수정 필요하기 때문에)

 

hostname 확인하는 명령어

$ hostnamectl

 

hostname 변경하는 명령어

$ sudo hostnamectl set-hostname [원하는 hostname]

 

결과를 확인하고 싶다면 다시 hostname을 확인하는 명령어를 입력하면 된다.

 

2. /etc/hosts 파일에서 hostname 변경

편집기를 이용해 /etc/hosts 파일에 들어간다.

(저는 nano를 사용했습니다.)

 

$ nano /etc/hosts
127.0.0.1	localhost
127.0.1.1	[원하는 hostname]

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

[원하는 hostname]이 변경 전에는 현재 hostname으로 되어 있을 것이다.

이를 자신이 바꾸고 싶은 hostname으로 변경 후 저장하고 나온다.

 

그 후 재부팅을 해주면 변경된 호스트 이름으로 나오게 될 겁니다.