# Setting a Static IP for Ethernet

**URL:** <https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067>\
**Category:** Product support\
**Created:** [February 12, 2020, 6:03pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067 "2020-02-12T18:03:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [February 12, 2020, 6:03pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/1 "2020-02-12T18:03:11Z")

</div>

Hi,

I’m trying to set a static IP address for my Raspberry Pi 3B+ running Pi-Hole. The device is set up to only use an Ethernet connection and I’m struggling to find the connections file to change the devices IP.

Can anyone help?

I’ve read through some of the other topics on the forums but I can’t quite work out what to do.

Thanks

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [February 12, 2020, 6:07pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/3 "2020-02-12T18:07:43Z")

</div>

Hi Gregor, welcome to the forums!

You can configure a static IP address for your balena device by editing the files inside `system-connections` directory if you mount your SD card on your computer.  
You would need to add the following snippet (tuned to your liking of course):

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

```

You can read more about networking in balenaOS and particularly setting a static IP for Ethernet in our documentation here:

- [https://www.balena.io/docs/reference/OS/network/2.x/#setting-a-static-ip](https://www.balena.io/docs/reference/OS/network/2.x/#setting-a-static-ip)

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [February 12, 2020, 6:12pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/5 "2020-02-12T18:12:47Z")

</div>

Hi Tmigone,

I’ve mounted the SD card in my computer but the only files in the system-connections directory are README.ignore and resin-sample.ignore.

Where should I add this snippet?

Do I need to create a new file?

I think I read that documentation but I couldn’t work out where to set the information as I had only ever edited the resin-wifi-01 file which doesn’t exist in this device.

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [February 12, 2020, 6:16pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/6 "2020-02-12T18:16:42Z")

</div>

You can create a new file an name it however you like, I suggest you use `resin-ethernet` or something like that to make it evident.

You can use the contents of the sample file to know what they should be, or copy them from the documentation:

```auto
[connection]
id=my-ethernet
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

```

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [February 12, 2020, 6:19pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/7 "2020-02-12T18:19:04Z")

</div>

Remember for the `address1=192.168.1.111/24,192.168.1.1` line you should put both the desired static IP and the gateway (your routers IP address most likely).

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [February 12, 2020, 6:29pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/8 "2020-02-12T18:29:53Z")

</div>

Thanks for your reply,

So if my router’s admin panel is 192.168.1.254 and I wanted my devices IP to be 192.168.1.100 would my line be:

address1=192.168.1.100/192.168.1.254

Is this correct?

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [February 12, 2020, 6:36pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/9 "2020-02-12T18:36:37Z")

</div>

Not exactly you would want it to be:

`address1=192.168.1.254/24,192.168.1.100`

The `/24` indicates the subnet mask you want to use (in this case ` /24 --> 255.255.255.0`) which is also required when setting an address.

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [February 12, 2020, 6:41pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/10 "2020-02-12T18:41:59Z")

</div>

Is the routers IP address the same as the IP used to reach its admin panel?

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [February 12, 2020, 6:50pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/11 "2020-02-12T18:50:32Z")

</div>

Yes it should be unless you have a super custom setup, but it’s extremely unlikely.

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [February 12, 2020, 7:11pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/13 "2020-02-12T19:11:22Z")

</div>

Hi tmigone I added the file to the device but it is not coming back online. The green light on the pi is flashing repeatedly in groups of 4 flashes.

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [February 12, 2020, 7:28pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/14 "2020-02-12T19:28:04Z")

</div>

Okay, that would indicate that we messed up the connection file. LED flashing pattern means no connection:

- [https://www.balena.io/docs/faq/troubleshooting/troubleshooting/#unable-to-connect-to-the-internet](https://www.balena.io/docs/faq/troubleshooting/troubleshooting/#unable-to-connect-to-the-internet)

Can you paste the contents of the file in here?

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [February 13, 2020, 6:02pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/16 "2020-02-13T18:02:55Z")

</div>

Thanks for the reply, the file is called resin-ethernet and the contents of the file are:

[connection]  
id=my-ethernet  
type=ethernet  
interface-name=eth0  
permissions=  
secondaries=

[ethernet]  
mac-address-blacklist=

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

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

---

<div class="post-metadata">

**Author:** ![dtischler](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dtischler/32/2483_2.png) [@dtischler](https://forums.balena.io/u/dtischler)\
**Post date:** [February 13, 2020, 7:32pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/17 "2020-02-13T19:32:18Z")

</div>

Hi Gregor, taking a second look at this file, it seems that the local IP Address and Gateway Address are actually backwards in the file, sorry about that! Give this a try instead:

[ipv4]  
address1=192.168.1.100/24,192.168.1.254

Thanks!

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [February 13, 2020, 7:35pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/19 "2020-02-13T19:35:19Z")

</div>

> [@dtischler](#):
>
> address1=192.168.1.100/24,192.168.1.254

Should the connections file have a filetype?

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [February 13, 2020, 7:38pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/20 "2020-02-13T19:38:11Z")

</div>

I Think that worked! Thanks for all your help!

---

<div class="post-metadata">

**Author:** ![dtischler](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dtischler/32/2483_2.png) [@dtischler](https://forums.balena.io/u/dtischler)\
**Post date:** [February 13, 2020, 7:41pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/21 "2020-02-13T19:41:16Z")

</div>

Excellent! Sorry we got that mixed up the first time.

🙂

---

<div class="post-metadata">

**Author:** ![amit3bcrec](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/amit3bcrec/32/5400_2.png) [@amit3bcrec](https://forums.balena.io/u/amit3bcrec)\
**Post date:** [May 9, 2022, 12:45am UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/23 "2022-05-09T00:45:08Z")

</div>

Hi @tmigone I have down this successfully earlier however last week my Pi SD card gone bad and I am adding a new device. I get following error file nmcli reload -

May 09 01:00:59 dfc7315 NetworkManager[1614]: [1652058059.9498] keyfile: ipv4.addresses: unexpected character ’ ’ for address1: '192.168.1.111/24,192.168.1.254 ’ (position 13)  
May 09 01:00:59 dfc7315 NetworkManager[1614]: [1652058059.9499] keyfile: ipv4.dns: ignoring invalid DNS server IPv4 address ’ ’  
May 09 01:00:59 dfc7315 NetworkManager[1614]: [1652058059.9502] keyfile: load: “/etc/NetworkManager/system-connections/resin-ethernet”: failed to load connection: invalid connection: connection.type: connection type 'ethernet ’ is not valid

Anyone seen this before, any advice on how to shoot?

Thanks,  
Amit

---

<div class="post-metadata">

**Author:** ![amit3bcrec](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/amit3bcrec/32/5400_2.png) [@amit3bcrec](https://forums.balena.io/u/amit3bcrec)\
**Post date:** [May 9, 2022, 5:28am UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/24 "2022-05-09T05:28:08Z")

</div>

Workaround update - I could not get the profile load from resin-ethernet file so hardcoded the static IP address via nmcli -

nmcli con add type ethernet con-name my-ethernet ifname eth0 ip4 192.168.1.111/24   
gw4 192.168.1.254  
nmcli con mod my-ethernet ipv4.dns “8.8.8.8 8.8.4.4”

HTH,  
Amit

---

<div class="post-metadata">

**Author:** ![tjb](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@tjb](https://forums.balena.io/u/tjb)\
**Post date:** [July 6, 2022, 1:29pm UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/26 "2022-07-06T13:29:08Z")

</div>

Hi

i was wondering if it is possible to do this from the dashboard? we have a number of devices where we don’t fully know the IP until they are installed. so i was wondering can we do this via a variable or something and not going into the resin-\* folder.

thanks, Tim

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [July 7, 2022, 8:31am UTC](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067/27 "2022-07-07T08:31:49Z")

</div>

Hi,

You could make a wrapper script for your actual application.

Try something like

```auto
#!/bin/bash

if [[-n "${MY_IP_ENV_VAR}" && -n "${MY_IFACE_ENV_VAR}"]]; then
    echo "setting "${MY_IFACE_ENV_VAR}" ip: ${MY_IP_ENV_VAR}"
    ip address add "${MY_IP_ENV_VAR}" dev "${MY_IFACE_ENV_VAR}"
fi

actual_command "$@"

```

With for example `MY_IFACE_ENV_VAR=eth0` and `MY_IP_ENV_VAR=192.168.1.10/24` .

[Next page](https://forums.balena.io/t/setting-a-static-ip-for-ethernet/63067.md?page=2)
