无法从外部连接到Linux服务器

时间:2014-05-19 12:30:04

标签: linux tcp debian

我有一台在Linux / debian机器上运行的服务器。我可以在同一台机器上正确地进行GET / PUT。

$ curl -v -X PUT -d "blabla" 127.0.1.1:5678
* About to connect() to 127.0.1.1 port 5678 (#0)
*   Trying 127.0.1.1...
* connected
* Connected to 127.0.1.1 (127.0.1.1) port 5678 (#0)
> PUT / HTTP/1.1
> User-Agent: curl/7.26.0
> Host: 127.0.1.1:5678
> Accept: */*
> Content-Length: 6
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 6 out of 6 bytes
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 405 Unsupported request method: "PUT"
< Connection: close
< Server: My Server v1.0.0
< 
* Closing connection #0

但是,如果我尝试从另一台机器(相同的本地网络),这就是它所说的:

$ curl -v -X PUT -d "blabla" 192.168.0.21:5678
* About to connect() to 192.168.0.21 port 5678 (#0)
*   Trying 192.168.0.21...
* Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host

从服务器端,没有防火墙正在运行:

$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination   

这是netcat揭示的内容:

$ netstat -alnp | grep 5678
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.1.1:5678          0.0.0.0:*               LISTEN      -

有没有办法调试可能发生的事情?

2 个答案:

答案 0 :(得分:3)

webapp正在侦听127.0.0.1,即loopback接口。为了能够在外面访问,它必须在192.168.0.21:5678或*:5678上监听,这意味着所有接口。

答案 1 :(得分:0)

我不得不评论following line

$ cat /etc/hosts
#127.0.1.1  [...]

这类似于我的debian挤压设置,似乎按预期工作。我不知道为什么这条额外的线条让事情变得如此糟糕。显然这是由于issue in GNOME包,但是这个服务器甚至没有安装X.