centos7防火墙使用方法

Posted on   风行天下-2080  阅读(154)  评论(0编辑  收藏  举报

参考网站:https://blog.csdn.net/achang21/article/details/52538049

https://blog.csdn.net/weixin_45649763/article/details/103348513     (防火墙iptables与firewall-cmd区别)

https://www.cnblogs.com/mozq/p/11159662.html

添加开放指定端口:

[root@yao bin]# firewall-cmd --zone=public --permanent --add-port=10051/tcp    

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

添加多个不连续端口:

[root@instance-fjii60o3 ~]# firewall-cmd --add-port=80/tcp --add-port=8080/tcp

防火墙重启:

[root@yao bin]# firewall-cmd --reload

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

查看防火墙列表:

[root@yao bin]# firewall-cmd --list-all

 删除制定端口:

firewall-cmd --zone= public --remove-port=80/tcp --permanent
配置文件:

[root@LinuxS03 ~]# vim /etc/firewalld/zones/public.xml 

[root@yao ~]# cat /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="dhcpv6-client"/>
<service name="ssh"/>
<port protocol="tcp" port="22222"/>
<port protocol="tcp" port="10050"/>
<port protocol="tcp" port="10051"/>
</zone>

#######################################################################
centos6防火墙开启方法:
查看状态:
iptables -L -n
下面添加对特定端口开放的方法:
使用iptables开放如下端口
/sbin/iptables -I INPUT -p tcp --dport 8000 -j ACCEPT
保存
/etc/rc.d/init.d/iptables save
重启服务
service iptables restart
查看需要打开的端口是否生效?
/etc/init.d/iptables status

法2:
或直接编辑/etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 4000 -j ACCEPT
保存在前面部分
再重启:
service iptables restart
 
 
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

随笔 - 618, 文章 - 0, 评论 - 6, 阅读 - 37万

Copyright © 2025 风行天下-2080
Powered by .NET 9.0 on Kubernetes

点击右上角即可分享
微信分享提示