티스토리 뷰

Ubuntu 20.x 이후 버전에는 rc-local 서비스가 비활성화 되어 있다.

 

1. /etc/rc.local 파일 생성

[localhost$ ] sudo nano /etc/rc.local
#!/bin/bash

iptables -A OUTPUT -p tcp --tcp-flags RST RST -j DROP
# 실행할 명령어

exit 0

[localhost$] sudo chmod +x /etc/rc.local

 

 

2. /lib/systemd/system/rc-local.service 파일 수정

[localhost$ ] sudo nano /lib/systemd/system/rc-local.service
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[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

 

3. 서비스 등록

[localhost$ ] sudo systemctl daemon-reload
[localhost$ ] sudo systemctl enable rc-local.service
[localhost$ ] sudo systemctl start rc-local.service

'Study > System' 카테고리의 다른 글

[ELK Stack] Elastic, Kibana 설치  (0) 2023.09.11
wget으로 ftp 사용하기  (0) 2023.06.30
[Linux] bash history에 Timestamp 남기기  (0) 2023.01.28
[centos7] python 설치  (0) 2023.01.26
Windows 10 cmd 창 안 열릴 때  (0) 2022.05.27
댓글