Edit: This is looking like a hardware problem -- I tried reinstalling initscripts, then went back to an older kernel, and both have the same problem. Somehow I never noticed before, or the network interface has developed a fault in the last few months. Either way, it's not systemd's fault :)
I'm having a strange problem getting a manually configured static IP to work. I've created the file /etc/systemd/system/network.service:
[Unit] Description=Network stuff Wants=network.target Before=network.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/sbin/ip link set dev eth0 up ExecStart=/sbin/ip addr add 192.168.0.2/24 dev eth0 ExecStart=/sbin/ip route add default via 192.168.0.1 ExecStop=/sbin/ip addr flush dev eth0 ExecStop=/sbin/ip link set dev eth0 down [Install] WantedBy=multi-user.target
(the wiki instructions say to also create /etc/config.d/network and then sort of import that, but I didn't see much point since this machine will only ever have that one fixed address.)
I then did
systemctl enable network systemctl start network
and it worked -- for that boot. Upon reboot, the network gets started and configured, and if I do "ip addr" I can see that the interface gets the address and everything. I can ping stuff out on the 'net, go places, etc.
So what's the problem? If the machine is freshly booted, I can't reach it from the outside. It won't respond to pings, and I can't ssh to it. If I then log in on the console and send even one packet out, then suddenly I can reach it on inbound connections.
My workaround right now is a cron job that pings the router every minute -- this makes the machine reachable from the outside after a cold boot -- but this is silly. (I tried putting a ping command right in the network.service file, then a call to a shell script that pings and logs its output -- but while that ping was successful, no matter how many delays I put in with sleep to make the ping happen later, it always had no effect on allowing inbound connections. systemd appears to wait for all the commands in network.service to finish executing before whatever comes next. But the cron job fixes things.)
As far as I can tell, there is a brief moment during bootup when everything works as expected (i.e. if I'm quick and very lucky, I can sometimes ping the machine during bootup, for half a second or so. SSH is also reachable during that half-second, but the connection gets reset and the machine goes unresponsive to outside connections before I can log in). So, it seems as if some other part of the bootup process turns off the ability to receive inbound connections *after* the network service/target/whatever runs successfully.
Last edited by thetrivialstuff (2013-02-08 00:38:02)
systemd has a target called network, i think your servicefile may be overriding that target.
Try giving your service a different name, like static-eth0.service
Booting with apg Openrc, NOT systemd.
Automounting : not needed, i prefer pmount
Aur helpers : makepkg + my own local repo === rarely need them
I've renamed it; the problem is still the same: "ip addr" shows that the interface is up and has the correct address, but I cannot reach it from other machines. I do "ping -c1 router_ip", and immediately after that everything works.
I'm still very confused about a lot of systemd things, though, so I will have to do some reading. In particular I don't understand:
- Why network.target would interfere with network configuration. I thought the purpose of making network.service as described in the wiki was that the network.service file "implements" network.target, i.e. tells systemd, "this is how you reach the network target."
- What network.target is, what it's supposed to do, and how it's supposed to work if the file behind it is completely empty except for some comments (and a reference to a man page that also doesn't explain it)
- Why I am able to "systemctl disable network.target" but not "systemctl enable network.target", but network.target can still auto-start even when it's disabled.
- If I try to run "systemctl start eth0_static" (or network.service, before I renamed it) when the interface already has an IP address, it fails. OK; that makes sense, the ip address assignment command returns failure in that case. But, every systemctl command to do with "eth0_static" then also fails, for no reason that I can see. For instance, "systemctl stop eth0_static" should work, because all that does is de-configure and shut down the interface -- which, if the interface is up, should work. The only way to get "systemctl <anything> eth0_static" to work again is to manually deconfigure the interface, then run "systemctl start eth0_static".
K, tried some other things and it looks like a hardware glitch now. So, cron job hack it is, til I trace it down in more detail. I remain confused about those systemd things, though :P