Centos 7 방화벽 설정

[firewalld 데몬]

1
sudo yum install firewalld
cs
-> 방화벽 설치

1
sudo systemctl start/stop/restart firewalld
cs
를 사용해서 데몬을 키거나 끌 수 있다.

chkconfig가 CentOS 7버전부터는 사라졌기 때문에,
부팅시 자동 시작이 필요하면 systemctl enable을 사용한다.

1
sudo firewall-cmd --state
cs
-> 방화벽이 작동중인지 아닌지를 체크한다


[포트 단위 허가]

1
2
sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
sudo firewall-cmd --permanent --zone=public --remove-port=80/tcp
cs

> 포트와 TCP/UDP 수정


[서비스 단위 허가]

1
2
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --remove-service=http
cs

> 프로토콜 수정


[IP 단위 허가]

1
2
sudo firewall-cmd --permanent --zone=public --add-source=192.168.0.0/16
sudo firewall-cmd --permanent --zone=public --remove-source=192.168.0.0/16
cs

> CIDR 수정

* IP단위, 서비스 단위, 포트 단위는 조합해서 쓸 수 있다.
ex) --add-source=192.168.0.0/16 --add-service=http


[XML 파일 위치]

위치 : /etc/firewalld/zones/[Zone].xml
기본값 : /etc/firewalld/zones/public.xml

Zone은 /etc/firewalld/firewalld.conf 에서 체크
기본 Zone은 public

위에서 친 firewall-cmd 명령들은 xml 파일에 반영된다.


만약 수동으로 xml 파일을 조작할 경우,

데몬 재부팅 혹은
1
sudo firewall-cmd --reload
cs
을 사용한다.

댓글