centos 防火墙 iptables firewalld SELinux

参考

相关内容

centos7 中才开始引用firewalld的概念,它是iptables的升级版,以上两者都不是真正的防火墙,都需要与内核netfilter配合使用。

Centos5、6使用iptables来管理服务器防火墙,Centos7 默认是firewalld。

SELinux是Linux一个子安全机制

本地环境

SELinux

/usr/sbin/sestatus -v        # 查看SELinux状态

# 关闭SELinux:
setenforce 0        # 1.临时关闭(不用重启机器)
修改/etc/selinux/config文件将SELINUX=enforcing改为SELINUX=disabled 修改配置文件需要重启机器


firewalld

# 使用systemctl
systemctl stop firewalld.service     #关闭firewalld
systemctl start firewalld.service      #启动服务
systemctl restart firewalld.service     #重启服务
systemctl enable firewalld.service     #启用firewalld系统重启firewalld服务加载
systemctl disable firewalld.service     #禁用firewalld系统重启firewalld服务不会加载
firewall-cmd --list-ports     #查看已经开放的端口
firewall-cmd --zone=public --add-port=80/tcp --permanent      #开启80端口:命令含义:–zone #作用域–add-port=80/tcp #添加端口,格式为:端口/通讯协议–permanent #永久生效,没有此参数重启后失效

# 使用service
service firewalld start    # 开启
service firewalld restart    # 重启
service firewalld stop    # 关闭

# 使用firewall-cmd
firewall-cmd --state    #查看状态

iptables

systemctl start iptables.service    # 开启iptables防火墙的命令是
systemctl restart iptables.service    # 重启iptables防火墙的命令是
systemctl stop iptables.service    # 关闭iptables防火墙的命令是
systemctl status iptables.service     #查看iptables防火墙状态的命令是
service iptables status  # 查看防火墙状态
service iptables stop  # 停止防火墙
service iptables start  # 启动防火墙
service iptables restart    # 重启防火墙
chkconfig iptables off  # 永久关闭防火墙
chkconfig iptables on # 永久关闭后重启

安装iptables

yum list | grep iptables    #查看yum源是否有iptables的安装包

yum install -y iptables.x86_64                                #安装iptables.x86_64 :该安装包主要包含iptables的相关命令以及iptables的相关模块
yum install -y iptables-services.x86_64               #该安装包主要配置文件、启动或重启用的systemctl的服务


iptables-services 包含信息

posted @ 2019-09-24 16:08  LoveSnowBaby  阅读(199)  评论(0编辑  收藏  举报