firewalld 기반의 접근제어 사용하기

환경

OS : CentOS-7

전통적인 iptables 를 기반으로 하지만..
firewalld 라는 패키지로 관리함…
그냥 iptables 를 사용하던가.. firewall-cmd 를 사용하던가.. 편한대로 사용하면 됨

 

설정파일

설정 경로 : /etc/firewalld

firewall-cmd를 이용해서 일반적인 설정을 하게 되면
/etc/firewalld/zones/public.xml 에 저장됨…

설치후 별다른 추가 설정을 하지 않았다면

firewall-cmd –get-default-zone

명령어를 실행 한 결과는 ”public”으로 출력될 것이다.

 

기본 사용법

환경 : 터미널 기반
명령어 : firewall-cmd

 

조건 : 20,22,80포트(TCP)를 허용

룰 추가


firewall-cmd --add-port=21/tcp
firewall-cmd --add-port=22/tcp
firewall-cmd --add-port=80/tcp

룰 삭제


firewall-cmd --remove-port=21/tcp
firewall-cmd --remove-port=22/tcp
firewall-cmd --remove-port=80/tcp

 

조건 : 8000 ~ 9000 까지의 포트(TCP)를 허용


firewall-cmd --add-port=8000-9000/tcp
firewall-cmd --remove-port=8000-9000/tcp

 

조건 : 192.168.0.0/255.255.255.0 대역을 허용


firewall-cmd --add-source=192.168.0.0/24
firewall-cmd --remove-source=192.168.0.0/24

 

조건 : 192.168.3.100 아이피를 허용


firewall-cmd --add-source=192.168.3.100
firewall-cmd --remove-source=192.168.3.100

 

조건 : 192.168.5.100 아이피를 차단


firewall-cmd --add-rich-rule='rule family="ipv4" source address=192.168.5.100 reject'
firewall-cmd --remove-rich-rule='rule family="ipv4" source address=192.168.5.100 reject'

firewall-cmd --add-rich-rule='rule family="ipv4" source address=192.168.5.100 drop'
firewall-cmd --remove-rich-rule='rule family="ipv4" source address=192.168.5.100 drop'

두개의 구문은 동일한듯 보이지만.. 약간의 차이가 있다.

  • reject : 차단을 하긴 하되… ”너 차단 되었어” 라는 응답을 해준다.
  • drop : 그냥 차단….

실제로 사용시에는 drop 을 사용하면 되겠다…

 

조건 : 192.168.10.170 아이피에 대해 80번 포트를 허용


firewall-cmd --add-rich-rule='rule family="ipv4" source address=192.168.10.170 port port="80" protocol="tcp" accept'
firewall-cmd --remove-rich-rule='rule family="ipv4" source address=192.168.10.170 port port="80" protocol="tcp" accept'

 

하지만.. 본 내용은… running 상태에서만 유효할 뿐..
서비스를 죽이거나 리부팅을 했을 경우에는 설정이 모두 날아감..

실제로 public.xml 파일을 확인해도 설정했던 내용들을 찾을 수 없다.

 

설정파일에 적용 하기

firewall-cmd –permanent
형태로 옵션을 줘야 한다.


firewall-cmd --permanent --add-port=21/tcp
firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=8000-9000/tcp
firewall-cmd --permanent --add-source=192.168.0.0/24
firewall-cmd --permanent --add-source=192.168.3.100
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address=192.168.5.100 reject'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address=192.168.5.100 drop'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address=192.168.10.170 port port="80" protocol="tcp" accept'

그리고 나서

firewall-cmd –reload

명령을 이용해 설정파일의 내용을 반영….

 

터미널에서 상태 확인


# firewall-cmd --list-all
public (default)
interfaces:
sources: 192.168.3.100 192.168.0.0/24
services: dhcpv6-client ssh
ports: 21/tcp 80/tcp 8000-9000/tcp 22/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
rule family="ipv4" source address="192.168.5.100" reject
rule family="ipv4" source address="192.168.5.100" drop
rule family="ipv4" source address="192.168.10.170" port port="80" protocol="tcp" accept

 

public.xml 내용


<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description></description>
<source address="192.168.0.0/24"/>
<source address="192.168.3.100"/>
<service name="dhcpv6-client"/>
<service name="ssh"/>
<port protocol="tcp" port="21"/>
<port protocol="tcp" port="80"/>
<port protocol="tcp" port="8000-9000"/>
<port protocol="tcp" port="22"/>
<rule family="ipv4">
<source address="192.168.5.100"/>
<reject/>
</rule>
<rule family="ipv4">
<source address="192.168.5.100"/>
<drop/>
</rule>
<rule family="ipv4">
<source address="192.168.10.170"/>
<port protocol="tcp" port="80"/>
<accept/>
</rule>
</zone>

About KENNETH 19688 Articles
지락문화예술공작단

1 Trackback / Pingback

  1. NAS DIY : 보안 | begns

Leave a Reply

Your email address will not be published.


*


이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.