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

network

#1

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?


#4

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.


#5

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)


#6

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


#7

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?


#8

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


#9

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?


#10

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.


#13

Can we still do this or is there extra steps?


#14

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