CentOS7使用httpd apache 和firewalld打開關閉防火牆與端口


Centos7 使用systemctl 工具操作命令

 

systemctl 是Centos7的服務管理工具中的主要工具 ,它融合之前service和chkconfig的功能於一體

 

一、httpd的設置

第一 、 httpd 服務的啟動 停止 重啟

啟動 : systemctl start httpd.service 

停止:    systemctl stop httpd.service 

重啟:     systemctl restart httpd.service

 

查看httpd 的狀態

systemctl status httpd.service

 

第二、將httpd 服務設置開機啟動

設置為開機啟動 :  systemctl enable httpd.service

設置開機不啟動:   systemctl disable httpd.service 

 

二、防火牆設置

firewalld 打開關閉防火牆端口

    1.啟動:  systemctl start firewalld

    2.查看狀態: systemctl status firewalld

    3.停止: systemctl stop firewalld

    4.禁用:systemctl disable firewalld

 

使用systemctl命令

啟動一個服務:     systemctl start firewalld.service 

停止一個服務:     systemctl stop firewalld.service

重啟一個服務:    systemctl restart firewalld.service 

查看一個服務的狀態 :    systemctl status firewalld.service

在開機時啟動一個服務:    systemctl enable firewalld.service 

在開機時禁用一個服務:    systemctl disable firewalld.service

查看已經啟動的服務列表法:  systemctl list-unit-files|grep enabled

查看啟動失敗的服務: systemctl --failed

 

 

配置  firewall-cmd 

查看版本:firewall-cmd --version

查看幫助:  firewall-cmd --help

查看狀態:  firewall-cmd --state

查看所有打開的端口:  firewall-cmd --zone=public --list-ports

更新防火牆規則: firewall-cmd --reload

查看區域信息: firewall-cmd --get-active-zones

查看指定接口所屬區域: firewall-cmd --get-zone-of-interface=eth0
拒絕所有包:firewall-cmd --panic-on
取消拒絕狀態: firewall-cmd --panic-off
查看是否拒絕: firewall-cmd --query-panic

 

開啟一個端口

firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent 這個參數是永久生效,如果不設置這個參數,默認重啟后就失效)

重新載入,使設置剩下

firewall-cmd --reload

查看

firewall-cmd --zone=public --query-port=80/tcp

刪除

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM