본문 바로가기

〔 SERVER 〕/↗『Linux』

[Centos]_7.x 리눅스 방화벽 설정

0. 사전작업

Centos 7.x 부터는 firewalld라는 방화벽 데몬이 따로 돌아간다. 예전처럼 iptables를 사용하고 싶다면 systemctl 설정을 변경시켜줘야 한다. 

이작업을 하기전에 firewalld 데몬을 중지 시키고 재부팅시에도 안올라오게 해주는 사전작업을 하기 바란다.

 

systemctl stop firewalld

systemctl mask firewalld

이렇게 해주면 된다.

 

1. 설치 확인

[root@localhost /]# rpm -qa |grep iptables
iptables-1.4.21-28.el7.x86_64 

 

2. 설치

[root@localhost /]# yum -y install iptables-services
Loaded plugins: fastestmirror
.................(중략)
=====================================================================================================================
 Package                           Arch                   Version                         Repository            Size
=====================================================================================================================
Installing:
 iptables-services                 x86_64                 1.4.21-33.el7                   base                  52 k

Transaction Summary
=====================================================================================================================
............ (중략)
Installed:
  iptables-services.x86_64 0:1.4.21-33.el7

Complete!

 

3. 설치 상태 체크

[root@localhost /]# systemctl list-unit-files |grep iptables
[root@localhost /]# [root@localhost /]# systemctl list-unit-files |grep iptables
iptables.service                              disabled
[root@localhost /]#

 

4. iptables 서비스 데몬을 자동으로 활성화 하게 설정

[root@localhost /]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@localhost /]#

 

5. 서비스 시작/중지

[root@localhost /]# systemctl start iptables
[root@localhost /]# systemctl stop iptables

 

중지시 

[root@localhost /]# systemctl status iptables.service
● iptables.service - IPv4 firewall with iptables
   Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Mon 2020-02-17 01:13:04 EST; 47s ago
  Process: 27864 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
  Process: 27810 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
 Main PID: 27810 (code=exited, status=0/SUCCESS)

 

활성화시

[root@localhost /]# systemctl status iptables.service
● iptables.service - IPv4 firewall with iptables
   Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
   Active: active (exited) since Mon 2020-02-17 01:14:03 EST; 4s ago
  Process: 27864 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
  Process: 27891 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
 Main PID: 27891 (code=exited, status=0/SUCCESS)

위와같이 실행하면 된다.