centos7防火牆配置以及緩存清空

一.centos7使用firewalld

1、firewalld的基本使用

啓動: systemctl start firewalld

關閉: systemctl stop firewalld

查看狀態: systemctl status firewalld 

開機禁用  : systemctl disable firewalld

開機啓用  : systemctl enable firewalld

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

啓動一個服務: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 is-enabled firewalld.service

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

查看啓動失敗的服務列表:systemctl --failed

3.配置firewalld-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



4 .那怎麼開啓一個端口呢?

添加
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

二.centos6使用iptables

查看哪些端口開放
vi /etc/sysconfig/iptables

service iptables status    #查看iptables狀態
service iptables restart   #iptables服務重啓
service iptables stop      #iptables服務禁用

三.查看監聽端口

netstat -lntp #查看監聽(Listen)的端口
netstat -antp #查看所有建立的TCP連接
iptables -L #查看防火牆規則

四、清理內存緩存

1、清理頁緩存:

  echo 1 > /proc/sys/vm/drop_caches

  2、清理目錄項緩存與文件結點緩存:

  echo 2 > /proc/sys/vm/drop_caches

  3、清理頁緩存、目錄項緩存與文件結點緩存:

  echo 3 > /proc/sys/vm/drop_caches

2.清空文件內容
     cat /dev/null > file_name
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章