CentOS7下,防火墙配置

CentOS中防火墙程序主要是firewall和iptables两种。

CentOS7中firewall服务已经默认安装好了,而iptables服务需要自己用yum install  iptabes-services来安装。


1、firewall防火墙操作


1、1 基本操作

操作命令

启动           systemctl start firewalld

关闭           systemctl  stop firewalld

查看状态    systemctl status firewalld

开机禁用    systemctl disable firewalld

开机启用    systemctl enable firewalld

查看版本    firewall-cmd --version

查看列表    firewall-cmd --list-all

1.2 开启一个防火墙端口

① 添加端口

扫描二维码关注公众号,回复: 3628573 查看本文章

firewall-cmd--add-port=3306/tcp --permanent

(--permanent永久生效,没有此参数重启后失效)

② 重新载入                          firewall-cmd --reload

③ 查看所有打开的端口        firewall-cmd --list-ports

1.3 删除一个已开启的端口

firewall-cmd --remove-port=3306/tcp--permanent



2、iptables防火墙操作

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

#关闭firewall                        service firewalld stop

#禁止firewall开机启动         systemctl disablefirewalld.service

#安装iptables防火墙            yum install iptables-services

2.2 Iptables防火墙基本操作

操作命令

查看防火墙状态    service  iptables status

停止防火墙           service  iptables stop

启动防火墙           service  iptables start

永久关闭防火墙    chkconfig  iptables off 

永久关闭后重启    chkconfig  iptables on

2.3 编辑iptables防火墙配置

vi /etc/sysconfig/iptables

以下是配置文件示例,编辑自己的规则

 

依照其中22端口,添加自己需要的端口

:wq保存退出后重启防火墙

service iptablesrestart

猜你喜欢

转载自www.cnblogs.com/zhaoyongkai/p/9816793.html