Linux【CentOS7】防火墙启动、重启添加端口等操作

前言:

      #centOS6系统,往下拉!!!

Centos6 使用的是iptables,Centos7 使用的是filewall   
iptables 用于过滤数据包,属于网络层防火墙。
firewall 能够允许哪些服务可用,那些端口可用...属于更高一层的防火墙。

1、 firewall常用命令

vim  /usr/lib/firewalld/services/ssh.xml
vim  /usr/lib/firewalld/services/http.xml
systemctl enable firewalld.service
systemctl restart firewalld.service
firewall-cmd --state    查看状态
firewall-cmd --list-all   查看过滤的列表信息
firewall-cmd --zone=public --permanent --add-port=8502/tcp     添加一个协议为tcp的8502端口过滤
vim /etc/firewalld/zones/public.xml     <port protocol="tcp" port="8502"/>
systemctl restart firewalld.service

2、用户配置目录

/etc/firewalld/

 3、查看防火墙状态

firewall-cmd --state

4、启动防火墙

#启动firewall:
systemctl start firewalld.service

#设置开机自启:
systemctl enable firewalld.service

#重启防火墙:
systemctl restart firewalld.service

#再次查看防火墙状态
firewall-cmd --state

5、开启指定端口

#可以通过修改配置文件的方式添加端口,也可以通过命令的方式添加端口

开端口命令:firewall-cmd --zone=public --add-port=8080/tcp --permanent
重启防火墙:systemctl restart firewalld.service
 
 
--zone #作用域
 
--add-port=80/tcp  #添加端口,格式为:端口/通讯协议
 
--permanent   #永久生效,没有此参数重启后失效

6、查询端口号8080 是否开启:

firewall-cmd --query-port=8080/tcp

7、重启防火墙:

firewall-cmd --reload

Centos6 添加防火墙规则,切换为iptables防火墙

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


1、关闭firewall:

systemctl stop firewalld.service
systemctl disable firewalld.service #禁止firewall开机启动

2、安装iptables防火墙

yum install iptables-services #安装

3、设置iptables开机启动

systemctl enable iptables

4、启动 iptables

systemctl start iptables

5、查看端口开放规则

 #如果未开放,vi /etc/sysconfig/iptables    添加   -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEP

   8080:端口,可以修改成你想要的

6、防火墙重启生效

service iptables restart

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章