Centos 防火墙命令

前端之家收集整理的这篇文章主要介绍了Centos 防火墙命令前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Centos7

Centos7 的firewalld 取代了iptables

查看开放端口

  1. firewall-cmd --list-ports

开启端口

  1. firewall-cmd --zone=public --add-port=80/tcp --permanent

开启范围端口 8080 - 9090范围的端口

  1. firewall-cmd --zone=public --add-port=8080-9090/tcp --permanent

命令含义

  1. zone #作用域
  2. add-port=80/tcp #添加端口,格式为:端口/通讯协议
  3. permanent #永久生效,没有此参数重启后失效

防火墙命令

  1. firewall-cmd --reload #重启firewall
  2. firewall-cmd --state #查看防火墙状态
  3. systemctl start firewalld.service #开启firewall
  4. systemctl stop firewalld.service #停止firewall
  5. systemctl disable firewalld.service #禁止firewall开机启动

Centos6

  1. #查看开放端口
  2. service iptables status
  3.  
  4. #开启8080端口
  5. /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
  6.  
  7. #开启命令:
  8. service iptables start
  9.  
  10. #关闭命令:
  11. service iptables stop
  12.  
  13. #永久关闭防火墙:
  14. chkconfig iptables off

可能发生的异常

1.启动或者关闭防火墙没任何的提示
  1. [root@ethnicity ~]# service iptables start
  2. [root@ethnicity ~]# service iptables stop
2.查看防火墙的状态直接提示模块未加载
  1. [root@ethnicity ~]# service iptables status
  2. iptables: Firewall modules are not loaded.

修复方法

  1. modprobe ip_tables #加载ip_tables模块
  2. modprobe iptable_filter #加载iptable_filter模块
  3. [root@ethnicity ~]# lsmod | grep iptable #查看模块,有模块即解决
  4. iptable_filter 2173 0
  5. ip_tables 9567 1 iptable_filter

猜你在找的CentOS相关文章