linux iptables开放/关闭端口命令

在CentOS/RHEL 7以前版本上开启端口

#开放端口:8080
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
#将更改进行保存
/etc/rc.d/init.d/iptables save
#重启防火墙以便改动生效:(或者直接重启系统)
/etc/init.d/iptables restart

#关闭iptable防火墙
/etc/init.d/iptables stop
service iptables stop # 停止服务
#查看防火墙信息
/etc/init.d/iptables status

在CentOS/RHEL 7上开启端口

CentOS/RHEL 7后,防火墙规则设置由firewalld服务进程默认管理。一个叫做firewall-cmd的命令行客户端支持和这个守护进程通信以永久修改防火墙规则。

 使用下面命令来永久打开一个新端口(如TCP/9200)

[root@localhost init.d]# firewall-cmd --zone=public --add-port=9200/tcp --permanent

  [root@localhost init.d]# firewall-cmd --reload 

如果不使用“--permanent”标记,把么防火墙规则在重启后会失效。

原文地址:https://www.cnblogs.com/zsg88/p/7810100.html