1、進入目錄:[[email protected] ~]# cd /etc/sysconfig

2、修改檔案:[[email protected] sysconfig]# vi iptables
2.1打開檔案後是這樣
2.2按鍵盤的a鍵變成編輯狀态
2.3在檔案添加一句:-I INPUT -p tcp --dport 3306 -j ACCEPT
其中3306是端口号。如果添加80就寫80
2.4按Esc鍵
2.5按Shift+:
2.6輸入wq儲存退出
3、重新開機防火牆
[[email protected] sysconfig]# service iptables restart
4、檢視端口
[[email protected] sysconfig]# /etc/init.d/iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3306
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
轉載于:https://www.cnblogs.com/Coling/articles/3521993.html