龙空技术网

Centos8系统arp静态绑定开机即生效

onme0 240

前言:

目前我们对“centos自动关机”大约比较看重,小伙伴们都想要剖析一些“centos自动关机”的相关内容。那么小编也在网上网罗了一些关于“centos自动关机””的相关文章,希望姐妹们能喜欢,姐妹们一起来了解一下吧!

概述

上期文章,我们说到主机D(Centos8系统)关机重启后,需要再次执行arp -f /etc/arp-static才能使arp静态绑定生效,本期文章分享一篇关于centos8系统开机自启动运行脚本的文章。

关键词

Centos8系统开机自启动运行自定义的脚本、Systemd

配置开机自启动运行自定义的脚本

第1步:创建自定义的脚本。即创建一个文件,仅包含“arp -f /etc/arp-static”即可,然后赋予“执行权限”;

#创建arp-static.sh脚本文件

[root@localhost ~]# echo 'arp -f /etc/arp-static'>> arp-static.sh

#查看arp-static.sh文件内容

[root@localhost ~]# cat arp-static.sh

arp -f /etc/arp-static

#赋予arp-static.sh执行权限

[root@localhost ~]# chmod +x arp-static.sh

#查看arp-static.sh权限设置

[root@localhost ~]# ls -l arp-static.sh

-rwxr-xr-x 1 root root 23 Dec 26 16:54 arp-static.sh

[root@localhost ~]#

第2步:创建arp-static.service文件,文件内容如下所示:

[root@localhost ~]# cat /usr/lib/systemd/system/arp-static.service

[Unit]

Description=arp-static

ConditionPathExists=/root/arp-static.sh

After=network.target

[Service]

Type=forking

ExecStart=/usr/bin/bash /root/arp-static.sh

[Install]

WantedBy=multi-user.target

[root@localhost ~]#

第3步:设置arp-static.service开机启动运行并查看设置情况;

[root@localhost ~]# systemctl enable arp-static.service

Created symlink from /etc/systemd/system/multi-user.target.wants/arp-static.service to /usr/lib/systemd/system/arp-static.service.

[root@localhost ~]#

#查看arp-static.service开机启动运行设置情况,关键词“enable”

[root@localhost ~]# systemctl status arp-static.service

● arp-static.service - arp-static

Loaded: loaded (/usr/lib/systemd/system/arp-static.service; enabled; vendor preset: disabled)

Active: inactive (dead)

Dec 26 17:09:13 localhost systemd[1]: Starting arp-static...

Dec 26 17:09:14 localhost systemd[1]: Started arp-static.

[root@localhost ~]#

至此,关于arp静态绑定开机自动生效的配置即已完成,经实际测试,系统开机之后,arp静态绑定即生效。

总结

借助arp静态绑定开机即生效的场景,总结分享关于centos8系统开机自启动运行脚本的简单案例,希望各位小伙伴有所收获。

以上分享,不足之处,欢迎各位小伙伴留言指正。

标签: #centos自动关机