0

I am trying to use systemd to set the MAC address and IP address of eth1 on my board.

MAC address
To set the MAC address, have created the following service:

/lib/systemd/system/eth1mac.service

[Unit]
Description=Setting up MAC address
Before=network.target

[Service]
ExecStart=/bin/sh /etc/eth1mac

[Install]
WantedBy=multi-user.target

This service points to the shell script here:
/etc/eth1mac

#!/bin/sh

ifconfig eth1 down
ifconfig eth1 hw ether 00:11:22:33:44:55
ifconfig eth1 up

This is working fine.

IP address
To set the IP address, have created the following service:
/lib/systemd/system/eth1ip.service

[Unit]
Description=Setting up eth1 IP address
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/bin/sh /etc/eth1ip

[Install]
WantedBy=multi-user.target

This service points to the shell script here:
/etc/eth1ip

#!/bin/sh

ifconfig eth1 192.168.160.218

Issue
This service is working, but isn't invoked every time we reboot the board. Do I need certain dependencies to ensure this service is re-run at reboot?

0

Do you have to use systemd for this? I wouldn't recommend making your own systemd services with custom shell scripts as it is hard to maintain and can get messy quickly.

The more common way to set a static IP address and MAC address on an interface is to set it in the /etc/network/interfaces config file (assuming a Debian based Linux system).

For example, appending this to the config:

auto eth1
iface eth1 inet manual
    address 192.168.160.218
    netmask 255.255.255.0
    hwaddress ether 00:11:22:33:44:55

There is also a way to configure network interfaces using systemd-networkd daemon that is part of systemd. You would have to edit the corresponding .network file for the interface that you want to configure. systemd-networkd should then configure this interface for you during bootup.

  • Thanks for your help @Jack. I don't have /etc/network/interfaces file. I am developing on Angstrom OS. – Brian Waters Feb 21 at 8:09
  • could you give me an example of what the .network file would look like for eth1 please? – Brian Waters Feb 21 at 10:00
  • From what I recall in my brief time using Angstrom Linux, it uses Connman to manage network interfaces, DNS, etc. Perhaps give this a try?: rocketboards.org/foswiki/Documentation/… – Jack Feb 22 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.