Linux中如何開啟8080埠供外界訪問 和開啟允許對外訪問的埠8000
舉例:
開放10000埠的解決步驟如下:
1、修改/etc/sysconfig/iptables檔案,增加如下一行:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10000 -j ACCEPT
重啟 iptables
service iptables restart2、重啟防火牆,這裡有兩種方式重啟防火牆
a) 重啟後生效
開啟: chkconfig iptables on關閉: chkconfig iptables off
b) 即時生效,重啟後失效
開啟: service iptables start關閉: service iptables stop
3、或者用menu-system-administration-firewall
去新增使用者需要的埠。
By the way:
a. netstat -tanp 去顯示埠狀態。
/usr/sbin/lsof -i
b. telnet ipaddr port
to check if ip and port is available before making connection.
http://www.cnblogs.com/simonhaninmelbourne/archive/2012/10/06/2713233.html
LINUX通過下面的命令可以開啟允許對外訪問的網路埠:
/sbin/iptables -I INPUT -p tcp --dport 8000 -j ACCEPT #開啟8000埠
/etc/rc.d/init.d/iptables save #儲存配置
/etc/rc.d/init.d/iptables restart #重啟服務
檢視埠是否已經開放
/etc/init.d/iptables status
裝好Tomcat7後,發現除了本機能訪問外界訪問不了,豈有此理。於是請教百度大神,在費一番周折後,總結步驟如下:
1.修改檔案/etc/sysconfig/iptables
[[email protected] ~]# cd /etc/sysconfig/
[[email protected] sysconfig]# vi iptables
檔案內容如下,注意紅色一行是新加的,目的是對外界開放8080埠
# 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]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
這行文字實際是從上一行拷貝修改而來,在VI中拷貝一行用yy,拷貝多行用yyn,貼上用p。還算方便的。
2.將iptables服務重啟。
[[email protected] sysconfig]# service iptables restart
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
Applying iptables firewall rules: [ OK ]
Loading additional iptables modules: ip_conntrack_ftp [ OK ]
[[email protected] sysconfig]#
3.如若不想修改iptables表,可以直接輸入下面命令:
# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
http://www.cnblogs.com/xiandedanteng/archive/2013/08/28/3287751.html