# 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:  


```bash
hostname
```

[![Pasted image 20250517145932.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/3EQfaJHeviMkFzFD-pasted-image-20250517145932.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/3EQfaJHeviMkFzFD-pasted-image-20250517145932.png)

##### We can edit the hostname file with this command:  


```bash
sudo nano /etc/hostname
```

##### Output:

[![Pasted image 20250517150053.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/AijIO8kW6PvCwYoi-pasted-image-20250517150053.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/AijIO8kW6PvCwYoi-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](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/v7nWNAYfR5QBFCsa-pasted-image-20250517150142.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/v7nWNAYfR5QBFCsa-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:  


```bash
sudo nano /etc/hosts
```

##### I'm going to change the box highlighted in green to my new hostname:

##### [![Pasted image 20250517150355.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/JhcAoWM0tFs36kGW-pasted-image-20250517150355.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/JhcAoWM0tFs36kGW-pasted-image-20250517150355.png)  
  
Save and exit that file.

##### To apply those changes we will have to reboot.  


```bash
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:  


```powershell
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](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/PDalQ9Xw4LhCZdwu-pasted-image-20250517150842.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/PDalQ9Xw4LhCZdwu-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.

```powershell
ping PI-DT-02
```

[![Pasted image 20250517151000.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/SM6oYZPc2Nj9rsLZ-pasted-image-20250517151000.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/SM6oYZPc2Nj9rsLZ-pasted-image-20250517151000.png)

##### We see that worked as well.

##### Lets ssh back in and see it confirmed:

##### [![Pasted image 20250517151234.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/Ax5Uindef6p1qKcR-pasted-image-20250517151234.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/Ax5Uindef6p1qKcR-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:

```bash
sudo pivpn uninstall
```

##### [![Pasted image 20250517151906.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/a8sNXC1EbBmZTgPE-pasted-image-20250517151906.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/a8sNXC1EbBmZTgPE-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:  


```bash
sudo rm -rf /etc/pivpn
```

##### Removes leftovers. 

##### Final Touch:  
If you want a clean slate without re-imaging:  


```bash
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](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/zsKr6ttugfiOSqLN-pasted-image-20250517152555.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/zsKr6ttugfiOSqLN-pasted-image-20250517152555.png)