ubuntu 20.04 預設重開機時無法啟用 /etc/rc.local
如果要重開機後執行的話,修改方式如下
1. 在檔案的最末端加入以下三行,存檔離開
vi /lib/systemd/system/rc-local.service
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
2. 建立 rc.local
vi /etc/rc.local
#!/bin/bash
route add -net 10.190.0.0 netmask 255.254.0.0 gw 10.191.14.253
route add -net 10.160.0.0 netmask 255.255.0.0 gw 10.191.14.253
3. 加入可執行權限
chmod +x /etc/rc.local
4. 設定開機啟動,並手動啟用測試
vi /lib/systemd/system/rc-local.service
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
systemctl daemon-reload
systemctl enable rc-local
systemctl start rc-local
systemctl status rc-local