Skip to main content

Changing Hostnames in Linux

·328 words·2 mins
system-administration tech debian linux raspberry-pi raspbian sysadmin technology
James Pettigrove
Author
James Pettigrove
Cloud Engineer with a focus on Microsoft Azure

Recently I decided to give my two Raspberry Pi devices an overhaul + change in functionality. Swapped out my Raspberry Pi Zero from being the always on, ASIC mining, Pi-Hole wonder to a mobile lab for my ongoing Linux SysAdmin learning that I touched upon here by utilising the Zero’s unique ability to be powered and network over the USB (more on that in a later post). Consequently, that put my Raspberry Pi A+ back into service.

Rather than just simply swap out the SD Card from the Zero, I wanted to start from scratch. Always a nicety in the world of IT, plus, it makes for another opportunity to get my hands dirty and perform tasks you often only do once. Set and forget if you will.

Well, one of those tasks is changing the hostname of the device to something with a bit more flavour than just ‘raspberrypi’ as it is by default in Raspbian.

Scratching my head, I had to remember what exactly the steps are to modify the hostname. Now that they are forefront of my mind, below is what is required:

The below applies to Raspbian and thus other Debian or Debian derivative Operating Systems. Though it’s safe to assume the vast majority of Linux Operating Systems will accept the below steps, YMMV.

Either as root, or elevate via sudo; using your favourite text editor (in the below case, nano) open the hosts file located in /etc/

sudo nano /etc/hosts

Modify the entry that lists the current hostname together with the IP address of 127.0.1.1 to state the new hostname, followed by saving and closing.

Next, once again, as root, or elevate via sudo; using the text editor, open the hostname file located in /etc/

sudo nano /etc/hostname

Clear out the only entry in the file and enter the desired hostname, followed by a save and close.

Once complete, a quick reboot and you will have a newly named Linux host. Too easy.

Related

Docker Daemon failing to start on Raspberry Pi 1 & Zeros
·535 words·3 mins
system-administration tech containers core-dump debian docker linux raspberry-pi raspbian segmentation-fault sysadmin technology
Have you recently attempted to install the containerization platform known as Docker on to a first generation Raspberry Pi (including A+ and B+) or a Zero and found you couldn’t start up a container?
Let's explore the Linux Filesystem: /Proc - Part 1
·553 words·3 mins
system-administration tech debian linux raspberry-pi raspbian sysadmin technology
Despite the Linux operating system being available in various and unique flavours and spins, many of the foundations that make up the operation system have similarities between them all.
Keeping your Pi-Hole container fresh with Cron
·396 words·2 mins
system-administration tech containers cron docker linux pihole raspberry-pi raspbian sysadmin technology
In our previous entry, we unleashed the awesome that is Pi-Hole inside a Docker container to make all the devices in our network ad-free when browsing the internet.