cod*_*ard 10 ubuntu netstat ipv4 ipv6 node.js
我在端口5403上运行node.js服务器.我可以在这个端口上远程访问私有IP,但是无法在同一端口上telnet到公共ip.
我假设这是因为node.js只是在监听ipv6.这是结果
netstat -tpln
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN
-
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
-
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
-
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
-
tcp6 0 0 :::5611 :::* LISTEN
25715/node
tcp6 0 0 :::22 :::* LISTEN
-
tcp6 0 0 ::1:631 :::* LISTEN
-
tcp6 0 0 :::5403 :::* LISTEN
25709/node
Run Code Online (Sandbox Code Playgroud)
如何让节点服务器监听ipv4
Dar*_*llo 19
你打电话时需要指定一个IPV4地址listen(),我对http模块有同样的问题.如果我用这个:
var http = require('http');
var server = http.createServer(function(request, response) {
...
});
server.listen(13882, function() { });
Run Code Online (Sandbox Code Playgroud)
它只能监听IPV6,你可以从netstat输出中看到:
$ netstat -lntp
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp6 0 0 :::13882 :::* LISTEN
Run Code Online (Sandbox Code Playgroud)
但是,如果我指定这样的IPV4地址:
var http = require('http');
var server = http.createServer(function(request, response) {
...
});
server.listen(13882, "0.0.0.0", function() { });
Run Code Online (Sandbox Code Playgroud)
netstat会将服务器报告为侦听IPV4:
$ netstat -lntp
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0 0.0.0.0:13882 0 0.0.0.0:13882 LISTEN
Run Code Online (Sandbox Code Playgroud)
我正在使用Ubuntu 16.04和npm 5.3.0.
HTH
| 归档时间: |
|
| 查看次数: |
7772 次 |
| 最近记录: |