CentOS7怎么设置开机自启动脚本

CentOS7设置开机自启动
设置一个脚本

cat /usr/local/bin/startup.sh 
brctl addbr br0 && brctl addif br0 em1 && ip addr del dev em1 192.168.3.198/24 && ifconfig br0 192.168.3.198/24 up && route add default gw 192.168.3.1

添加到开机启动文件

 cat /etc/rc.d/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/local/bin/startup.sh &

设置可执行权限

chmod +x /usr/local/bin/startup.sh 
chmod +x /etc/rc.d/rc.local 

注意:rc.local也要设置,否则可能开机不执行

posted @ 2023-11-07 17:34  minseo  阅读(414)  评论(0编辑  收藏  举报