How to permanently set a static IP on a running resinOS?

Workstation: Windows 10
Target device: RPi 2

After flashing and booting I can set a static IP using:
ifconfig eth0 192.168.0.1 netamask 255.255.255.0

I want the static IP to be set at boot time.
I cannot create a new file in /resin-boot/system-connections/ because the system is mounted read only.

How can I permanently set a static IP?

Hi, there are a few ways to do that. The easiest way is after flashing the image, you may drop a connection profile file to the boot partition’s system-connections directly from your Windows machine. Here is a sample file contents: https://docs.resin.io/reference/OS/network/2.x/#setting-a-static-ip

Alternatively you may use the D-Bus NetworkManager’s API to create this connection profile dynamically from inside your application container when the container starts. More information on this here: https://docs.resin.io/reference/OS/network/2.x/#changing-the-network-at-runtime

Please let us know if you have additional questions regarding this.

The easiest way is after flashing the image, you may drop a connection profile file to the boot partition’s system-connections directly from your Windows machine.

I would like to do that, but I cannot, because the filesystem is mounted as Read-only.
Is it safe to temporarily remount as rw? (mount / -o remount,rw)

What I meant is that after flashing the SD card with Etcher, you may access the boot partition from your laptop directly and add the file there - that is before ejecting the SD card from your Windows laptop and before plugging it into the device.

Alternatively like you suggest you may remount temporary the partition in rw mode from the host OS of the device. It is safe to do that.

EDIT: The previous paragraph is not the recommended approach. The /etc/NetworkManager/system-connections folder is already in RW mode and bind mounted to the state partition and serves exactly this purpose

1 Like

I now have the following set up:

root@resin:~# cat /resin-boot/system-connections/resin-static
[connection]
id=resin-static
type=ethernet
interface-name=eth0
permissions=
secondaries=

[ethernet]
mac-address-blacklist=

[ipv4]
address1=192.168.1.111/24,192.168.1.1
dns=8.8.8.8;8.8.4.4;
dns-search=
method=manual

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto

but when the system boots there is no static ip (no ipv4 line in ifconfig output).

Manually executing ifconfig eth0 192.168.1.111 netmask 255.255.255.0 works fine. What could be wrong with my connection file?

Can you please paste the output of the ip route command please? Running that from a host OS terminal.

I got this to work now, but I’m not sure why:

Initially, I edited the connection file directly in /resin-boot/system-connections/ after remounting it as rw. The file I created (resin-static, see above) persisted after a reboot.

I then noticed that /mnt/boot/system-connections/ has different content. I copied my resin-static connection file to /mnt/boot/system-connections/ and now it works.

Why is that?

Actually I misled you on this one… There is another location that is of interest and is already in rw mode. You may add the file directly to /etc/NetworkManager/system-connections which is bind mounted to a folder on the state partition. The state partition is in rw mode and changes should be made preferably there.

There is a paragraph about how the system-connections folders related to one another in the https://docs.resin.io/reference/OS/network/2.x/#changing-the-network-at-runtime section.

Can we still do this or is there extra steps?

Yes, you can add a connection profile on the boot partition’s system-connections folder.

1 Like

That was easy :slight_smile:
I got this to work by logging in remotely and creating a /etc/NetworkManager/system-connections/eth1-static connections file to configure the second network interface on our device.
This makes the file appear in /mnt/state/root-overlay/etc/NetworkManager/system-connections, but not in resin-boot/system-connections, as expected.
Am I understanding this correctly, that once this file exists, it is guaranteed to persist across reboots (already tested that), application upgrades, OS upgrades etc?

Hi @dirk, glad you got it working. Yes the files in /mnt/state/root-overlay are the read/write persistent configuration state for a device and should persist between reboots and OS upgrades.

1 Like

Is there a way to manipulate the /etc/NetworkManager/system-connections directory through the supervisor API? We use dbus and NetworkManager commands today, but would prefer to avoid the Python-based command-line approach.

Is there a way to manipulate the /etc/NetworkManager/system-connections directory through the supervisor API? We use dbus and NetworkManager commands today, but would prefer to avoid the Python-based command-line approach.

I don’t think the supervisor API can be used for that, however it’s possible to use NetworkManager’s DBUS interface with programming languages other than Python. This site provides some pointers and examples: Projects/NetworkManager/Developers - GNOME Wiki!

:thinking: That’s what I said we were currently doing…

I’m now looking at https://github.com/FGRibreau/network-config as a solution.

I meant that other programming languages, like C, Javascript, Ruby and others, can be used to interact with NetworkManager via the DBUS interface, instead of using Python and instead of running command-line tools in child processes. The network-config library may not be a good solution because it seems to be built on ifconfig, and NetworkManager might end up overwriting or conflicting with changes made via ifconfig. If your app uses Javascript / Node, perhaps a library like the following might work better: https://github.com/JumpLink/node-networkmanager although I have not tested it myself. :slight_smile:

Ahh, I see, sorry. Thanks for that tip - I’ll look at using that library instead!