0

I am using Raspbian Stretch Lite 2018-04-18. I currently have static IP working over wifi. I setup /etc/wpa_supplicant/wpa_supplicant.conf to connect to my wifi and setup /etc/dhcpcd.conf to use a static ip:

interface wlan0
static ip_address=192.168.0.101/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

But, instead of making changes to the /etc/dhcpcd.conf file I would like to be able to set the IP address of the Pi from a configuration file located in the /boot directory so that I can easily change it by mounting the sdcard on a Mac computer, which automounts the /boot partition. This will allow me to easily provision multiple pis with different IP addresses.

I know you can setup a static ip for ethernet using /boot/cmdline.txt, so I did try adding ip=192.168.0.101::192.168.0.1:255.255.255.0:rpi:wlan0:off to this file, but that didn't work. This thread seems to imply setting ip in cmdline.txt only works for ethernet.

  • You can create a symlink from /etc/dhcpcd.conf to /boot/dhcpcd.conf and place that file there. – Janka Jun 12 '18 at 18:30
  • Thanks Janka. That seems like it should work, i'll test and let you know. This person, harizanov.com/2014/09/…, seems to think that works. – Andrew Ringler Jun 12 '18 at 20:56
  • @Janka You can't create a symlink on FAT – Milliways Jun 12 '18 at 22:49
  • And? The symlink is on the / fs, not /boot. – Janka Jun 12 '18 at 22:58
0

OK. Thanks for your suggestions Janka. Follows is a full answer.

First edit /etc/wpa_supplicant/wpa_supplicant.conf and /etc/dhcpcd.conf so you are connected to the network the way you want.

Then create the symlinks (also making backups of these config files):

sudo mkdir /boot/network
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf           
/boot/network/wpa_supplicant.conf
sudo mv /etc/wpa_supplicant/wpa_supplicant.conf 
/etc/wpa_supplicant/wpa_supplicant.conf.backup
sudo ln -s /boot/network/wpa_supplicant.conf 
/etc/wpa_supplicant/wpa_supplicant.conf

sudo cp /etc/dhcpcd.conf /boot/network/dhcpcd.conf
sudo mv /etc/dhcpcd.conf /etc/dhcpcd.conf.backup
sudo ln -s /boot/network/dhcpcd.conf /etc/dhcpcd.conf

Now you can edit /boot/network/dhcpcd.conf and /etc/wpa_supplicant/wpa_supplicant.conf when mounting your sd-card from Windows or Mac.

Note that I placed the config files at boot/network instead of directly in boot. I did this because the Pi, I discovered, already has a process that looks for a file at /boot/wpa_supplicant.conf and moves it to /etc/wpa_supplicant/wpa_supplicant.conf when found. Since I eventually want to enable read-only Raspberry pi this copy operation would have been problematic, so placing wpa_supplicant.conf at /boot/network/wpa_supplicant.conf avoids this process.

0

I can't post a comment as I don't have the required reputation - but I've used @Andrew Ringler's answer/method for a while now and it works great. Recently built a new Buster Pi from an image, applied this then tried to do an apt upgrade and got this in the output:

dpkg: error processing package dhcpcd5 (--configure):
 installed dhcpcd5 package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of raspberrypi-net-mods:
 raspberrypi-net-mods depends on dhcpcd5 (>= 6.10.1-1+rpi2); however:
  Package dhcpcd5 is not configured yet.

dpkg: error processing package raspberrypi-net-mods (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 dhcpcd5
 raspberrypi-net-mods
E: Sub-process /usr/bin/dpkg returned an error code (1)

Removing the symlink for /etc/dhcpcd.conf, putting the file back, and re-running apt upgrade solved the issue, and allowed dhcpcd5 to configure itself correctly. I could then swap it back to the symlink and everything carried on as normal.

There's no issue operationally with the symlink, it just seems that dhcpcd (unfortunately!) doesn't like it during an upgrade.

New contributor
Ben N is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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.