@bendraper
If you make a script to do this, you might want to make it monitor eth0 state so if eth0 goes down and back up, the IP doesn't get removed.
Here's a bash example of what I do to check the IP address of ethernet and put it back if it goes down and back up
while true
do
if [[ -e "/sys/class/net/$eth_dongle_interface" ]]; then
eth_dongle_ip=$(ip -4 addr show $eth_dongle_interface | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -1)
else
eth_dongle_ip=""
fi
if [[ "$eth_dongle_ip" != *"$ETHERNET_IP"* && -e "/sys/class/net/$eth_dongle_interface" ]]; then
echo "setting IP address to: $ETHERNET_IP"
ip addr flush dev $eth_dongle_interface
sleep 1
ip link set dev $eth_dongle_interface up
sleep 1
ip addr add $ETHERNET_IP/255.255.255.0 dev $eth_dongle_interface
fi
sleep 1
done
Of course, this is in my modified voxl-modem with custom variables for the interface (eth0 or eth1) and variables for the IP address. You might just want to hard code those when testing.