centos7安装iptables

Centos7下默认的防火墙是Firewall,替代了之前的iptables

firewall配置

  1. 系统配置目录
    /usr/lib/firewalld/services
    目录中存放定义好的网络服务和端口参数,系统参数,不能修改。
  2. 用户配置目录
    /etc/firewalld/

如何自定义添加端口

用户可以通过修改配置文件的方式添加端口,也可以通过命令的方式添加端口,注意,修改的内容会在/etc/firewalld/ 目录下的配置文件中还体现。

  1. 命令的方式添加端口
    firewall-cmd --permanent --add-port=9527/tcp
    参数介绍:
  • firwall-cmd:是Linux提供的操作firewall的一个工具;
  • --permanent:表示设置为持久;
  • --add-port:标识添加的端口;
    另外,firewall中有Zone的概念,可以将具体的端口制定到具体的zone配置文件中。
    例如:添加8010端口
    firewall-cmd --zone=public --permanent --add-port=8010/tcp
    --zone=public:指定的zone为public;
  1. 修改配置文件的方式添加端口

firewall常用命令

  1. 重启、关闭、开启firewalld.service服务
    service firewalld restart 重启
    service firewalld start 开启
    service firewalld stop 关闭
  2. 查看firewall服务状态
    systemctl status firewall
  3. 查看firewall的状态
    firewall-cmd --state
  4. 查看防火墙规则
    firewall-cmd --list-all

CentOS切换为iptables防火墙:

切换到iptables首先应该关掉默认的firewalld,然后安装iptables服务。

  1. 关闭firewall:
    service firewalld stop
    systemctl disable firewalld.service #禁止firewall开机启动

  2. 安装iptables防火墙
    yum install iptables-services
    yum install iptables* -y#安装
    注:rpm -qa|grep iptables,查看有没有iptables的安装包,如果你的系统是centos系统,那么你的yum源就是网络yum源,只要保障你的虚拟机能够上网就行,那么就先yum list查看一下,然后直接yum install iptables* -y

  3. 编辑iptables防火墙配置
    vi /etc/sysconfig/iptables #编辑防火墙配置文件
    service iptables start #开启
    systemctl enable iptables.service #设置防火墙开机启动

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容