0

I accidentally changed my hostname to an invalid one, containing ".". I managed to change the hostname back to a valid one but the dhcpcd and ssh service fail to start. If I ping my RPi from another computer I get "Destination host unreachable". Also, RPi seems to not be connected to the network. I already tried changing to different hostnames using raspi-config. Nothing worked so far.

I use an ethernet cable connected to the RPi with interace eth0. I have Raspbian installed on a Flash Drive.

dhcpcd

ssh

Ingo
  • 42,107
  • 20
  • 85
  • 197
The24thDS
  • 1
  • 4
  • How did you change it? – Milliways Oct 28 '18 at 10:30
  • I changed it in these 2 files /etc/hostname and /etc/hosts – The24thDS Oct 28 '18 at 10:43
  • On the RPi ... what is the output of hostnamectl ? ... also, your error messages include a "exec format error" ... this may indicate that, somehow, your RPi has a few x86 executables rather than ARM ... Are there any other changes, updates, modifications to the /etc/apt/sources.list file, any PPAs added, any extra packages downloaded and installed ignoring as many errors as possible? – RubberStamp Oct 28 '18 at 12:12
  • You can check if the sshd program matches the system configuration with these two commands: Check the libc architecture using dpkg -l libc6 .... and then ensure sshd is the correct one for that architecture using: ldd /usr/sbin/sshd – RubberStamp Oct 28 '18 at 13:53
  • Add the output from file /usr/sbin/sshd. – goldilocks Oct 28 '18 at 13:55
  • @RubberStamp dpkg -l libc6 -> Name: libc6:armhf Architecture armhf ldd /usr/sbin/sshd -> not a dynamic executable @goldilocks file /usr/sbin/sshd : data and /etc/apt/sources.list has a stretch-backports main – The24thDS Oct 28 '18 at 15:26
  • Two last questions... 1 What is the output of ls -l /usr/sbin/sshd .... 2 What is the output of strings /usr/sbin/sshd |head -n 15 ... It seems pretty clear that somehow at least some of the critical system executables have either been damaged or replaced... I would recommend getting a new SD card and reinstalling Raspbian. You should be able to retrieve any information that you may need from the current SD card once you have a working RPi... use a USB card reader to retrieve any user files. – RubberStamp Oct 28 '18 at 17:55

3 Answers3

1

I suggest, after the modification of the host-name, to connect a keyboard and a screen (if possible) to your raspberry, do a apt-get --purge remove and then install sshd again. Check also /var/log/syslog for errors. We don't have your rasp version, jessie or streetch... Check the package list to be sure to have the right repository for packages install (compatible with your distribution).

  • The problem in this case is, that dhcpcd is also broken and so you cannot connect for updates. – Ingo Oct 28 '18 at 16:07
1

Look at the update. It is important.

Please post text and not images. Just the important error message is stripped-down: dhcpcd(377): ... Exec format error ???. With lack of further information I guess dhcpcd has problems to read its configuration file /etc/dhcpcd.conf or maybe there is anywhere a cached malformed hostname. Please check if there are some unknown entries in dhcpcd.conf. You can look at the journal if there are some related errors shown with:

rpi ~$ journalctl --boot --unit=dhcpcd.service

You can also try to run dhcpcd from the command line with the debug flag -d set:

rpi ~$ sudo /usr/lib/dhcpcd5/dhcpcd -w -d
# or maybe
rpi ~$ sudo /sbin/dhcpcd -w -d

This should give you detailed output on the screen (stderr) what's going on.

Update:
As I have learned from the comment it is very likely that /sbin/dhcpcd and /usr/sbin/sshd are broken or have been replaced. I also see just now that the error message:

Exec format error

is given on dhcpcd AND on sshd. Following the answer from @Valentin R. is a good advice for both packages. You can also first try to reinstall them with:

rpi ~$ sudo apt --reinstall install dhcpcd5
rpi ~$ sudo apt --reinstall install openssh-server

But because dhcpcd is not working it may be a problem that your eth0 interface has no ip address and you cannot connect to the Raspbian repository for update. You can temporary configure the interface. For example I use the local network 192.168.10.0/24 with ip address 192.168.10.60 for the RasPi and default gateway 192.168.10.1. The gateway is the ip address from your internet router. You have to use the ip addresses from your network and must use one for your RasPi that isn't used by another device.

rpi ~$ sudo ip addr add 192.168.10.60 dev eth0
rpi ~$ sudo ip route add default via 192.168.10.1 dev eth0 proto static
rpi ~$ sudo bash -c "echo nameserver 8.8.8.8 >> /etc/resolv.conf"

Couldn't test it, hope it works.

If you can't get it to run you can use systemd-networkd. It doesn't need dhcpcd. For detailed information look at (1). Here only in short. Execute these commands:

# disable classic networking
rpi ~$ sudo -Es
rpi ~# systemctl mask networking.service
rpi ~# systemctl mask dhcpcd.service
rpi ~# sudo mv /etc/network/interfaces /etc/network/interfaces~
rpi ~# sed -i '1i resolvconf=NO' /etc/resolvconf.conf

# enable systemd-networkd
rpi ~# systemctl enable systemd-networkd.service
rpi ~# systemctl enable systemd-resolved.service
rpi ~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Create this file:

rpi ~# cat /etc/systemd/network/04-eth0.network
    [Match]
    Name=eth0
    [Network]
    DHCP=yes

Reboot.
Now you should have a network connection as before.


Reference:
[1] Howto migrate from networking to systemd-networkd with dynamic failover

Ingo
  • 42,107
  • 20
  • 85
  • 197
  • 1
    Exec format error is I am pretty sure exactly what it sounds like. The binary has been replaced or become corrupted. – goldilocks Oct 28 '18 at 13:57
  • @goldilocks Ah..I understand now: the format of the Exec(utable) file is erroneous. OK, we will see with debug. – Ingo Oct 28 '18 at 14:04
  • @Ingo trying to run dhcpcd gives me the same error: cannot execute binary file: Exec format error – The24thDS Oct 28 '18 at 15:22
  • @David I have just updated my answer. – Ingo Oct 28 '18 at 15:47
  • @Ingo ip route add default via 192.168.10.1 dev eth0 proto static gives me RTNETLINK answers: Network is unreachable – The24thDS Oct 28 '18 at 15:54
  • What is your network? Do you have 192.168.10.1? Do you use an ethernet cable with interface eth0 or do you have a wireless connection with interface wlan0? Is it possible to reflash your SD Card? – Ingo Oct 28 '18 at 16:03
  • I have used my IP, yes I use an ethernet cable. I have Raspbian installed on a Flash Drive. @Ingo – The24thDS Oct 28 '18 at 16:43
  • I would guess more of the fs may be damaged and there was a fsck at boot recently; check if there is anything in /lost+found. – goldilocks Oct 28 '18 at 16:47
  • /lost+found is empty – The24thDS Oct 28 '18 at 16:53
  • @David I have updated the answer with using systemd-networkd. You can try this. – Ingo Oct 29 '18 at 10:23
  • @Ingo Thank you for your help. Unfortunately, I couldn't test your commands because my RPi is no longer booting. It gives me Kernel panic -not syncing. At this point I think I will just reinstall Raspbian. – The24thDS Oct 29 '18 at 18:56
  • @David Thank you for the feedback. Most people simply does not respond anymore and I wonder what happened. – Ingo Oct 29 '18 at 20:53
0

I suggest you use sudo raspi-config to change the host name again. Change it to an unwanted name and then change it to the wanted name. Perhaps raspi-config will make all the needed changes.

joan
  • 71,024
  • 5
  • 73
  • 106