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

**URL:** <https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006>\
**Category:** Product support\
**Tags:** network\
**Created:** [September 19, 2018, 9:10pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006 "2018-09-19T21:10:43Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://forums.balena.io/u/leon)\
**Post date:** [September 19, 2018, 9:10pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/1 "2018-09-19T21:10:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [September 20, 2018, 11:05am UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/4 "2018-09-20T11:05:21Z")

</div>

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](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](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.

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://forums.balena.io/u/leon)\
**Post date:** [September 20, 2018, 1:20pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/5 "2018-09-20T13:20:10Z")

</div>

> 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`)

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [September 20, 2018, 1:58pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/6 "2018-09-20T13:58:47Z")

</div>

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_

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://forums.balena.io/u/leon)\
**Post date:** [September 20, 2018, 2:11pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/7 "2018-09-20T14:11:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [September 20, 2018, 2:41pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/8 "2018-09-20T14:41:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://forums.balena.io/u/leon)\
**Post date:** [September 20, 2018, 3:09pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/9 "2018-09-20T15:09:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [September 20, 2018, 3:17pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/10 "2018-09-20T15:17:07Z")

</div>

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](https://docs.resin.io/reference/OS/network/2.x/#changing-the-network-at-runtime) section.

---

<div class="post-metadata">

**Author:** ![bgold](https://avatars.discourse-cdn.com/v4/letter/b/cab0a1/32.png) [@bgold](https://forums.balena.io/u/bgold)\
**Post date:** [October 15, 2018, 7:16pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/13 "2018-10-15T19:16:27Z")

</div>

Can we still do this or is there extra steps?

> [@majorz](#):
>
> may drop a connection profile file to the boot partition’s `system-connections` directly from your Windows machine

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [October 16, 2018, 9:20am UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/14 "2018-10-16T09:20:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dirk](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@dirk](https://forums.balena.io/u/dirk)\
**Post date:** [May 24, 2019, 7:38am UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/15 "2019-05-24T07:38:13Z")

</div>

That was easy 🙂  
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?

---

<div class="post-metadata">

**Author:** ![shaunmulligan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/shaunmulligan/32/34_2.png) [@shaunmulligan](https://forums.balena.io/u/shaunmulligan)\
**Post date:** [May 24, 2019, 7:45am UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/16 "2019-05-24T07:45:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jgentes](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jgentes/32/1595_2.png) [@jgentes](https://forums.balena.io/u/jgentes)\
**Post date:** [June 14, 2019, 8:49pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/20 "2019-06-14T20:49:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pdcastro](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pdcastro/32/1264_2.png) [@pdcastro](https://forums.balena.io/u/pdcastro)\
**Post date:** [June 28, 2019, 10:39pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/23 "2019-06-28T22:39:10Z")

</div>

> _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!](https://wiki.gnome.org/Projects/NetworkManager/Developers)

---

<div class="post-metadata">

**Author:** ![jgentes](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jgentes/32/1595_2.png) [@jgentes](https://forums.balena.io/u/jgentes)\
**Post date:** [June 28, 2019, 10:52pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/25 "2019-06-28T22:52:18Z")

</div>

🤔 That’s what I said we were currently doing…

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

---

<div class="post-metadata">

**Author:** ![pdcastro](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pdcastro/32/1264_2.png) [@pdcastro](https://forums.balena.io/u/pdcastro)\
**Post date:** [June 28, 2019, 11:09pm UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/30 "2019-06-28T23:09:41Z")

</div>

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](https://github.com/FGRibreau/network-config) library may not be a good solution because it seems to be built on [ifconfig](https://linux.die.net/man/8/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](https://github.com/JumpLink/node-networkmanager) although I have not tested it myself. 🙂

---

<div class="post-metadata">

**Author:** ![jgentes](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jgentes/32/1595_2.png) [@jgentes](https://forums.balena.io/u/jgentes)\
**Post date:** [June 29, 2019, 4:28am UTC](https://forums.balena.io/t/how-to-permanently-set-a-static-ip-on-a-running-resinos/4006/32 "2019-06-29T04:28:02Z")

</div>

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