0

Summary

I am trying to set a static IP on a beaglebone black system. (Running Debian 9)

Thus far, I have tried;

  • editing /etc/network/interfaces

  • creating a shell script and running it from systemd

Neither method has worked so far. I will give a detailed explaination of both at the end of this post, however before this:

  • What is the correct (most sensible) way to set a static IP with Debian 9? Is it the case that there are many possible methods, and that they are all equally as valid?

A few things to point out:

  • I know that ifconfig is different from ip and that ip has "replaced" the older program ifconfig - however on my system both commands work. I have no idea why this is the case. ifconfig is not an alias for ip addr as the output is different. I have no idea what the difference between them is.

  • I know essentially nothing about systemd and I have just copied information I found online here

Details

  • /etc/network/interfaces

I have added the lines

iface eth0 inet static
    address XXX.XXX.XXX.XXX (redacted for obvious reasons)
    netmask 255.255.255.0
    gateway XXX.XXX.XXX.XXX

When I reboot, and run either ifconfig or ip addr I can see that eth0 has a completely different ip to the one I "assigned" in /etc/network/interfaces

I thought this would work as this method is familiar to me. So I don't understand what is going wrong or how to test / debug this.

  • systemd

I made a shell script in /home which sets the ip manually. The shell script contains;

ifconfig eth0 XXX.XXX.XXX.XXX netmask 255.255.255.0
route add default gw XXX.XXX.XXX.XXX eth0

plus one additional debugging line

echo "systemd" > /home/test.txt

If I run this script as root (it is owned by root) from the bash command line, then the ip is changed as expected. (ifconfig shows the expected static ip)

I tried to get systemd to exec this script by adding a new file in /etc/systemd/system called network-set-static-ip.service

The file /etc/systemd/system/network-set-static-ip.service contains

[Unit]
After=networking.service

[Service]
ExecStart=/home/set_ip_static.sh

[Install]
WantedBy=default.target

I have never used systemd before, and I haven't got a clue if any of this is correct, or whether it is just totally wrong.

Restarting the system does not result in the file /home/test.txt being created, so I think systemd is not running the script /home/set_ip_static.sh.

Is there anything obvious I have done wrong? Is there any way to debug systemd somehow and find out what is going wrong?

Conclusion

I should conclude by saying I do not care which method I use to get the ip address set statically. It can be either of these two or something completely different if there is a better alternative.

As long as when the system boots, the IP is set to the static value, then that is good enough.

3
  • If network-manager package is installed and network-manager.service runs, the configuration is in /etc/NetworkManager/ and the main tool is nmcli. Your desktop environment (if any) may have its own GUI tool to configure the manager. What is the output of systemctl status network-manager.service? I think I have uninstalled the package in my Debian and now /etc/network/interfaces works. Commented Jun 19, 2019 at 21:18
  • @KamilMaciorowski It says that service does not exist. I believe I have the GUI version installed. But startx reports command not found... Is startx called something else on this system? Is there a way to check whether I have a gui or network manager installed? nmcli is also another command not found... Commented Jun 19, 2019 at 21:28
  • OK, so it's not Network Manager. I'm not able to help you further (at least for now). Commented Jun 19, 2019 at 21:31

1 Answer 1

0

Note

This answer is not "an answer" to either of the two problems/issues specified in the question above, however it is a possible alternative that works.

References:

https://elritsch.github.io/2017/08/02/execute-script-at-linux-startup.html

https://elritsch.github.io/2017/08/02/execute-script-at-linux-startup.html

Steps

This works with Debian 9 which uses systemd.

  1. Create a script that you want to run, eg /home/script.sh, make it executable (chmod +x /home/script.sh)

  2. Create a file /etc/rc.local which used to exist with SysVinit systems, make it executable

  3. Create /etc/systemd/system/rc-local.service. Add this content

[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local
    
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
    
[Install]
WantedBy=multi-user.target
  1. Edit /etc/rc.local, add this content
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/home/script.sh #add this line to exec script/commands

exit 0
  1. Ensure all scripts are executable and enable the systemd service with systemctl enable rc-local

  2. Reboot

Keywords: systemd sysv sysvinit debian 9 linux run startup script at boot

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .