Simple 정리
1. 열린 포트 확인
[root@localhost home]# firewall-cmd --permanent --zone=public --list-ports
2. 포트열기
[root@localhost home]# firewall-cmd --permanent --zone=public --add-port=80/tcp
success
[root@localhost home]# firewall-cmd --permanent --zone=public --add-port=443/tcp
success
3. IP 허용
# 추가하기 (내부IP)
[root@localhost ~]# firewall-cmd --permanent --add-source=192.168.0.0/24
# 제거하기
[root@localhost ~]# firewall-cmd --permanent --remove-source=192.168.0.0/24
4. reload
[root@localhost home]# firewall-cmd --reload
success
/usr/lib/firewalld/zones
/usr/lib/firewalld/services
GUI 환경에서는 firewall-config, CUI 환경에서는 firewall-cmd 사용
( 구글 클라우드 사용 CUI모드)
구글 클라우드 Centos8을 설정하고 nginx를 깔고 접속해 보니 바로 접속이 된다.
이상해서 방화벽 설정을 보니
[root@instance-1 services]# firewall-cmd --list-all
trusted
target: ACCEPT
icmp-block-inversion: no
interfaces:
sources:
services:
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
zone 이 trusted 로 설정되어 있어 모든 패킷이 허용되는 상황이다.
zone을 public로 바꾸면 SSH 외의 패킷은 거부한다. 빨리 바꾸자.
[root@instance-1 services]# firewall-cmd --set-default-zone=public
success
그리고 사용할 서비스들을 열어주고 reload 한다.
[root@instance-1 services]# firewall-cmd --permanent --add-service=http --add-service=https
success
[root@instance-1 services]# firewall-cmd --reload
success
permanent 옵션을 줘야 리부팅 되도 설정이 살아있다.
** 참고로 기본적으로 정의된 zone 가 서비스 포트는 아래 폴더에 있다.
/usr/lib/firewalld/zones
/usr/lib/firewalld/services
포트 오픈 테스트: 다른 리눅스 서버에서 nmap으로 테스트 할 수 있다.
[root@si ~]# nmap 35.224.***.*** -p 80,443,22,25
Starting Nmap 5.51 ( http://nmap.org ) at 2020-07-17 15:00 KST
Nmap scan report for 58.33.224.35.bc.googleusercontent.com (35.224.33.58)
Host is up (0.18s latency).
PORT STATE SERVICE
22/tcp open ssh
25/tcp filtered smtp
80/tcp open http
443/tcp closed https
Nmap done: 1 IP address (1 host up) scanned in 2.27 seconds
open: 방화벽이 열려 있다.
filtered: 방화벽에 막혀 있다.
closed: 방화벽은 열려 있으나 다른 이유에 의해 막혀 있다.
'Linux' 카테고리의 다른 글
CentOS 8 에 Nginx, MariaDB 10, PHP 7 , Wordpress 설치 (0) | 2020.07.28 |
---|---|
CentOS8 Nginx SSL 인증서 적용하기 (0) | 2020.07.21 |
CentOS 8 에 Visual Studio Code (vs code) 설치 (0) | 2020.03.10 |
Centos8 APM 설치 (0) | 2020.03.09 |
Centos7 하드디스크 추가하기 (0) | 2020.03.06 |