Bagi Anda yang sudah terbiasa mengunakan file rc.local di Debian 8, mungkin agak sedikit bingung karena pada Debian 10 file tersebut sudah tidak ada.
Ya secara resmi Debian 10 sudah menghapus file rc.local yang biasanya kita gunakan untuk melakukan inisiasi program atau script agar aktif secara otomatis saat server booting . Nah, untuk membuat atau mengaktifkan kembali ikuti tutorial berikut ini :
- Buat file dengan nama “rc-local.service” pada folder /etc/systemd/system/ dan isinya silahkan copy dari script berikut ini
root@ns1:~# pico /etc/systemd/system/rc-local.service
[Unit] Description=/etc/rc.local ConditionPathExists=/etc/rc.local [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target
- Buat file “rc.local” di dalam folder /etc/ dan isinya silahkan copy dari script berikut ini
root@ns1:~# pico /etc/rc.local
#!/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
- Berikan hak akses execution (+x) pada file rc.local agar dapat di eksekusi atau dijalankan
root@ns1:~# chmod +x /etc/rc.local
- Aktifkan file rc-local
root@ns1:~# systemctl enable rc.local.service
Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /etc/systemd/system/rc-local.service.
- Jalankan file rc-local
root@ns1:~# systemctl start rc-local.service
- Cek status file rc-local apakah sudah aktif
root@ns1:~# systemctl status rc-local.service
● rc-local.service - /etc/rc.local
Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)
Drop-In: /usr/lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (exited) since Sun 2021-01-10 16:29:59 WIB; 3min 1s ago
Process: 14947 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
- Pengujian file rc.local
root@ns1:~# pico /etc/rc.local
#!/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.
iptables -t nat -A POSTROUTING -o ens33 -j MASQUERADE
exit 0
root@ns1:~# systemctl restart rc-local.service
root@ns1:~# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
- Selesai
- Semoga bermanfaat