我想添加一些静态 ARP 条目,这些条目将在系统重新启动后保留下来。为此,我尝试使用 systemd 服务,该服务只需通过文件填充 ARP 表/etc/ethers
:
[Unit]
Description=startup-test
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=root
Group=root
ExecStart=arp -f
Restart=on-failure
[Install]
WantedBy=multi-user.target
此方法不起作用,并且启动时不会添加 ARP 条目,但 systemd 服务似乎运行该arp -f
命令(尽管由于“网络无法访问”而未成功):
输出systemctl status
:
● startup.service - startup-test
Loaded: loaded (/etc/systemd/system/startup.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sun 2023-01-29 15:10:53 EET; 1min 7s ago
Process: 562 ExecStart=arp -f (code=exited, status=0/SUCCESS)
Main PID: 562 (code=exited, status=0/SUCCESS)
CPU: 14ms
Jan 29 15:10:52 raspberrypi systemd[1]: Started startup-test.
Jan 29 15:10:53 raspberrypi arp[562]: SIOCSARP: Network is unreachable
Jan 29 15:10:53 raspberrypi arp[562]: arp: cannot set entry on line 1 of etherfile /etc/ethers !
Jan 29 15:10:53 raspberrypi arp[562]: SIOCSARP: Network is unreachable
Jan 29 15:10:53 raspberrypi arp[562]: arp: cannot set entry on line 2 of etherfile /etc/ethers !
Jan 29 15:10:53 raspberrypi systemd[1]: startup.service: Succeeded.
但是,如果我使用 手动启动服务systemctl start
,则不会引发任何错误(并且 ARP 表会按预期填充)。
systemctl status
手动启动后的输出:
● startup.service - startup-test
Loaded: loaded (/etc/systemd/system/startup.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sun 2023-01-29 15:11:55 EET; 5s ago
Process: 1664 ExecStart=arp -f (code=exited, status=0/SUCCESS)
Main PID: 1664 (code=exited, status=0/SUCCESS)
CPU: 13ms
Jan 29 15:11:55 raspberrypi systemd[1]: Started startup-test.
Jan 29 15:11:55 raspberrypi systemd[1]: startup.service: Succeeded.
这里有什么问题吗?
附言。我已经成功地通过使用钩子来做我想做的事情dhcpcd
。所以我不是在寻找替代方法,我只是想知道 systemd 方法有什么问题。
(树莓派靶心)