Skip to content

Instantly share code, notes, and snippets.

@hongry18
Created July 3, 2017 00:45
Show Gist options
  • Save hongry18/833fa7ec78729ceece4fa3e055b2778f to your computer and use it in GitHub Desktop.
Save hongry18/833fa7ec78729ceece4fa3e055b2778f to your computer and use it in GitHub Desktop.
CentOS Firewall

Firewall Setting

CentOS 6.x

iptables

  • chain
    • input: 들어오는 모든 패킷
    • output: 나가는 모든 패킷
    • forward: 라우터로 사용되는 패킷
  • match
    • --source, -s: 출발지
    • --destination, -d: 목적지
    • --protocol, -p: 포트
    • --in-interface, -i: 입력 인터페이스
    • --out-interface, -o: 출력 인터페이스
    • --state: 연결된 상태와의 매칭
    • --string: 애플리케이션 계층 데이터 바이트 순서와 매칭
    • --comment: 주석
    • --syn, -y: SYN패킷 허용하지 않음
    • --fragment, -f: 두번째 이후의 조각에 대해 규칙명시
    • --table, -t: 처리될 테이블
    • --jump, -j: 규칙에 맞는 패킷처리 명시
    • --match, -m: 특정 모듈과 매치
  • command
    • -A, --append: 규칙 추가
    • -D, --delete: 규칙 제거
    • -C, --check: 패킷 테스트
    • -R, --replace: 규칙 교체
    • -I, --insert: 규식 삽입
    • -L, --list: 규칙 출력
    • -F, --flush: chain으로부터 규칙을 모두 삭제
    • -Z, --zero: 초기화
    • -N, --new: chain 추가
    • -X, --delete-chain: chain 삭제
    • -P, --policy: 기본정책 변경

print lists

iptables -nL
iptables -nL --line-numbers
iptables -L -v

add accept port

iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 80:89 -j ACCEPT
iptables -A INPUT -s 192.168.0.1 -j ACCEPT
iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -s 192.168.0.0/255.255.255.0 -j ACCEPT
iptables -A INPUT -s 192.168.0.2 -m mac --mac-source 00:12:AB:CD:99:A1 -j ACCEPT

delete all policy defined in chain

iptables -F

restart iptables

service iptables restart

CentOS 7.x

firewalld

print lists

# previous defined
firewall-cmd --get-zones
# all zones
firewall-cmd --list-all-zones
# default lists
firewall-cmd --get-default-zone
# active list
firewall-cmd --get-active-zone
# service lists
firewall-cmd --get-services

add policy

# port
firewall-cmd --permanent --zone=public --add-port=80/tcp

# ip and port
firewall-cmd --permanent --zone=public --add-source=192.168.1.0/24 --add-port=22/tcp

# service
firewall-cmd --permanent --zone=public --add-service=http

remove policy

firewall-cmd --permanent --zone=public --remove-port=80/tcp

restart & check

firewall-cmd --reload
firewall-cmd --list-services --zone=public
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment