Set static/fixed IP address in Yocto at image creation time

Hi all,

are there any way to change the default connman behavior from dhcp to fixed IP (192.168.0.1) from Yocto at image creation time?

I know that the IP can be changed at first access, but I want to set it before in order to access for the first time at a fixed address and then change the settings with a tool like webmin.

Thank you in advance,

Stefano.

Connman is targeted towards mobile network management. It’s strength is in dynamic network configurations, and making use of various (wired and wireless) network technologies.

While it is possible to use connman to configure a static IP address for an ethernet network device, it is not really suited for that use case. I recommend to use systemd-networkd, which is part of our BSP too.

systemd-networkd allows to use a simple configuration files. We already make use of networkd to configure the USB RNDIS network interface. You can add another configuration file inside /etc/systemd/network/ (e.g. called wired.network)…

[Match]
Name=eth0

[Network] 
Address=192.168.0.1/24
Gateway=192.168.0.254

…and integrate it similar to the existing rndis.network file, see bbappend and files sub directory of our systemd configuration: systemd « recipes-core - meta-toradex.git - oe-core BSP layer (obsolete)

To avoid conflicts with connman, remove connman from the image by removing CONMANPKGS from IMAGE_INSTALL in the image recipe:
http://git.toradex.com/cgit/meta-toradex.git/tree/recipes/images/angstrom-lxde-image.bb?h=V2.5-next

(I recommend to test your configuration on a standard image first. You can remove connman using opkg remove connman connman-gnome).

Thank you for your answer Stefan, it works well for the static IP address.

Now I am looking for a (maybe web based) solution that can be used to configure the network interfaces. Webmin doesn’t work well in angstrom, and other web panels that I found are for large server management…
Have you tried some tools for this task?
Any suggestion will be appreciated…

Stefano.

@stefan.agner I am trying to use init-ifupdown instead of systemd-networkd because init-ifupdown use /etc/network/interfaces and this will enable the webmin network configuration module.

The problem is that systemd seems to not call /etc/init.d/network at boot, AFAIK systemd should call sysv scripts… Have you ever tested this scenario? May I create a systemd service script in order to let /etc/init.d/network start?

Thank you for your time,
Stefano.

@Stefano, you probably need to install init-ifupdown (OpenEmbedded Layer Index - init-ifupdown) to make /etc/network/interfaces work. Note that we also had some interference with the System V Init scripts/systemd and connman and included a workaround in the image recipe: console-trdx-image.bb « images « recipes - meta-toradex.git - oe-core BSP layer (obsolete)

@stefan.agner yes, I forgot to mention that I intend to use init-ifupdown.

My tests show that if I remove /etc/systemd/system/networking.service the /etc/init.d/networking script is called and used to manage the network part.
So I want to create a sort of do_mkrmscript in my image recipe in order to remove that file, but unfortunately I haven’t understand how and when you run the ${WORKDIR}/rmscript in your image… Do you launch it via IMAGE_PREPROCESS_COMMAND ?

@Stefano,

Yeah that file actually is a systemd mask file, which means that it disables the networking.service:

root@colibri-vf:~# ls -la /etc/systemd/system/networking.service 
lrwxrwxrwx    1 root     root             9 Dec 16  2015 /etc/systemd/system/networking.service -> /dev/null

It seems that the package systemd-compat-units is responsible for that. The package disables various systemd compatibility services (see SYSTEMD_DISABLED_SYSV_SERVICES). To test, you can remove the networking from that list. The proper way would be to overwrite that variable using a bbappend in your layer.

Thank you @stefan.agner, now init-ifupdown script work well and I am able to use Webmin in order to configure the network interfaces!

I came across this issue today, looking for how to set a static IP address in a bootimage for Colibri iMX6. I understand that a configuration file in /etc/systemd/network/ might be a possibility to achieve that.

However, I’d like to keep connman in my bootimage because I’ve already spent quite some effort to migrate existing implementations for user-controllable IP configuration so that they use connman if running on Colibri iMX6.

So my question is: What is an appropriate, connman-compatible way to set a static IP address/netmask/gateway in a Colibri iMX6 bootimage? It shall be possible to modify the network settings or to switch to DHCP by calls of “connmanctl config …” later on.

So my question is: What is an appropriate, connman-compatible way to set a static IP address/netmask/gateway in a Colibri iMX6 bootimage? It shall be possible to modify the network settings or to switch to DHCP by calls of “connmanctl config …” later on.

You can keep Connman in the Image, but just disable it for testing purposes, as described here.

Best regards,
Jaski