因为服务器一重启很多配置就要重新配,很麻烦,那么有没有一种方式可以实现开机自启动。当然有了,那就是配置rc.local文件了!
那什么是rc.local脚本嗯?
rc.local脚本是一个Ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令。该脚本位于/etc/路径下,需要root权限才能修改。
该脚本具体格式如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14!/bin/sh -e
rc.local
This script is executed at the end of each multiuser runlevel.
Make sure that the script will "exit 0" on success or any other
value on error.
In order to enable or disable this script just change the execution
bits.
By default this script does nothing.
exit 0注意: 一定要将命令添加在exit 0之前。里面可以直接写命令或者执行Shell脚本文件sh。
下面这个是用来开机自启动网络的命令
1
2
3
4
5
6
7
8add by SongJianTao 2018-5-8
use to config network auto
ip addr del dev enp11s0 192.168.1.50/24
tunctl -t tap0
brctl addif be-ex tap0
ifconfig tap0 0.0.0.0 promisc up
end by SongJianTao注意如果不生效的话,可以尝试rc.local文件头部/bin/sh修改为/bin/bash,还可以增加日志输出功能,来查看最终为什么这个脚本不启动的原因,代码如下所示:
1 |
|
- 今天正在奋笔疾书、焦头烂额的写报告,老胡说他要上网,但是服务器怎么也上不去网,查了很多原因也不知道(mmp,原来没出现过这种情况啊),经过层层排查,最后可能是因为交换机长期没有关的的问题,导致不能用(交换机的质量这么差的吗), 所以直接把网线接在了路由器上,那就要更改配置了,不要直接在/etc/resolve.conf那设置,因为重启会消失,要在/etc/resolvconf/resolv.conf.d/base 这个文件下改,加上nameserver 192.168.1.1 这样就可以了,然后果然可以了,所以这个不能赖我了,要赖交换机!这个锅我不背!