1

My situation: i need to run some raspberrys, with the same applications and configurations in a network.

I started to configure a single raspberry, running with raspbian. Created an backup of its sd card on ubuntu with dd command and installed this backup on the sd cards of all other raspberrys. Everything looks great.

BUT, now i got the problem, that all raspberrys got the same ip. Although i'm using DHCP. My suspicion is, that there are "temporary" or specific generated files in the image, which are now used by all the raspberrys.

Do i need to regenerate or delete files, to use an image of a specific raspberry, on a different raspberry?

  • Are you sure rpi interface is configured to use DHCP ? It is most likely the case of static ip. – dhruvvyas90 Jun 25 '15 at 14:27
  • 1
    have you tried sudo dhclient -r wlan0 (or whatever your wifi card name is) on the image? BTW - I use one master raspbian image and copy this with dd to 15 SD cards and never have this issue. Now I do reboot my router regularly, and typically before I use the rPi's (classroom setting) which might solve the problem too ... – Phil B. Jun 25 '15 at 15:34
  • 1
  • @user1133275 isn't lease based on mac address ? Since different pis will be having different macs, it is out of question. Just my thought. Not sure. – dhruvvyas90 Jun 25 '15 at 16:49
  • @dastaan, Generally There should be no conflict but as noted in the link there are different DHCP use cases and if he wants to avoid IP sharing with intermittent client connections he should clear the history on the clients before cloning. – user1133275 Jun 25 '15 at 19:28
2

Generally There should be no conflict but as noted here there are different DHCP use cases and if you want to avoid IP sharing with intermittent client connections you should clear the history on the clients before cloning.

dhclient -r -v eth0 && rm /var/lib/dhcp/dhclient.eth0* ;
| improve this answer | |
1

Have you changed the hostname on each of the copied images? Your DHCP server may be assigning addresses based on the hostname of the requesting device. I use dnsmasq as my DHCP server and it does this. This can either be reconfigured on your DHCP server, or by changing the host name on each RPi to be different. To change the hostname, edit /etc/hostname and /etc/hosts.

| improve this answer | |
1

I think user1133275 has the answer to your question (i.-e. cleaning the DHCP cache), but there are a couple of other things to watch out when "cloning" Linux systems.

Change Hostname

First of all, you might want to tune the hostname as well, or you will have the same hostname for all. It is often not a problem, but it is an easy way to find out on which host you are rather than looking at the IP address. You need to change the hostname (or adjust it) in the following files:

  • /etc/hostname
  • /etc/hosts

It would then be best to restart the network but depending on the Raspbian release you are using (Wheezy or Jessie) it might be different, so just reboot :-)

Regenerate SSH host keys

Second, if you have install the SSH server, all your Raspberry Pi will have the same host SSH keys, so you cannot reliably authenticate the Raspberry Pi you are connected to.

On Raspbian it is easy matter: delete the host keys and regenerate them.

sudo rm /etc/ssh/ssh_host_*
sudo dpkg-reconfigure openssh-server

Note: if the last command fails, you can always manually generate them (if you are still in Wheezy, then skip the last one):

ssh-keygen -t rsa -b 4096 -N "" -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t ecdsa -b 521 -N "" -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -N "" -f /etc/ssh/ssh_host_ed25519_key

Restore interface name

Third, you might find that the network interface name (e.g. eth0) is different on each Raspberry Pi. It is because each of them have a different MAC address (unique for each Ethernet board) and those MAC address mapping to interface name are stored in the file /etc/udev/rules.d/70-persistent-net.rules. So on all the "cloned" Raspberry Pi I would edit the file and remove the entry in it. This is a bit more than cosmetic change, if you had some specific configuration or script relying on the interface name, then there will be broken.

Other optional tweaks

Finally, there are other tweaks to perform but it depends of what you are using/installed on this image. For example, you might want to update Samba configuration (the hostname and description), any certificates you created for TLS connections (such as an HTTPS server or for mail server). You might want to change passwords of users (including root if it is activated).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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