You are not logged in.

#1 2018-06-21 05:03:31

zeermooi
Member
Registered: 2018-06-21
Posts: 4

systemd.service static arp

Hello i am trying to create systemd.service that will set static arp when the network is brought up.
I made two services that set static arp succesfully, however when disconnecting and reconnecting, the services have to be restarted to set a new static arp.

I am using NetworkManager with nm-applet to connect.
Here are the two services that i made, but have to be restarted each time:
arp-ethers.service calls the /etc/ethers file to set static arp:

[Unit]
Description=Load static arp entries
ConditionPathExists=/etc/ethers
DefaultDependencies=on
After=network.target

[Service]
Type=oneshot
ExecStart==/sbin/arp -f /etc/ethers 
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

arp -s exec.service:

[Unit]
Description=Load static arp entries
After=network.target

[Service]
Type=oneshot
ExecStart=/sbin/arp -s <set ip here> <set mac here>
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

How can i make sure the static arp is set when nm-applet brings up the network, without manually restarting the .services?

Last edited by zeermooi (2018-06-21 14:53:57)

Offline

#2 2018-06-21 05:36:02

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: systemd.service static arp

Not an Installation issue, moving to Apps & DEs...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2018-06-21 07:24:11

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,431

Re: systemd.service static arp

You want to Wants= and After= (or Before=) on network-online.target and enable NetworkManager-wait-online.service . network.target is invoked when network devices become available, which is too soon for what you want to do.

Also remove the RemainAfterExit=yes, as that will assume the service to have been started, and they won't be invoked again.

Last edited by V1del (2018-06-21 07:35:07)

Offline

#4 2018-06-21 12:08:57

zeermooi
Member
Registered: 2018-06-21
Posts: 4

Re: systemd.service static arp

[Unit]
Description=Load static arp entries
ConditionPathExists=/etc/ethers
DefaultDependencies=on
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/sbin/arp -f /etc/ethers

[Install]
WantedBy=multi-user.target

systemctl enable arp-ethers.service
systemctl start arp-ethers.service

When disconnect the wired network with the nm-applet, and re-connect, the arp entry is not set static, unless: systemctl restart arp-ethers.service
Would love to see the arp entry set static when disconnect/re-connect with nm-applet...

*edit*

~ $ systemctl status NetworkManager-wait-online.service
● NetworkManager-wait-online.service - Network Manager Wait Online
   Loaded: loaded (/lib/systemd/system/NetworkManager-wait-online.service; enabled; vendor preset: disabled)
   Active: active (exited) since Thu 2018-06-21 13:50:41 CEST; 19min ago
     Docs: man:nm-online(1)
 Main PID: 4190 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/NetworkManager-wait-online.service

Jun 21 13:50:41 systemd[1]: Starting Network Manager Wait Online...
Jun 21 13:50:41 systemd[1]: Started Network Manager Wait Online.
concordis@gentoo ~ $ systemctl status arp-ethers.service
● arp-ethers.service - Load static arp entries
   Loaded: loaded (/etc/systemd/system/arp-ethers.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Thu 2018-06-21 14:04:18 CEST; 6min ago
  Process: 4655 ExecStart=/sbin/arp -f /etc/ethers (code=exited, status=0/SUCCESS)
 Main PID: 4655 (code=exited, status=0/SUCCESS)

Jun 21 14:04:18 systemd[1]: Starting Load static arp entries...
Jun 21 14:04:18 systemd[1]: Started Load static arp entries.

Last edited by zeermooi (2018-06-21 12:13:11)

Offline

#5 2018-06-21 13:22:56

seth
Member
Registered: 2012-09-03
Posts: 50,012

Re: systemd.service static arp

I doubt the service is somehow controlled by NM, try https://wiki.archlinux.org/index.php/Ne … dispatcher

Offline

#6 2018-06-21 13:38:39

zeermooi
Member
Registered: 2018-06-21
Posts: 4

Re: systemd.service static arp

Hello seth, thank you.

cd /etc/NetworkManager/dispatcher.d/pre-up.d
then put arp.sh script in there with the #!/bin/sh arp -s command.

Offline

#7 2018-06-21 14:50:10

zeermooi
Member
Registered: 2018-06-21
Posts: 4

Re: systemd.service static arp

is it a bad idea to make the entry arp -a of router/gateway static?

Offline

#8 2018-06-21 19:11:09

seth
Member
Registered: 2012-09-03
Posts: 50,012

Re: systemd.service static arp

Err… what?
1. why do you implement a static ARP if you're not sure why you're doing this?
2. static ARPs are mostly useful to mitigate ARP spoofing, to a certain degree for better performance (but in a ethernet LAN that's rather neglectable)
3. "arp -a" is just a different output format (according to the manpage "BSD-style")

Offline

#9 2019-08-26 00:29:01

ninjazeevis
Member
Registered: 2019-08-12
Posts: 4

Re: systemd.service static arp

I do not want to necrobump this old post, but i was not sure if i should make new post, because the content of this one suits my question.
The answer provider by V1del, solved my issue on making static arp with systemd.service.
When i boot the Arch laptop, wpa_supplicant@wlp1s0.service, and systemd-networkd.service, get started, and there is internet connectivity, without any problems.
The static arp entry is set to permanent.

But when the laptop is connected to the internet for a few hours, the $ arp -a, command shows that the arp entry is not permanent anymore?
How can this happen, and how do i prevent the arp entry from changing?

Offline

#10 2019-08-26 14:41:29

seth
Member
Registered: 2012-09-03
Posts: 50,012

Re: systemd.service static arp

Reasons.
Any process w/ root permissions (like systemd-networkd) can theoretically edit the ARP list, simply flushing the cache should™ ("will", but try yourself: "ip -s -s neigh flush all") not remove static entries, though.

You should
a) open a new thread since this is off-topic (OP tried to add an entry after NM, this is more about systemd services - and he indicated to have no idea why he wanted static entries itfp.)
b) elaborate on what you do and how things change over time (ie. how do you add the entry *exactly* and the conrasting outputs of "arp -n")

Pro tip: if you want to control your network on that level, stupid network managing services that try to outsmart you will only get in your way. NM and systemd-networkd are kitchen sinks.

Offline

Board footer

Powered by FluxBB