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,961
  • 20
  • 87
  • 207
The24thDS
  • 1
  • 4

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

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,961
  • 20
  • 87
  • 207
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,852
  • 5
  • 76
  • 108