连接到本地网络Raspberry Pi

时间:2015-12-05 19:48:32

标签: linux raspberry-pi raspbian

我有一个:

Rasberry Pi 2

运行

Raspbian Jessie Version:November 2015

我使用Undertow(Java http服务器)来为网站服务。这是我用来构建服务器的代码。

Undertow server = Undertow.builder()
                   .addHttpListener(8890, "localhost")
                   .setHandler(Handlers.pathTemplate()
                      .add("/", resource(new PathResourceManager(staticFilePath, 100))
                              .setDirectoryListingEnabled(false))
                   .build();

问题:我无法在本地网络上看到来自其他计算机的网络服务器,尽管能够通过ping和SSH进入PI。

我所做的(在Pi2上):

wget localhost:8890

正确返回index.html

netstat -lptn

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::22                   :::*                    LISTEN      -               
tcp6       0      0 127.0.0.1:8890          :::*                    LISTEN      1743/java  

我的开发机器上的Chrome 192.168.1.8:8890给出了 ERR_CONNECTION_REFUSED

wget 192.168.1.8:8890

连接到192.168.1.8:8890 ...失败:连接被拒绝。

nmap 192.168.1.8

Starting Nmap 6.40 ( http://nmap.org ) at 2015-12-05 14:05 CST
Nmap scan report for 192.168.1.8
Host is up (0.039s latency).
Not shown: 999 closed ports
PORT   STATE SERVICE
22/tcp open  ssh

Nmap done: 1 IP address (1 host up) scanned in 1.83 seconds

我的理解是没有防火墙,所以我感到困惑的是为什么我无法从我的开发机器上看到服务器。

1 个答案:

答案 0 :(得分:1)

请参阅:

tcp6       0      0 127.0.0.1:8890    :::*      LISTEN      1743/java  

您的Web服务器仅侦听本地主机地址(127.0.0.1)。这样就无法从localhost访问它。

您的nmap扫描显示相同:唯一可远程访问的端口是22。

要远程访问此服务,您必须将Web服务器绑定到属于此raspberry pi(192.168.1.8)的任何非本地地址或绑定到SSH服务的“任何地址”0.0.0.0。

如何执行此操作将在Web服务器的手册中编写。也许你必须从“-d”参数开始,即

standalone.sh -b=0.0.0.0
standalone.sh -Djboss.bind.address=0.0.0.0

或类似的东西。

在侦听器设置代码中,这看起来像

“localhost”必须替换为某个公共名称。这可以是“0.0.0.0”或“192.168.1.8”。我们也可以

cat "192.168.1.8 somename" >> /etc/hosts

然后使用somename:

Undertow server = Undertow.builder() .addHttpListener(8890, "somename")