Linux下 iptables防火牆 放開相關port 拒絕相關port 及查看已放開port

來源:互聯網
上載者:User

標籤:chain   配置   loading   in out   ref   prot   etc   sys   inpu   

我用的是fedora 14

1. 查看iptables 防火牆已經開啟的port:/etc/init.d/iptables status

[[email protected] ~]#/etc/rc.d/init.d/iptables status             或者 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:3306

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

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

 

2. 開啟 tcp 8080port 

/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

/etc/rc.d/init.d/iptables save  或者 service iptables save #儲存配置 /etc/rc.d/init.d/iptables restart 或者 service iptables restart #重新啟動服務

[[email protected] ~]# /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
[[email protected] ~]# /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[[email protected] ~]# /etc/rc.d/init.d/iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

[[email protected] ~]# 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:8080
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:3306

3. 刪除chain INPUT指定規則1;

[[email protected] ~]# iptables -D INPUT 1
[[email protected] ~]# 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:3306

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

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

4.Reject 指定port;

[[email protected] ~]# /sbin/iptables -I INPUT -p tcp --dport 8080 -j REJECT
[[email protected] ~]# service iptables status                             
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination        
1    REJECT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:8080 reject-with icmp-port-unreachable
2    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        

很多其它的規則能夠參考

http://www.2cto.com/os/201304/201164.html

 

 

 

Linux下 iptables防火牆 放開相關port 拒絕相關port 及查看已放開port

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.