본문 바로가기
컴퓨터 활용(한글, 오피스 등)/50_2.운영체제_리눅스

Linux CentOS 방화벽(firewalld) 확인하기, 추가하기, 삭제하기

by 3604 2023. 11. 28.
728x90

출처: [Linux CentOS - (22) ] 방화벽(firewalld) 확인하기, 추가하기, 삭제하기 (tistory.com)

 

firewalld 방화벽은 centos 7버전부터 적용이 된다. 그 이전 버전은 iptables로 관리되어 왔었다.



특정 port로 방화벽 해제하기

80, 81, 82번 포트에 대해서….

추가(해제) 하기
firewall-cmd --permanent --add-port=80/tcp 또는 /udp
firewall-cmd --permanent --add-port=81/tcp 
firewall-cmd --permanent --add-port=82/tcp

제거 하기
firewall-cmd --permanent --add-remove=80/tcp 
firewall-cmd --permanent --add-remove=81/tcp 
firewall-cmd --permanent --add-remove=82/tcp


변경된 firewall 구성을 적용하기

해당 firewall을 설정했으면 반드시 리로딩을 해주어야 반영이 됩니다.

firewall-cmd --reload


방화벽 상태 확인하기

firewall-cmd --state
현재 실행 중이면 running, 실행 중이 아니면 not running을 출력.

 

방화벽 내리기 : systemctl stop firewalld


시스템(CentOS) firewall 설치

보통 리눅스도 기본적으로 Firewall은 설치가 되서 나오기는 하지만 간혹 설치가 되어있지 않은 경우도 있습니다. 이렇때 firewall을 설치하는 방법입니다.

yum을 이용하여 firewall을 설치 합니다.
yum install firewalld

매번 서버 부팅/재부팅 시 자동으로 firewall 데몬(firewalld)이 실행되게 합니다.
systemctl enable firewalld
systemctl start firewalld
  firewall을 설치하고 실행하면 기본적으로 모든 들어오고 나가는 것에 대해 막습니다. 그래서 설치 후에 내가 원하는 서비스나 port는 통과될 수 있게 열어줘야 합니다. 물론 모두 개방해놓고 원하는 것만 막을 수도 있긴한데 그것은 firewall의 취지와 역행하는 것이라 추천하지 않습니다.


서비스로 방화벽 해제 하기

일단 방화벽이 다 막고 있다는 가정하에 원하는 서비스에 대해 해제하는 방법입니다.

http, https 서비스에 대해서….

추가(해제) 하기
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https

제거 하기
firewall-cmd --permanent --remove-service=http
firewall-cmd --permanent --remove-service=https

firewall-cmd : firewall cli명령어
--permanent : 영구적으로 실행해라 (default zone에 등록됩니다.)
--add-service : 해당 서비스를 추가해라
--remove-service : 해당 서비스를 삭제해라


port 구간으로 방화벽 해제하기

6000 ~ 9000번 포트에 대해서….

추가(헤제) 하기
firewall-cmd --permanent --add-port=6000-9000/tcp

제거 하기
firewall-cmd --permanent --remove-port=6000-9000/tcp


특정 IP에 대해 방화벽 해제하기

특정 IP에 대해서 해당 서버에 접근하는 것을 허용하는 방법입니다.
192.168.0.100에 대해서….

추가(접근허용) 하기
firewall-cmd --permanent --add-source=192.168.0.100

 

제거 하기
firewall-cmd --permanent --remove-source=192.168.0.100


IP대역에 대해 방화벽 해제하기

특정 IP대역에 대해서 해당 서버에 접근하는 것을 허용하는 방법입니다.
192.168.0.0/255.255.255.0에 대해서….

추가(접근 허용) 하기
firewall-cmd --permanent --add-source=192.168.0.0/24

제거 하기
firewall-cmd --permanent --remove-source=192.168.0.0/24


특정 IP에 대해 접근 못하게 하기

이번에는 특정 IP에 대해서 해당 서버에 접근하지 못하게하는 방법입니다.
192.168.0.100에 대해서….

추가(접근 불가) 하기
#--> 피드백 보내줌
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address=192.168.0.100 reject'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address=192.168.0.100 drop'
#--> 피드백 없음

 

제거 하기
#--> 피드백 보내줌
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address=192.168.0.100 reject ' 
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address=192.168.0.100 drop'
#--> 피드백 없음


특정 IP에 대해 특정 Port에 접근하게 하기

이번에는 특정 IP에 대해서 특정 Port에만 접근하게 하는 방법입니다.
192.168.0.100가 8000포트에 대해서 접근을….

추가(접근 허용) 하기
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address=192.168.0.100 port port="8000" protocol="tcp" accept'

제거 하기
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address=192.168.0.100 port port="8000" protocol="tcp" accept'


IP대역에 대해 특정 Port에 접근하게 하기

이번에는 IP대역에 대해서 특정 Port에만 접근하게 하는 방법입니다.
192.168.0.0/255.255.255.0가 8000포트에 대해서 접근을….

추가(접근 허용) 하기
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address=192.168.0.0/24 port port="8000" protocol="tcp" accept'

 

제거 하기
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address=192.168.0.0/24 port port="8000" protocol="tcp" accept'


현재 방화벽 리스트 보기

이제 현재 등록되어 있는 방화벽 리스트를 보고 원하는데로 등록이 되었는지 확인합니다.

firewall-cmd --list-all

 
728x90