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 fromip
and thatip
has "replaced" the older programifconfig
- however on my system both commands work. I have no idea why this is the case.ifconfig
is not an alias forip 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.
network-manager
package is installed andnetwork-manager.service
runs, the configuration is in/etc/NetworkManager/
and the main tool isnmcli
. Your desktop environment (if any) may have its own GUI tool to configure the manager. What is the output ofsystemctl status network-manager.service
? I think I have uninstalled the package in my Debian and now/etc/network/interfaces
works.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...