리눅스 서버 방화벽 포트 허용 방법 / firewall-cmd 명령어 사용

방화벽 포트 허용 방법

firewall-cmd --permanent --zone=public --add-port=포트/tcp
firewall-cmd --permanent --zone=public --add-service=elasticsearch
firewall-cmd --reload
firewall-cmd --list-ports

위 명령어를 순차적으로 실행하면 서버로 들어오는 요청(인바운드) 포트에 대한 방화벽이 허용됩니다.

firewall-cmd 명령어 실행 시 에러

irewall-cmd: command not found

firewalld 설치 및 실행 후 다시 시도하면 됩니다.


yum으로 firewalld 설치 및 실행

yum install firewalld
systemctl unmask firewalld
systemctl enable firewalld
systemctl start firewalld

위 명령어를 순차적으로 실행하면 firewalld 설치 및 실행이 완료됩니다.

root 계정이 아닌 경우 firewalld 설치 시 에러

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
You need to be root to perform this command.

root 계정으로 다시 시도합니다.

firewalld 실행 여부 확인

firewall-cmd --state

running이라고 나오면 firewalld가 실행 중인 것입니다.
firewalld 실행 중에는 대부분의 포트가 막혀서 허용하지 않은 포트는 서버에 접근할 수 없습니다.


firewalld 종료

sudo systemctl stop firewalld

Leave a comment