shell - linux下的网卡启动后,如何自动加载脚本文件?
ringa_lee
ringa_lee 2017-04-17 15:45:52
[Linux讨论组]
ringa_lee
ringa_lee

ringa_lee

全部回复(2)
ringa_lee

直接在/etc/sysconfig/network-scripts/ifcfg-<name> 的最后写上你要执行的脚本即可
这似乎并不能保证在网卡成功启动后才能执行,也就是只要你尝试启动网卡,这里的命令都会执行,因此你可以尝试写入判断网卡已经成功启动的脚本

怪我咯

我的是fedora发行版本,提供参考:

sudo touch /etc/rc.d/rc.local
sudo vim /etc/rc.d/rc.local

在/etc/rc.d/rc.local文件中写入

#!/bin/bash
# 在这个文件中写入开机启动需要执行的命令

然后使用:wq命令 保存并退出.

赋予可执行权限:
sudo chmod+x /etc/rc.d/rc.local

设置开机启动:
sudo systemctl enable rc-local.service
如果出现以下错误提示:

[root@dev-zhanghua ~]# systemctl enable rc-local.service
The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).


sudo vim /usr/lib/systemd/system/rc-local.service
在rc-local.service文件末尾加入:
[Install]
WantedBy=multi-user.target
并重新设置开机启动:
sudo systemctl enable rc-local.service


查看状态, 如果出现以下提示, 设置成功!
[zhanghua@dev-zhanghua ~]$ systemctl status rc-local.service
rc-local.service - /etc/rc.d/rc.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/rc-local.service; enabled)
Active: active (running) since Wed 2015-04-15 11:37:40 CST; 1h 44min ago
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号