Linux下防火牆開啟相關埠及檢視已開啟埠

Michael_DD發表於2014-11-18
Linux下防火牆開啟相關埠及檢視已開啟埠


1. 預設情況下Linux的防火牆都是在關閉狀態下的
[root@test etc]# service iptables status
Firewall is stopped.
[root@test etc]#

2. 防火牆開通的情況
[root@test ~]# service iptables start
iptables: Applying firewall rules: [  OK  ]
[root@test ~]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         

[root@test ~]#

以上可以看出,防火牆開通的埠為22  state NEW tcp dpt:22
還有其他一些狀態資訊


3. 開通特定埠,比如tcp 80 和 5666埠
[root@test ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT


4. 儲存並重啟防火牆
[root@test ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables: [  OK  ]
[root@test ~]# service iptables restart
iptables: Flushing firewall rules: [  OK  ]
iptables: Setting chains to policy ACCEPT: filter [  OK  ]
iptables: Unloading modules: [  OK  ]
iptables: Applying firewall rules: [  OK  ]
[root@test ~]# service iptables status
Table: 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:80
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
3    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
6    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         

埠80 已開通。同樣的方式開通5666埠

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29500582/viewspace-1337181/,如需轉載,請註明出處,否則將追究法律責任。

相關文章