在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”標記,把么防火牆規則在重啟后會失效。