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=
static routers=
static domain_name_servers=

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= 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

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           
sudo mv /etc/wpa_supplicant/wpa_supplicant.conf 
sudo ln -s /boot/network/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.

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.