mbellm
Posts: 4
Joined: Sat Jul 07, 2018 5:55 pm

Setting a static IP address from SD card before boot

Sat Jul 07, 2018 5:57 pm

Hi there, I'm wondering if there's a way to set a static IP address from my Mac through the boot drive before I first start my RPI.

Maybe some sort of way to edit /etc/dhcpcd.conf from the SD card?

Thanks!

jbudd
Posts: 1500
Joined: Mon Dec 16, 2013 10:23 am

Re: Setting a static IP address from SD card before boot

Sun Jul 08, 2018 8:34 am

I can't think of a way to do that.

Why do you need a static IP?

fbe
Posts: 649
Joined: Thu Aug 17, 2017 9:08 pm

Re: Setting a static IP address from SD card before boot

Sun Jul 08, 2018 6:03 pm

It would be one way, to guess the IP address of the RPi, when doing a headless setup.

SurferTim
Posts: 1800
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Setting a static IP address from SD card before boot

Sun Jul 08, 2018 6:22 pm

mbellm wrote: Hi there, I'm wondering if there's a way to set a static IP address from my Mac through the boot drive before I first start my RPI.

Maybe some sort of way to edit /etc/dhcpcd.conf from the SD card?

Thanks!
Yes. I have. Insert the SD card into a PC. You may need root privilege to edit.

Navigate to the root drive on the SD card and open /etc/dhcpcd.conf with a text editor. Enter the network settings as shown in the examples there. Save.

jbudd
Posts: 1500
Joined: Mon Dec 16, 2013 10:23 am

Re: Setting a static IP address from SD card before boot

Sun Jul 08, 2018 6:27 pm

Only problem is, the root partition is not accessible from a PC.
But maybe it is accessible from a Mac, which the original poster has?

SurferTim
Posts: 1800
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Setting a static IP address from SD card before boot

Sun Jul 08, 2018 6:30 pm

It is with Ubuntu. I don't use Windows.

ejolson
Posts: 6029
Joined: Tue Mar 18, 2014 11:47 am

Re: Setting a static IP address from SD card before boot

Sun Jul 08, 2018 6:39 pm

jbudd wrote:
Sun Jul 08, 2018 6:27 pm
Only problem is, the root partition is not accessible from a PC.
But maybe it is accessible from a Mac, which the original poster has?
In my opinion, how to edit files on the root partition of an SD card for the Pi should be explained in an official tutorial or as part of the standard documentation. In short, two possible ways to do this are

1. Use another Pi setup as a desktop machine with a USB card reader to modify /etc/dhcpcd.conf on the root partition of the new SD card for the headless Pi.

2. Live boot the x86 Raspberry Pi desktop on either a Mac or PC compatible and use that.

SurferTim
Posts: 1800
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Setting a static IP address from SD card before boot

Sun Jul 08, 2018 7:24 pm

Three possible ways. Use a Ubuntu/Debian PC to edit the file.

User avatar
HawaiianPi
Posts: 6004
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Setting a static IP address from SD card before boot

Sun Jul 08, 2018 10:38 pm

fbe wrote:
Sun Jul 08, 2018 6:03 pm
It would be one way, to guess the IP address of the RPi, when doing a headless setup.
Why do you need to guess?

With a Mac you should be able to SSH into pi@raspberrypi.local, and then do whatever you want. You can also easily find the IP with a network scanner app, like Fing for smartphones. Some router makers also have apps (I have the ASUS router app on my phone and can see everything connected to my router, regardless of which network they're using).

You can also set the IP of the Pi in your router's DHCP configuration, which is actually the best way to get a static IP on your local network, because the IP is assigned to the hardware ID of the device, so it will always have the same IP, no matter what you are running on it. I don't have to worry about messing with static IP settings on every SD card because the're set in my router. I can put any card in any of my Pi computers and I know which IP I have given them.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5915
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Setting a static IP address from SD card before boot

Sun Jul 08, 2018 11:12 pm

HawaiianPi wrote:
Sun Jul 08, 2018 10:38 pm
fbe wrote:
Sun Jul 08, 2018 6:03 pm
It would be one way, to guess the IP address of the RPi, when doing a headless setup.
...
You can also set the IP of the Pi in your router's DHCP configuration, which is actually the best way to get a static IP on your local network, because the IP is assigned to the hardware ID of the device, so it will always have the same IP, no matter what you are running on it. I don't have to worry about messing with static IP settings on every SD card because the're set in my router. I can put any card in any of my Pi computers and I know which IP I have given them.
+1 I've used that method for almost every device connected to the house network, not just the Pi's. The exception was an old USB NAS device which I didn't get around to reconfiguring and thus now temporarily unusable after my IP upgraded the modem/router which used a different local network address set (by default) Also any static address needs to be outside of the range assigned by the (router 's) DHCP server. The only time I regard a static IP as being useful is when a "one to one" ( network style) connection is needed between two devices only.
Trev
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

ejolson
Posts: 6029
Joined: Tue Mar 18, 2014 11:47 am

Re: Setting a static IP address from SD card before boot

Mon Jul 09, 2018 4:48 am

FTrevorGowen wrote:
Sun Jul 08, 2018 11:12 pm
HawaiianPi wrote:
Sun Jul 08, 2018 10:38 pm
fbe wrote:
Sun Jul 08, 2018 6:03 pm
It would be one way, to guess the IP address of the RPi, when doing a headless setup.
...
You can also set the IP of the Pi in your router's DHCP configuration, which is actually the best way to get a static IP on your local network, because the IP is assigned to the hardware ID of the device, so it will always have the same IP, no matter what you are running on it. I don't have to worry about messing with static IP settings on every SD card because the're set in my router. I can put any card in any of my Pi computers and I know which IP I have given them.
+1 I've used that method for almost every device connected to the house network, not just the Pi's. The exception was an old USB NAS device which I didn't get around to reconfiguring and thus now temporarily unusable after my IP upgraded the modem/router which used a different local network address set (by default) Also any static address needs to be outside of the range assigned by the (router 's) DHCP server. The only time I regard a static IP as being useful is when a "one to one" ( network style) connection is needed between two devices only.
Trev
The DHCP servers built into some home routers, such as the one I have, don't let you assign specific IP addresses to particular devices based on MAC numbers. While it would be possible to turn off the built-in server and run a full featured one on the Pi, that would still involve setting a static IP for the Pi. In a home or hobby setting there can also be situations where no DHCP service is available at all, either because one is using a bare network cable between two machines or a simple switch. Relying on DHCP also introduces a single point of failure: No machine can use the network if the DHCP server is down.

Although directly setting static IP numbers in each device doesn't scale well beyond about 50 devices, learning something simple before attempting a more complicated setup may lead to a gentler learning curve from an educational point of view.

User avatar
HawaiianPi
Posts: 6004
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Setting a static IP address from SD card before boot

Mon Jul 09, 2018 8:13 am

ejolson wrote:
Mon Jul 09, 2018 4:48 am
The DHCP servers built into some home routers, such as the one I have, don't let you assign specific IP addresses to particular devices based on MAC numbers.
Sounds like you need a better router...

ejolson wrote:
Mon Jul 09, 2018 4:48 am
In a home or hobby setting there can also be situations where no DHCP service is available at all, either because one is using a bare network cable between two machines or a simple switch.
Yes, and those are the details that should be included in the OP of a request for help (otherwise assumptions are made and it wastes everyone's time).

ejolson wrote:
Mon Jul 09, 2018 4:48 am
Relying on DHCP also introduces a single point of failure: No machine can use the network if the DHCP server is down.
And if your router is down, then DHCP is the least of your troubles. Not sure what point you are trying to make here. :?

ejolson wrote:
Mon Jul 09, 2018 4:48 am
... learning something simple before attempting a more complicated setup may lead to a gentler learning curve from an educational point of view.
True, and I offered a few other options that are simpler than pre-configuring a static IP. I've been here a while, and in my experience when someone using a static IP comes here asking for help, it is almost always their attempt at setting a static IP that caused their troubles.

SSH by hostname, or logging into a router (or using a network scanner app) to find the IP are simpler and less error prone solutions for Windows or Mac users which can't access the ext4 rootfs partition by default. Of course those aren't the only options, just the easier ones (in my opinion).
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

User avatar
HawaiianPi
Posts: 6004
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Setting a static IP address from SD card before boot

Mon Jul 09, 2018 8:36 am

mbellm wrote:
Sat Jul 07, 2018 5:57 pm
Hi there, I'm wondering if there's a way to set a static IP address from my Mac through the boot drive before I first start my RPI.

Maybe some sort of way to edit /etc/dhcpcd.conf from the SD card?

Thanks!
After responding to ejolson's reply it occurred to me that I did not directly address your original question. Editing the /etc/dhcpcd.conf file would require accessing the ext4 formatted rootfs partition of the Raspbian imaged SD card, and neither Windows or Mac OS can do that by default.

There are options like installing additional filesystem drivers to your Mac, or a virtual machine running Linux, or dual booting with Linux, or a live Linux distro (one you can run without installing).

If you have another Pi computer already set up you can use that to edit the card (even headless over SSH).

But if all you want is an easy way to connect via SSH or VNC, then a static IP is not needed and the options I offered above are easier.

There are also other network scanner apps, but I like to suggest Fing because it really is a nice app that even puts a little Raspberry icon next to your Pi computers to make them easier to find on a crowded network.
Last edited by HawaiianPi on Mon Jul 09, 2018 11:42 pm, edited 1 time in total.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

User avatar
DougieLawson
Posts: 40227
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Setting a static IP address from SD card before boot

Mon Jul 09, 2018 8:42 am

If using ethernet rather than WiFi you can add

Code: Select all

ip=192.168.3.14
to the end of F:\cmdline.txt on Windows with Notepad++.

It's crude and ugly and not recommended.
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

User avatar
davidcoton
Posts: 5505
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Setting a static IP address from SD card before boot

Mon Jul 09, 2018 8:44 am

ejolson wrote:
Mon Jul 09, 2018 4:48 am
Although directly setting static IP numbers in each device doesn't scale well beyond about 50 devices, learning something simple before attempting a more complicated setup may lead to a gentler learning curve from an educational point of view.
I disagree entirely. In my experience setting static IPs on a device leads to a hard and harsh learning experience -- "Don't do that."
  • Most of us struggle to manage a list of five static IPs on a network, let alone 50.
  • Static IPs still require the router to be configured NOT to use those addresses.
  • Devices with static IPs cannot be safely moved to other networks.
It's far better to learn the right way first time, than to have to un-learn and re-do a network static configuration.
Of course it would be better still if we could let DHCP do its stuff (without address reservation), and device names would "just work"across all network devices and OSs. But that is not reality at present.
Location: 345th cell on the right of the 210th row of L2 cache

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Setting a static IP address from SD card before boot

Mon Jul 09, 2018 9:40 am

davidcoton wrote:
Mon Jul 09, 2018 8:44 am
[*]Static IPs still require the router to be configured NOT to use those addresses.
I agree with "Don't do that." for static IP.

However, I'd like to mention that some routers would check if an dynamic IP is usable before assigning it to a client. The dnsmasq would send a ICMP ping to make sure the IP is usable.

rhildinger
Posts: 39
Joined: Thu Jun 09, 2016 6:07 pm

Re: Setting a static IP address from SD card before boot

Wed Jul 11, 2018 9:21 pm

SurferTim wrote:
Sun Jul 08, 2018 7:24 pm
Three possible ways. Use a Ubuntu/Debian PC to edit the file.
For the sake of completeness, there is actually a 4th way to edit files on the root partition of a Pi SD card, but this method requires $. You can install an extFS driver for Mac that will allow it read and write to Linux ext partitions:

https://www.paragon-software.com/home/extfs-mac/

Unfortunatley, it costs $40 USD.

jerrm
Posts: 202
Joined: Wed May 02, 2018 7:35 pm

Re: Setting a static IP address from SD card before boot

Wed Jul 11, 2018 10:15 pm

rhildinger wrote:
Wed Jul 11, 2018 9:21 pm
For the sake of completeness, there is actually a 4th way to edit files on the root partition of a Pi SD card, but this method requires $. You can install an extFS driver for Mac that will allow it read and write to Linux ext partitions:

https://www.paragon-software.com/home/extfs-mac/

Unfortunatley, it costs $40 USD.
Does the mac version not have the trial mode? On Windows unregistered Paragon extfs is fully functional for something like 10 days. After that it works, but is limited to something like 5mbps speed. Annoyingly slow, but more than adequate for editing the occasional config file.

mbellm
Posts: 4
Joined: Sat Jul 07, 2018 5:55 pm

Re: Setting a static IP address from SD card before boot

Thu Aug 16, 2018 4:37 am

Hi all, just getting around to reading all your responses. Great discussion so far. I'm actually doing this all on a subnet with about 50 Pis so there is no router involved at all. I used the extFS Mac trial for a while until it expired :(.
DougieLawson wrote:
Mon Jul 09, 2018 8:42 am
If using ethernet rather than WiFi you can add

Code: Select all

ip=192.168.3.14
to the end of F:\cmdline.txt on Windows with Notepad++.

It's crude and ugly and not recommended.
This would actually work for my purposes but for whatever reason it doesn't seem to work for me... Not sure why, I am using ethernet.

User avatar
DougieLawson
Posts: 40227
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Setting a static IP address from SD card before boot

Thu Aug 16, 2018 5:50 am

That ip=xxx.xxx.xxx.xxx is there for a root fs on a network file system share so it should still work.

https://www.kernel.org/doc/Documentatio ... fsroot.txt
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Pr0toc01
Posts: 1
Joined: Sun Sep 30, 2018 7:36 am

Re: Setting a static IP address from SD card before boot

Sun Sep 30, 2018 7:41 am

You can access your Ext2 Ext3 Ext4 filesystems on windows using Ext2Fsd ( http://www.ext2fsd.com/?cat=3 )

There are a few ways actually

Here is a link to an article on How-To-Geek that covers 3 ways
https://www.howtogeek.com/112888/3-ways ... m-windows/


Im a fan of Ext2Fsd, personally.

nickfox
Posts: 4
Joined: Tue Nov 14, 2017 11:18 pm

Re: Setting a static IP address from SD card before boot

Sat Jul 27, 2019 6:26 pm

there may be something to help you in the official documentation
https://www.raspberrypi.org/documentati ... address.md

mikeyw64
Posts: 20
Joined: Fri Sep 13, 2019 9:55 am

Re: Setting a static IP address from SD card before boot

Wed Oct 02, 2019 10:14 pm

+1 on Ext2Fsd to edite /etc/dhcpcd.conf from windows.

Only thing I have to add is to make sure you use a static IP that is outside of the range assigned by your router to avoid conflict(if needs be adjust the range but mine started at 192.168.1.100 by default.

ALso dont forget to add a default route to your main routers lan IP & a DNS address eg

Code: Select all

interface eth0
static ip_address= 192.168.1.10/24
static routers=192.168.1.1
static domain_name_servers=1.1.1.1

ok maybe not essential but saves faffing about :)

swathy
Posts: 1
Joined: Thu Jan 23, 2020 8:16 am

Re: Setting a static IP address from SD card before boot

Mon Mar 16, 2020 11:58 am

This worked for me to do headless IP setup from my ubuntu system. https://foolsvilla.blogspot.com/2020/03 ... s-for.html
My IP address range was different though :D :) :)

NimbUx
Posts: 275
Joined: Fri Jan 03, 2020 10:33 am

Re: Setting a static IP address from SD card before boot

Mon Mar 16, 2020 8:05 pm

I used extfsd with success to access Linux ext2 / ext3) parts under various older Windows versions (XP to Seven, *32 bit* only though). But when I installed and tried the *64* bit version under Windows Ten *64 bits* a few weeks ago, precisely in an attempt to access ext4 parts of my RPi's CF, I had no success, ext2fs did not seem to work, so was uninstalled. I may not have been persistent enough, do you guys confirm the newest ext2fsd working on Win10-64 bits ?
Otherwise, I can mention a free (as in beer, only) solution that does work for me has been: DiskGenius

Return to “General discussion”