输入命令:
vi /etc/sysconfig/iptables
内容修改成如下:
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
输入命令 ctrl+c
输入命令 :wq (冒号也要输入)
*****************************************扩展************************************************************
如果测试socket连接,需要再打开一个窗口,那就直接增加一个端口号。
-A INPUT -m state –state NEW -m tcp -p tcp –dport 23000 -j ACCEPT
增加完之后需要重启服务:
sudo service iptables restart
重启之后查看端口号打开状态:使用命令
/etc/init.d/iptables status
(责任编辑:IT) |