Command-line way of changing Computer Name in Ubuntu

Know Command-line and GUI way of changing Computer Name

In this session of Terminal Tuts, we will learn how to change your Ubuntu computer name and your server host name via Terminal. Command-line method is more useful for system administrators as usually they do it remotely. To edit the computer name, one has to edit “/etc/hostname” and “/etc/hosts” system files. In this article, we will see how to do edit them.

Rename Host Name in Ubuntu 17.10

METHOD 1: Command-line way useful for Remote login

STEP 1: Launch Terminal and enter the following command to install vim.

sudo apt-get install vim

Change Host name in Ubuntu
Change Host name in Ubuntu

STEP 2: Enter the following command to open the hosts file.

sudo vim /etc/hostname

STEP 3: You will see text editor within the Terminal. Press ‘Esc’ key and then ‘i’ to enter into INSERT mode where you can edit the file.

Change Host Name
Change Host Name

STEP 4: Go ahead and rename the computer by editing the first line which has the current computer name. For example I have renamed my PC name from fosslinux to fosslinuxtest.

Host Name Changed
Host Name Changed

STEP 5: After editing is complete you have save the file and exit out of it. To do press esc key to get to last line. Then type :wq and press enter. vim will save the sh file and exit out to terminal.

Save and Exit Command in vim
Save and Exit Command in vim

STEP 6: Type reboot in the terminal to restart the computer.

That’s it. Your computer name should be changed!

PC Name Changed!
PC Name Changed!

METHOD 2: GUI Way useful for a desktop computer

STEP 1: Type ‘Settings’ in the applications search box and click ‘Settings’.

Launch Settings
Launch Settings

STEP 2: In the ‘Settings’ app, click ‘Details’ located at the bottom left corner.

Click'Details'
Click ‘Details’

STEP 3:  Rename the PC and simply close the app.

Rename the PC
Rename the PC

STEP 4: Reboot the PC to see the new name in effect.

Kiran Kumar
Hi there! I'm Kiran Kumar, founder of FOSSLinux.com. I'm an avid Linux lover and enjoy hands-on with new promising distros. Currently, I'm using Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities especially during Winter ;). When I'm not writing for FOSSLinux, I'm seen biking and hiking on scenic trails. Hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more, and spread Linux love!. If you find a time, drop me an email or feedback from the 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

24,261FansLike
192FollowersFollow

LATEST ARTICLES

How to create Manjaro Linux Live USB drive in Windows PC

Create Manjaro Live USB flash drive
Manjaro Linux is based on the independently developed Arch operating system.  Arch Linux is already known to be an exceptionally fast, powerful, and lightweight distribution. But Arch Linux is typically targeted to geeks who have some Linux background and command-line usage.
manjaro screenshots
Want to take a quick virtual tour Manjaro XFCE edition instead of downloading GBs worth of ISO image and then making a Live USB of it? We will make it easy for you. Here are a series of screenshots of the important aspects of Manjaro Linux in XFCE edition. This is a light-weight edition, and aims to be fast and low on system resources. You will be amazed on how it is still visually appealing and user friendly.
screen capture apps linux
Do you want to make a video tutorial for YouTube or show-off your epic victory royale to your friends? Look no further — as we have compiled the 10 Best Screen Capturing Software for Linux. Whether you need to record your desktop screen or take a simple screenshot, FOSSLinux has got your back.
essential linux commands
Last week, we shared with you several "cool and fun" commands to get comfortable and confident with the Linux command-line. In our quest to further aid Linux users with mastery of the command line, or CLI, we present you with a variety of command-line utilities essential for all Linux users, regardless of proficiency level.