4,852 瀏覽數

RHEL 7 (Systemd) – 防火牆

Red Hat Enterprise Linux 7 防火牆 Firewall 預設是開啟的 (可以透過 #iptables -L 指令觀察),但要怎麼關閉它呢!!

首先 RHEL7 已經改用 systemd 的開機方式.以前的指令 #service , /etc/init.d/ , #chkconfig 的方式都不適用了.必須用 #systemctl 指令,關於 #systemctl 請自行參考,而且 Firewall 服務名稱不叫做 iptables 改成為 firewalld .

  • FireWall Status
    [root@localhost ~]# systemctl status firewalld
    firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
       Active: active (running) since Wed 2016-03-16 06:02:23 EDT; 15min ago
     Main PID: 550 (firewalld)
       CGroup: /system.slice/firewalld.service
               └─550 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
    
    Mar 16 06:02:19 localhost.localdomain systemd[1]: Starting firewalld - dynami...
    Mar 16 06:02:23 localhost.localdomain systemd[1]: Started firewalld - dynamic...
    Hint: Some lines were ellipsized, use -l to show in full.
    
  • Stop and Start firewall
    還是可以用 service 這個指令,不過系統會自動導向成 systemctl 指令來做,systemctl 透過 start , stop 來立即性的開啟與關閉防火牆的功能.

    [root@localhost ~]# service firewalld stop
    Redirecting to /bin/systemctl stop  firewalld.service
    [root@localhost ~]# /bin/systemctl stop firewalld.service
    
    [root@localhost ~]# service firewalld start
    Redirecting to /bin/systemctl start  firewalld.service
    [root@localhost ~]# /bin/systemctl start firewalld.service
    
  • Disable and Enable firewall
    systemctl 透過 enable , disable 就是像以前透過 chkconfig iptables on , off 一樣,設定開機的時候是不是要把服務啟動.

    [root@localhost ~]# systemctl disable firewalld
    rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
    rm '/etc/systemd/system/basic.target.wants/firewalld.service'
    
    [root@localhost ~]# systemctl enable firewalld
    ln -s '/usr/lib/systemd/system/firewalld.service' '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
    ln -s '/usr/lib/systemd/system/firewalld.service' '/etc/systemd/system/basic.target.wants/firewalld.service'
    

發表迴響