dawon
Posts: 1
Joined: Mon Mar 30, 2020 3:24 am

How to change the hostname of Raspberrypi4 on an SD card?

Mon Mar 30, 2020 3:46 am

Hi, This is my first time at this forum.
I'm working on a project using Raspberry Pi4, and I'm writing because I have a question.

I'm using Raspberry Pi 4 and Raspbian Buster(released 20-02-13).
I need to change the RaspberryPi's hostname before first boot.
So, I want to change Pi's hostname on an SD card. Is it possible?

epoch1970
Posts: 5022
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: How to change the hostname of Raspberrypi4 on an SD card?

Mon Mar 30, 2020 11:50 am

Before first boot, you have to edit the image.
At first boot, add your own scriptlet to the image.

If you're in fact interested in the name assumed on the network (hostname.domainname) by the host, then you might be able to configure your DHCP and DNS server to provide a name for the host, and resolve it.
That would work before first boot.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

jbudd
Posts: 1358
Joined: Mon Dec 16, 2013 10:23 am

Re: How to change the hostname of Raspberrypi4 on an SD card?

Mon Mar 30, 2020 3:40 pm

You can do it if you boot your PC from a Linux live USB drive.

Replace "raspberrypi" with your chosen hostname in [mount point of SD rootfs]/etc/hosts and [mount point of SD rootfs]/etc/hostname

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5590
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: How to change the hostname of Raspberrypi4 on an SD card?

Mon Mar 30, 2020 4:23 pm

jbudd wrote:
Mon Mar 30, 2020 3:40 pm
You can do it if you boot your PC from a Linux live USB drive.

Replace "raspberrypi" with your chosen hostname in [mount point of SD rootfs]/etc/hosts and [mount point of SD rootfs]/etc/hostname
Or, if you've another uSDHC card that you can boot your P4B from (with the "wrong" hostname) and a USB card reader to put the, not yet booted uSDHC card in, edit the equivalent files on that. (effectively that's what I used to do, albeit on a Pi that had just been first-booted, before there was a raspi-config option: https://www.cpmspectrepi.uk/raspberry_p ... tName.html ie. in the "Wheezy" days ;) )
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

Return to “General discussion”