1

I have a strange problem with ma Raspberry Pi, and I'd like to fix it, but I have no idea how.

Normally when running, it will advertise its configured hostname to my router, so that I can access it with that hostname. But sometimes, it will advertise its hostname as $_HOSTNAME instead. The strange thing is that it doesn't just decide on boot, but when it is just sitting there, suddenly it changes the hostname. I know that it must be the Pi, as it happened with different home routers (Fritzbox and Speedport), and no matter how it is connected (on the Fritzbox it was connected on WiFi only, now it has both WiFi and Ethernet connection, though the WiFi apparently shut down automatically, and it is listed as $_HOSTNAME on its ethernet connection by the router).

In case it matters: It's a Raspberry Pi 2B running Raspbian. I don't remember the OS version (or how to figure it out), but uname -rv gives 4.19.66+ #1253 Thu Aug 15 11:37:30 BST 2019. OTOH, the problem occurred both before and after an OS upgrade, so the version probably doesn't matter too much anyway.

I've grepped for $_HOSTNAME in /etc, and found this in /etc/wicd/dhclient.conf.template:

# wicd will replace $_HOSTNAME in the following line with
# the appropriate hostname for this system
send host-name "$_HOSTNAME";

So I guess the problem is with wicd not properly doing this replacement sometimes. But I have no idea why (and more importantly, how to fix it).

Edit: Contents of /etc/os-release:

PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

UPDATE with info from comments:
Actually the original version came on a SD-card I bought together with the Pi itself (it was some system where you could choose between OSs, but I don't remember the details because it's quite a long time since). Since then I've moved it to a bigger SD card, and at some time did a version upgrade through apt-get by changing repositories, following a guideline found on the internet. Thinking about it, I can't really exclude that the initial install system installed a non-standard configuration of Raspbian. Anyway, I never touched the networking stack myself.

What about earlier versions? Since I at one point upgraded through apt-get, it might still use whatever was used by the previous version (which was quite old, definitely 2016 at latest, as it was unused since then until I reactivated it last year).

7
  • 1
    wicd is not installed on Raspbian by default. Either you use an unmodified Raspberry Pi OS or you tell us what you have changed on your installation to get wicd.
    – Ingo
    Commented Dec 28, 2020 at 11:23
  • Are you actually using wicd, or just have it installed? Commented Dec 28, 2020 at 11:53
  • dhclient.conf.template ... unlikely a file called *.template is going to actually have any impact on anything Commented Dec 28, 2020 at 12:09
  • @DmitryGrigoryev: I have no idea; for everything networking I just used the default configuration. It's just the only place in /etc I found this when I grepped for [^A-Z]_HOSTNAME so I guessed that this might be relevant.
    – celtschk
    Commented Dec 28, 2020 at 13:29
  • Tell us the OS. Type this in your terminal window: cat /etc/os-release. Edit your question to add the results.
    – Seamus
    Commented Dec 28, 2020 at 15:08

4 Answers 4

2

You are running an old version of the OS: stretch). The current version is buster. Nothing particularly wrong with that - unless you're having problems, and calling on others to help!

Raspberry Pi OS (nèe Raspbian) is based on Debian. Debian updates on an irregular schedule (we will sell no wine before it's time), but stretch was released in 2017. In other words - the "answer" for you is to download a new image, and re-flash your SD card:

1. Download the image you need.

2. Backup/save any files you need from your SD card to a USB/thumb drive

3. Remove SD card & re-flash

4. Insert SD card & apply power - following the appropriate instructions

If you encounter any issues, please post a new question here.

2
  • Well, that certainly will be a major undertaking which will have to wait until I have sufficient time.
    – celtschk
    Commented Dec 28, 2020 at 17:33
  • @celtschk: An hour? If you're concern is losing data you might have created, get youself an extra SD card. Seriously - this is not an involved procedure.
    – Seamus
    Commented Dec 28, 2020 at 20:24
0

wicd runs dhclient with config file in /var/lib/wicd which gets copied there from /etc/wicd/dhclient.conf.template. The default config file contained the line: send host-name "$_HOSTNAME"; the comment says "# wicd will replace $_HOSTNAME in the following line with the appropriate hostname for this system". This didn't seem to be working at version 1.7.4 Solution: I replaced /etc/wicd/dhclient.conf.template with /etc/dhcp/dhclient.conf

0

Doing a sudo raspi-config and renaming the host worked for me. After a reboot the $_hostname was gone from the list of active dhcp leases in my TP-link router web interface.

PS: Mind the hostname naming conventions.

-1

I will check the following and see if the wrong name is there:

hostname -s

check the dhcp config file, this should send the hostname in quotes to the router:

grep 'send host-name' /etc/dhcp/dhclient.conf

also, check or edit the hosts, verify the incorrect name is not there:

cat /etc/hosts
9
  • 1
    What has dhclient to do with it?
    – Seamus
    Commented Dec 28, 2020 at 14:50
  • The first one gives the correct hostname, the second one gives send host-name = gethostname();
    – celtschk
    Commented Dec 28, 2020 at 15:45
  • @celtschk: Perhaps ignore this answer until fcm explains why he's calling on dhclient. AFAICR, stretch (your OS ver) came with dhcpcd as the default DHCP client.
    – Seamus
    Commented Dec 28, 2020 at 16:09
  • @Seamus: What about earlier versions? Since I at one point upgraded through apt-get, it might still use whatever was used by the previous version (which was quite old, definitely 2016 at latest, as it was unused since then until I reactivated it last year).
    – celtschk
    Commented Dec 28, 2020 at 16:19
  • 1
    No, there is no dhclient, so it cannot send the hostname to the router.
    – Ingo
    Commented Dec 28, 2020 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.