Skip to main content

Changing the Hostname on Linux and Removing VPN Server.

I want to change the hostname on my pivpn because I have moved that to a different system and want to use this for something else but don't need to reinstall linux:

use hostname to see current hostname or it is after your profile name right there in the terminal:
hostname

Pasted image 20250517145932.png

We can edit the hostname file with this command:
sudo nano /etc/hostname
Output:

Pasted image 20250517150053.png

I'm going to change the name to PI-DT-02 because I already have another pi I named PI-DT-01.
Pasted image 20250517150142.png

CTRL+S to save and CTRL+X to exit.
Now we need to edit the hosts file to update the name to match the new one with this command:
sudo nano /etc/hosts
I'm going to change the box highlighted in green to my new hostname:
Pasted image 20250517150355.png

Save and exit that file.
To apply those changes we will have to reboot.
sudo reboot
That disconnects the SSH session and I'll wait for it to come up.
If you want to know when it is reachable you can use the powershell command:
ping 192.168.1.16 -t
Be sure to replace this with the address of your pi.
It will ping that IP address until you cancel it with CTRL+C
Pasted image 20250517150842.png

We see the IP reply back and we know that it is back online.
Lets take it a step further and see if we can ping the new hostname.
ping PI-DT-02

Pasted image 20250517151000.png

We see that worked as well.
Lets ssh back in and see it confirmed:
Pasted image 20250517151234.png

Good to Go!
The rest is specific to the old setup of my pivpn. I was using wireguard so lets remove these packages:
sudo pivpn uninstall
Pasted image 20250517151906.png

I'm removing the full stack so I'm using y for the answer to all the questions.
I'll go ahead and reboot now.
Lets strip the pi down to a Clean Base:
sudo rm -rf /etc/pivpn
Removes leftovers. 
Final Touch:
If you want a clean slate without re-imaging:
sudo apt install deborphan
sudo deborphan | xargs sudo apt-get -y remove --purge
This removes orphaned libraries left behind by uninstalled apps.
Notice it didn't remove some of my home directory contents which I wish to keep:

Pasted image 20250517152555.png