CentOS /Linux 開放80、8080端口或者開放某個端口

CentOS /Linux 開放80、8080端口或者開放某個端口
方式一
開放端口
查看防火牆設置發現沒開啓80端口
> iptables -L -n 

修改端口配置文件
> vim  /etc/sysconfig/iptables

開放端口
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

重啓iptables
>  service iptables restart

重啓防火牆
重啓後生效 
  開啓: chkconfig iptables on 
  關閉: chkconfig iptables off

即時生效,重啓後失效 
  開啓: service iptables start 
  關閉: service iptables stop

開放一個範圍的端口3000到5000

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3000:5000 -j ACCEPT

方式二
查看哪些端口被打開
 > netstat -anp

關閉端口號
> iptables -A OUTPUT -p tcp --dport 端口號-j DROP

打開端口號:
>  iptables -A INPUT -ptcp --dport  端口號-j ACCEPT

> iptables -I INPUT -p tcp --dport 5672 -j ACCEPT 

以下是linux打開端口命令的使用方法。
  nc -lp 23 &(打開23端口,即telnet) 
  netstat -an | grep 23 (查看是否打開23端口)

linux打開端口命令每一個打開的端口,都需要有相應的監聽程序纔可以
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章