我试图在我的Cent OS 5.2中打开端口843 ,我添加了以下行etc\sysconfig\iptables :
-A INPUT -p tcp --dport 843 -j ACCEPT
然后更新我的iptables服务。 我需要通过sudo node index.js命令来监听由root用户运行的node.js应用程序中的那个端口,但是当我尝试通过该端口build立连接时仍然会出现forbidden port错误。
这是我通过运行sudo iptables -L -v :
Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 2811 238K ACCEPT tcp -- any any anywhere anywhere tcp dpt:http 112 6224 ACCEPT tcp -- any any anywhere anywhere tcp dpt:hbci 0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:843 41 2124 ACCEPT tcp -- any any anywhere anywhere state NEW tcp multiport dports 5901:5903,6001:6003 13093 13M ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED 26 3584 ACCEPT icmp -- any any anywhere anywhere 0 0 ACCEPT all -- lo any anywhere anywhere 109 6404 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:ssh 888K 80M REJECT all -- any any anywhere anywhere
这是sudo netstat -ptl | grep node sudo netstat -ptl | grep node :
tcp 0 0 *:843 *:* LISTEN 12927/node tcp 0 0 *:http *:* LISTEN 12927/node tcp 0 0 *:10843 *:* LISTEN 12927/node
我试着在socket.io中用这个代码来监听那个端口:
var io = require('socket.io').listen( 843, { log: false, flashPolicyServer: true, transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling', 'jsonp-polling'] } ); io.sockets.on('connection', function(socket){ // my event listeners });
问题解决了。 所有的服务器configuration都是正确的,显然客户端的防火墙阻止了这个端口。 所以我切换到使用与http服务器(端口80)相同的端口的sockjs ,因此没有连接被客户端阻塞的风险。