To change the hostname of your Raspberry Pi running Debian, follow these steps:


1. Check the Current Hostname

Run this command to see the current hostname:

hostname

2. Update the Hostname

Edit the hostname and hosts files to change the hostname.

a. Edit /etc/hostname

sudo nano /etc/hostname

Replace the existing hostname with your desired hostname (e.g., mynewhostname). Save and exit (Ctrl + O, then Enter, and Ctrl + X).

b. Edit /etc/hosts

sudo nano /etc/hosts

Find the line that looks like this:

127.0.1.1    currenthostname

Replace currenthostname with your new hostname. It should now look like:

127.0.1.1    mynewhostname

Save and exit the file.


3. Apply the Changes

Reboot your Raspberry Pi to apply the changes:

sudo reboot

4. Verify the Change

After rebooting, check the new hostname:

hostname

You should see the new hostname displayed.