How to Activing rc.local on Ubuntu Server 18.04

How to Activing rc.local on Ubuntu Server 18.04 – Usually we use rc.local to run scripts or commands when the server has finished restarting. However, by default the rc.local function is not activated on the ubuntu server operating system.

rc-local Ubuntu Server 18.04

So, you need to activate it first before you can use it. To run the script or command that you want to run.

Enabling rc.local on Ubuntu Server is not difficult, just activate using systemctl and create the rc.local file in the /etc/ folder and give execute access to the file.

Step by Step to Activate rc.local:

Before following the steps below, make sure your server can be accessed. After that, remote your server via SSH for smooth configuration.

Step 1 – Create file rc.local

First, create the rc.local file in the /etc/ folder in root mode.

$ sudo -i
# nano /etc/rc.local

Step 2 – Fill with bash script in the rc.local file

Second, please fill in the rc.local file using bash script.

#!/bin/bash

add your script or command here

# example
route add -net 192.168.0.0/24 gw 192.168.0.100

exit 0

Step 3 – Grant Execute Access File rc.local

Third, grant execute access rights to the rc.local file.

# chmod +x /etc/rc.local

Step 4 – Enabling rc-local

Finally, please enable rc-local config.

# systemctl enable rc-local

Verify your configuration by restarting your server. Make sure the script or command that you put in the /etc/rc.local file goes as desired.

About Ahmad Lukman Hakim 61 Articles
Admin LUKMANLAB, Network Engineer, System Administrator.