How to change hostname on CentOS/Ubuntu

Sometimes you will need to change hostname in some Distro Linux like CentOS or Ubuntu and you are considering what is the easy way to do that. So i will help you to set hostname CentOS 7/6 and Ubuntu/Debian with below instructions. However, you know what is hostname value in Linux right? An alias name to indicate your system to easily manage.

1. Change hostname on CentOS and Ubuntu

+ CentOS/RHEL/Fedora 6

– For example, the value of hostname i will use is : host.cuongquach.com
– You just need to edit this file : ‘/etc/sysconfig/network

# vi /etc/sysconfig/network
HOSTNAME=host.cuongquach.com
# hostname "host.cuongquach.com"

+ CentOS/RHEL/Fedora 7

– Edit this file: ‘/etc/hostname

# vi /etc/hostname
HOSTNAME=host.cuongquach.com
# hostname "host.cuongquach.com"

+ Ubuntu/Debian

# echo "host.cuongquach.com" > /etc/hostname
# hostname -F /etc/hostname

2. Change info in file hosts then reboot

– Edit DNS hosts to match new hostname for translation IP-Hostname.

# vi /etc/hosts
127.0.0.1 host.cuongquach.com

– Reboot your system to apply new change.

# reboot

3. Checking

– Run command “hostname” and you will see your hostname.

# hostname
host.cuongquach.com

See, you can do it by yourself for changing or setting new hostname in Linux.

Previous articleHướng dẫn thay đổi hostname trên Linux
Next articleFix error EPEL Repo “Cannot retrieve metalink for repository” on CentOS
Bạn đang theo dõi website "https://cuongquach.com/" nơi lưu trữ những kiến thức tổng hợp và chia sẻ cá nhân về Quản Trị Hệ Thống Dịch Vụ & Mạng, được xây dựng lại dưới nền tảng kinh nghiệm của bản thân mình, Quách Chí Cường. Hy vọng bạn sẽ thích nơi này !