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

7
  • How did you change it?
    – Milliways
    Oct 28, 2018 at 10:30
  • I changed it in these 2 files /etc/hostname and /etc/hosts
    – The24thDS
    Oct 28, 2018 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? Oct 28, 2018 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 Oct 28, 2018 at 13:53
  • Add the output from file /usr/sbin/sshd.
    – goldilocks
    Oct 28, 2018 at 13:55

3 Answers 3

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).

1
  • The problem in this case is, that dhcpcd is also broken and so you cannot connect for updates.
    – Ingo
    Oct 28, 2018 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

12
  • 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, 2018 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, 2018 at 14:04
  • @Ingo trying to run dhcpcd gives me the same error: cannot execute binary file: Exec format error
    – The24thDS
    Oct 28, 2018 at 15:22
  • @David I have just updated my answer.
    – Ingo
    Oct 28, 2018 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, 2018 at 15:54
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.

1
  • I already tried raspi-config.
    – The24thDS
    Oct 28, 2018 at 10:49

Your Answer

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

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