firewalld concept and configuration

35
Enterprise Linkx 7 New Feature RHEL , OEL , CentOS , Fedora Suk Kim , Oracle ACE Director Nobreak Senior managed Consultant

Upload: suk-kim

Post on 18-Jul-2015

2.290 views

Category:

Engineering


6 download

TRANSCRIPT

Page 1: firewalld concept and configuration

Enterprise Linkx 7 New FeatureRHEL , OEL , CentOS , Fedora

Suk Kim , Oracle ACE Director

Nobreak Senior managed Consultant

Page 2: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

v작성자 : 김재벌 ( 김석 )

v버전 : 1.0

vcontact : [email protected] , http://blog.solaris.co.kr

v본 문서의 저작권은 저작자에게 있습니다.

v본 문서의 상업적 이용은 금하며, 일부의 복사, 전제, 임의 수정 등은 금합니다.

v본 문서를 개인 학습용으로만 사용이 가능합니다.

Page 3: firewalld concept and configuration

목차

v방화벽 구성과 관리vfirewalld 필요성v방화벽 스택vzone , service , icmptypes , runtime , permanet , directvpre-defined zonevpre-defined servicevfireall 구성 설정

v firewall-configv firewall-cmd

v런타임vpermanetvdirect

Page 4: firewalld concept and configuration

방화벽 관리 및 구성

Page 5: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewalld 의 필요성

v기존 iptables의 한계v룰 변경시 서비스 중지 및 설정 변경v오픈스택이나 KVM과 같은 가상화 호스트에서는 네트워크 변

화가 수시로 발생되므로 필터링 정책에 변경이 필요v응용프로그램 자체에서 필터링 정책을 구성하는 경우 iptables

정책과 충돌되는 등의 문제 야기

vfirewalld가 필요한 이유?vKVM , openstack 과 같은 가상화, 클라우드 환경하에서의 필

터링 정책 동적 추가 가능vDBUS API를 통한 정보 공유를 통해 정책 충돌 문제 해결

v 노트DBUS란? 어플리케이션간의 통신을 지원하는 인터페이스

Page 6: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

방화벽 스택 ( Firewall Stack )

system-config-firewall

iptables(service)

firewalld (daemon & service)

iptables(command)

커널(netfilter)

firewall-config firewall-cmd

Page 7: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

핵심 개념vDBUS 인터페이스

v어플리케이션간의 통신을 지원하는 인터페이스

vZONEv네트워크 및 방화벽 연결에 사용되는 인터페이스v신뢰도 정의vfirewalld.zone (5) man 참조

vServicev로컬 포트 및 대상 목록과 서비스 유효시 자동으로 로드v사전 정의된 서비스를 활성화/비활성화 가능vfirewalld.service(5) man 참조

vICMP 타입vICMP 정보와 IP 오류 메시지 교환에 사용vfirewalld 에서 제한적으로 사용vfirewalld.icmptype(5) man 참조

Page 8: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

핵심 개념v런 타임(run time) 설정

v영구적이지 않음 , 재로드시만 유지v서비스 재시작, 재부팅시 제거됨.

v영구(permanent) 설정v설정 파일에 저장v시스템 재시작, 재부팅시에도 유지

v다이렉트(direct) 설정v서비스와 응용프로그램에 룰 추가시 사용v영구적이지 않음.v실행 또는 재시작시 firewalld 에서 DBUS로 통지된 후 적용.

vetables 지원vlibvirt 데몬 요청 처리vnetfilter의 iptables 와 etables 문제 해결을 위해 존재v동시 적용되는 경우는 존재 하지 않음.

Page 9: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewalld pre-defined zone 종류

vReject Vs. Drop 차이 ??vman -s 5 firewalld.zone

Page 10: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewalld pre-defined zone 종류영역(Zone) 설명

block (변경 불가) 모든 패킷을 거부(reject)하고 있지만, 내부에서 외부로의 반환 패킷은 허용

dmz 내부로 들어오는 패킷은 거부(reject) , 외부로의 연결, ssh 같은 사전 정의된 서비스는 허용

drop (변경 불가) 내부로 들어오는 모든 패킷 폐기(drop). 외부로의 연결만 허용(심지어 ICMP 에러 도 폐기)

external 내부로 들어오는 패킷 거부(reject), 외부로의 연결과 사전 정의된 "ssh"에만 허용 , IP 마스커레이딩 활성화

home 내부로 들어오는 패킷은 거부(reject) , 기본적으로 "dhcpv6-client", "ipp-client", "mdns", "samba-client", "ssh" 허용

internal 내부로 들어오는 패킷은 거부(reject) , 기본적으로 "dhcpv6-client", "ipp-client", "mdns", "samba-client", "ssh"가 허용 (시작시 home 과 동일)

public 기본 영역. 새롭게 추가된 네트워크 인터페이스의 기본 Zone(영역)으로 사용내부로 들어오는 패킷은 거부(reject) , "ssh"와 "dhcpv6-client"에만 허용

trusted (변경 불가) 모든 패킷 허용

work 내부로 들어오는 패킷은 거부(reject) ,기본적으로 "dhcpv6-client", "ipp-client", "ssh" 허용

Page 11: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewalld pre-defined service

서비스 이름 설명

ssh 로컬 ssh 서버 , 22/tcp

dhcpv6-client 로컬 dhcpv6 클라이언트 , fe80::/64 ipv6 네트워크에서 546/udp

ipp-client 로컬 IPP 프린트 , 631/tcp

samba-client 로컬 윈도우 파일과 프린트 공유 클라이언트 , 137/udp , 138/u에

mdns 멀티캐스트 DNS ( mDNS) 로컬 링크 이름 풀이.224.0.0.251 (ipv4) 또는 ff02:fb (ipv6) 멀티캐스트 , 5353/udp

v 노트

# firewall-cmd --get-services 명령으로 서비스 목록 확인 가능/usr/lib/firewalld/services 디렉토리에 서비스 구성 파일 정의매뉴얼페이지 firewalld.zone(5) 참고

Page 12: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall 구성 설정

v/etc/firewalld 내의 파일을 직접 수정

vfirewall-config 도구 (GUI) 사용

v구성 후 반드시 firewalld 서비스를 재시작 또는 재로드 해야만반영됨.

vfirewall-cmd 명령 사용

Page 13: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

방화벽 설정 ( firewall-config : GUI )

[root@el7 ~]# firewall-config

Page 14: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (상태확인)

firewalld 상태 확인

[root@el7 ~]# firewall-cmd --state

firewalld 패키지 버전 확인

[root@el7 ~]# rpm -qf $( which firewall-cmd )state

firewalld reload ( 상태 정보 손실 없이 다시 로딩 )--complete-reload 사용시 상태 정보 손실 ( 장애 조치 및 문제 해결시 사용)

[root@el7 ~]# rpm -qf $( which firewall-cmd )state

v 노트

--complete-reload 사용시 상태 정보 손실 되며 심각한 방화벽 문제시에만적용.

Page 15: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (목록확인)

지원 가능한 영역(zone) 목록

[root@el7 ~]# firewall-cmd --get-zones

지원 가능한 ICMP type 목록

[root@el7 /]# firewall-cmd --get-icmptypes

지원 가능한 서비스 목록

[root@el7 /]# firewall-cmd --get-services

Page 16: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (목록확인)

지원 가능한 영역(zone) 목록 (공백으로 구분)

[root@el7 /]# firewall-cmd --list-all-zones

영역별로 인터페이스,서비스,포트,포트포워드 등 정보출력됨.

Page 17: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (목록확인)

영역의 기능 출력 (생략시 기본 영역 출력)

[root@el7 /]# firewall-cmd --list-all

DMZ 영역 기능 출력

[root@el7 /]# firewall-cmd --zone=dmz --list-all

Page 18: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (목록확인)

영역의 기능 출력 (생략시 기본 영역 출력)

[root@el7 /]# firewall-cmd --get-default-zone

기본 영역 변경 (여기서는 home 영역으로 변경)

[root@el7 /]# firewall-cmd --set-default-zone=home

활성화 된 영역 출력

[root@el7 /]# firewall-cmd --get-active-zone

Page 19: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (구성)

인터페이스의 영역 정보

[root@el7 /]# firewall-cmd --get-zone-of-interface=eth0public

인터페이스 영역에 추가 (영역 생략시 기본 영역 , 재로드 후 적용됨.)

[root@el7 /]# firewall-cmd [--zone=<zone>] --add-interface=<interface>

인터페이스 영역에 변경

[root@el7 /]# firewall-cmd [--zone=<zone>] --change-interface=<interface>

v 노트

--add-interface 옵션과 유사 하지만 이전에 다른 영역에 위치한 경우 새 영역으로 추가

Page 20: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (구성)

영역에서 인터페이스 제거

[root@el7 /]# firewall-cmd [--zone=<zone>] --remove-interface=<interface>

영역에 인터페이스 존재 유무 질의

[root@el7 /]# firewall-cmd [--zone=<zone>] --query-interface=<interface>

인터페이스 영역에 변경 ( [--zone=<zone>] 생략시 기본영역 )

[root@el7 /]# firewall-cmd --list-services dhcpv6-client ssh

패닉모드 활성화 ( 긴급하게 트래픽 차단시)

[root@el7 /]# firewall-cmd --enable-panic

패닉모드 비활성화

[root@el7 /]# firewall-cmd --disable-panic

패닉모드 확인(질의)

[root@el7 /]# firewall-cmd --query-panic

Page 21: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (런타임 영역 핸들링)

영역에서 서비스 활성화

[root@el7 /]# firewall-cmd [--zone=<zone>] --add-service=<service> [--timeout=<seconds>]

IPP 클라이언트 서비스 활성화 ( 60초 , home 영역에 적용)

[root@el7 /]# firewall-cmd --zone=home --add-service=ipp-client --timeout=60

v 노트

서비스 활성시 영역 미지정시에 기본영역에 적용되며 , 시간을 설정하는 경우 해당 시간에만 활성화 되며 , 이미 활성화되어 서비스 중인 경우는 경고메시지 없음.

v런타임 핸들링은 영구적인 것이 아님.

v재시작 또는 재로드시까지 만 유지.

Page 22: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (런타임 영역 핸들링)

기본영역에 http 서비스 활성화

[root@el7 /]# firewall-cmd --add-service=http

영역에서 서비스 비활성화

[root@el7 /]# firewall-cmd [--zone=<zone>] --remove-service=<service> [--timeout=<seconds>]

home 영역에 http 서비스 비활성화 (유효한서비스:1 , 없으면 0 을 출력)

[root@el7 /]# firewall-cmd [--zone=<zone>] --query-service=<service>

Page 23: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (런타임 영역 핸들링)

영역에서 포트 및 프로토콜 구성 (포트는 범위 입력 가능)

[root@el7 /]# firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]

영역에서 포트 및 프로토콜 제거

[root@el7 /]# firewall-cmd [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>

영역에서 포트 및 프로토콜 구성 확인 (질의)

[root@el7 /]# firewall-cmd [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

Page 24: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (런타임 영역 핸들링) 영역에서의 마스커레이딩 활성화

[root@el7 /]# firewall-cmd [--zone=<zone>] --add-masquerade

영역에서의 마스커레이딩 비활성화

[root@el7 /]# firewall-cmd [--zone=<zone>] --remove-masquerade

영역에서의 마스커레이딩 확인 (질의)

[root@el7 /]# firewall-cmd [--zone=<zone>] --query-masquerade

영역에서의 ICMP 차단 활성화

[root@el7 /]# firewall-cmd [--zone=<zone>] --add-icmp-block=<icmptype>

영역에서의 ICMP 차단 비활성화

[root@el7 /]# firewall-cmd [--zone=<zone>] --remove-icmp-block=<icmptype>

영역에서의 ICMP 차단 비활성화

[root@el7 /]# firewall-cmd [--zone=<zone>] --query-icmp-block=<icmptype>

Page 25: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (런타임 영역 핸들링) echo-reply 메시지를 public 영역에서 차단

[root@el7 /]# firewall-cmd --zone=public --add-icmp-block=echo-reply

영역에서 포트포워드 (포트매핑) 활성화

[root@el7 /]# firewall-cmd [--zone=<zone>] --add-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

영역에서 포트포워드 (포트매핑) 비활성화

[root@el7 /]# firewall-cmd [--zone=<zone>] --remove-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

영역에서 포트포워드 (포트매핑) 활성 유무 확인 (질의)

[root@el7 /]# firewall-cmd [--zone=<zone>] --query-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

v 노트포트포워딩은 커널제한으로 ipv4 만 가능

Page 26: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (런타임 영역 핸들링)

예제) home 영역에서 127.0.0.2 로 ssh 포워딩

[root@el7 /]# firewall-cmd --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2

-- 이하 여백 --

Page 27: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (permanent)

vpermanent 옵션v구동 일때 직접적인 영향 없음v재부팅 또는 --permanent 옵션 사용시 적용v구동, permanent 동시 적용시 모두 적용v--permanent 옵션은 모든 인수 앞에 존재해야 함.

permanet 서비스 목록

[root@el7 /]# firewall-cmd --permanent --get-services

permanet icmp 타입 목록

[root@el7 /]# firewall-cmd --permanent --get-icmptypes

permanet zone 목록

[root@el7 /]# firewall-cmd --permanent --get-zones

Page 28: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (permanent)

zone 내의 서비스를 추가

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --add-service=<service>

zone 내의 서비스를 제거

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --remove-service=<service>

zone 내의 서비스를 조회

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --query-service=<service>

예) home 영역에서 ipp-client 서비스를 영구적(permant) 하게 활성화

[root@el7 /]# firewall-cmd --permanent --zone=home --add-service=ipp-client

Page 29: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (permanent)

포트/프로토콜 조합 구성 영구적으로 활성화

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --add-port=<port>[-<port>]/<protocol>

포트/프로토콜 조합 구성 영구적으로 비활성화

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>

영구적으로 사용 가능한 목록 조회

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

예) home 영역에서 https (443/tcp) 영구적(permant) 활성화

[root@el7 /]# firewall-cmd --permanent --zone=home --add-port=443/tcp

Page 30: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (permanent)

영역에서 마스커레이딩 영구적(permant) 비활성화

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --remove-masquerade

영역에서 마스커레이딩 영구적(permant) 활성화

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --add-masquerade

영역에서 영구적(permant) 마스커레이딩 조회

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --query-masquerade

Page 31: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (permanent)

영역에서 icmp 차단 - 영구적(permant) 비활성화

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --remove-icmp-block=<icmptype>

영역에서 icmp 차단 - 영구적(permant) 활성화

[root@el7 /]#firewall-cmd --permanent [--zone=<zone>] --add-icmp-block=<icmptype>

영역에서 icmp 차단 - 영구적(permant) 조회

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --query-icmp-block=<icmptype>

public 영역에서 icmp echo-reply 영구 차단

[root@el7 /]# firewall-cmd --permanent --zone=public --add-icmp-block=echo-reply

Page 32: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (permanent)

영역에서 영구 포트포워드 (포트매핑) 비활성화

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --remove-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

영역에서 영구 포트포워드 (포트매핑) 활성화

[root@el7 /]#firewall-cmd --permanent [--zone=<zone>] --add-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

영역에서 영구 포트포워드 (포트매핑) 활성화 여부 조회

[root@el7 /]# firewall-cmd --permanent [--zone=<zone>] --query-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

예제) home 영역에서 영구적으로 127.0.0.2 로 ssh 포워딩

[root@el7 /]# firewall-cmd --permanent --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2

Page 33: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (direct)

명령을 방화벽으로 전달 ( args : iptables , ip6tables , etables 사용 가능)

[root@el7 /]# firewall-cmd --direct --passthrough { ipv4 | ipv6 | eb } <args>

vdirect 옵션v서비스나 응용프로그램에 적용v사용자 정의 규칙 추가v룰은 저장되지 않고 , 재로드, 재시작 시 재입력해야 함v--direct 옵션은 모든 인수 앞에 존재해야 함.

테이블에 체인 추가

[root@el7 /]# firewall-cmd [--permanent] --direct --add-chain { ipv4 | ipv6 | eb } <table> <chain>

테이블에서 체인 제거

[root@el7 /]# firewall-cmd [--permanent] --direct --remove-chain { ipv4 | ipv6 | eb } <table> <chain>

Page 34: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (direct)

테이블에 체인 존재 유무 질의 ( true : 0 , false : 1 출력 )

[root@el7 /]# firewall-cmd [--permanent] --direct --query-chain { ipv4 | ipv6 | eb } <table> <chain>

테이블에 추가된 모든 체인을 출력 ( 공백 구분 )

[root@el7 /]# firewall-cmd [--permanent] --direct --get-chains { ipv4 | ipv6 | eb } <table>

테이블 체인에서 args 와 룰을 제거

[root@el7 /]# firewall-cmd [--permanent] --direct --remove-rule { ipv4 | ipv6 | eb } <table> <chain> <args>

테이블에 체인 우선순위 <priority>로 <args> 와 함께 룰 추가

[root@el7 /]# firewall-cmd [--permanent] --direct --add-rule { ipv4 | ipv6 | eb } <table> <chain> <priority> <args>

Page 35: firewalld concept and configuration

Copyright © 2015 All Rights Reserved Noreak Co.,LTD. Reproduction is strictly PROHIBITED

firewall-cmd 사용 (direct)

테이블에 체인에 <args>를 가지는 룰 유무 질의 ( true: 0 , false: 1 )

[root@el7 /]# firewall-cmd [--permanent] --direct --query-rule { ipv4 | ipv6 | eb } <table> <chain> <args>

테이블의 체인에 추가 된 모든 체인을 변경으로 구분 출력

[root@el7 /]# firewall-cmd [--permanent] --direct --get-rules { ipv4 | ipv6 | eb } <table> <chain>