Raspberry Pi – How to change hostname & automate DHCP Lease renewal

Shell instructions as follows:

Update DHCP lease

Create a script sh file and put the following contents into it. Run the script when you want to renew the DHCP lease.

#!/bin/bash
sudo dhclient -v eth0
sudo nohup dhclient &

To check dhcp config:
sudo dhcpcd -T eth0

Update the Hostname

open /etc/hosts file
change the name on the line with 127.0.1.1 to your preferred name and save the file.
open /etc/hostname
change the name to your preffered name and save the file.
reboot.

Leave a comment