连接到本地网络 Raspberry Pi [英] Connecting to a local network Raspberry Pi

查看:98
本文介绍了连接到本地网络 Raspberry Pi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个:

树莓派 2

运行

Raspbian Jessie 版本:2015 年 11 月

我正在使用 Undertow(一个 Java http 服务器)来为网站提供服务.这是我用来构建服务器的代码.

I am using Undertow (a Java http server) to serve a website. This is the code that I use to build the server.

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

问题:尽管能够 ping 和 SSH 进入 PI,但我无法从本地网络上的另一台机器看到网络服务器.

Problem: I am unable to see the webserver from another machine on the local network despite being able to ping and SSH into the PI.

我所做的(在 Pi2 上):

What I have done (on the Pi2):

wget localhost:8890

正确返回 index.html

returns the index.html correctly

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

Chrome on my development machine 192.168.1.8:8890 gives ERR_CONNECTION_REFUSED

wget 192.168.1.8:8890

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

Connecting to 192.168.1.8:8890... failed: Connection refused.

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

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

It is my understanding that there is no firewall so I am baffled as to why I can't see the server from my development machine.

推荐答案

参见:

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

您的 Web 服务器仅侦听本地主机地址 (127.0.0.1).这样,除了本地主机之外,任何地方都无法访问它.

Your web server listens only on localhost address (127.0.0.1). This way it couldn't be accessed from anywhere but localhost.

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

And your nmap scan shows the same: the only remotely accessible port is 22.

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

To access this service remotely you have to bind web server to any non-local address belonging to this raspberry pi (192.168.1.8) or to "any address" 0.0.0.0, as SSH service is bound.

如何执行此操作已写在您的 Web 服务器手册中.可能,您必须以-d"参数开始,即

How to do this is written in the manual of your web server. Probably, you have to start is with a "-d" param, i.e.

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

或类似的东西.

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

In listener setup code this looks like

"localhost" 必须替换为一些公共名称.这可能是0.0.0.0"或192.168.1.8".我们也可以

"localhost" have to be replaced with some public name. This could be "0.0.0.0" or "192.168.1.8". We also can

cat "192.168.1.8 somename" >> /etc/hosts

然后使用某个名称:

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

这篇关于连接到本地网络 Raspberry Pi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆