Setting a Static IP for Ethernet

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

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

[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:

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.

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:

[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

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

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?

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.

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

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

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.

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

Can you paste the contents of the file in here?

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

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!

Should the connections file have a filetype?

I Think that worked! Thanks for all your help!

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

:slight_smile:

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

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

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

Hi,

You could make a wrapper script for your actual application.

Try something like

#!/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 .