Skip to content

Instantly share code, notes, and snippets.

@zoonderkins
Last active June 2, 2022 06:12
Show Gist options
  • Save zoonderkins/688bd44f20ce1794e1120e654e6a2e4b to your computer and use it in GitHub Desktop.
Save zoonderkins/688bd44f20ce1794e1120e654e6a2e4b to your computer and use it in GitHub Desktop.
rc-local on ubuntu

Install rc-local on Ubuntu

sudo nano /etc/rc.local

#!/bin/sh -e

rm /etc/resolv.conf

cat <<EOF >>/etc/resolv.conf
nameserver 76.76.19.19
nameserver 94.140.15.15
nameserver 9.9.9.11

EOF

exit 0
sudo chmod +x /etc/rc.local
sudo systemctl enable rc-local.service
sudo systemctl start  rc-local.service

Error and solution

Error: The unit files have no installation config (WantedBy, RequiredBy, Also, Alias settings in the [Install] section, and DefaultInstance for template units).

Solution:

sudo nano /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target

## 加入 Install 即可, Add Install 
[Install]
WantedBy=multi-user.target        
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment