linux iptables开放/关闭端口命令

只愿长相守 提交于 2020-02-06 11:46:29

在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”标记,把么防火墙规则在重启后会失效。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!