通过以太网将Raspberry Pi连接到没有路由器的笔记本电脑? [英] Hook up Raspberry Pi via Ethernet to laptop without router?
问题描述
我正在使用Raspberry Pi进行气球项目.当我们有可能恢复Raspberry Pi时,它很可能会在农村地区,我想在那时安全地关闭Pi.
I'm working on a balloon project with a Raspberry Pi. When we potentially recover the Raspberry Pi, it will most likely be in a rural location and I'd like to turn off the Pi at that point safely.
在附近没有路由器或网络的情况下,我想知道是否可以通过以太网电缆将Raspberry Pi连接到笔记本电脑?
Without a router or network nearby, I was wondering if there is a way to hook up a Raspberry Pi with an Ethernet cable directly to a laptop?
推荐答案
这是针对Ubuntu的解决方案(该想法也适用于Windows或Mac),我今天才尝试过,它就像一种魅力.
It's a solution for Ubuntu (the idea also works for Windows or Mac) I just tried today and it works like a charm.
材料
- 交叉以太网电缆(名称很漂亮,但这只是普通的以太网电缆)
- 一台笔记本电脑(ubuntu)
- Raspberry Pi(我有Pi2)
Ubuntu上的先决条件
-
安装网络管理器
Install network-manager
$sudo apt-get install network-manager
安装nmap
$sudo apt-get install nmap
在笔记本电脑(Ubuntu)上编辑有线连接
- 将IpV4设置更改为共享到其他计算机"
- 保存设置
- 重新启动笔记本电脑
通过以太网交叉电缆共享笔记本电脑的WiFi连接
-
使用以太网电缆与笔记本电脑连接RPi
Hook up your RPi with your laptop using the Ethernet cable
查找以太网连接(笔记本电脑)的广播地址,
Look up the broadcast address of the Ethernet connection (Laptop),
$/sbin/ifconfig eth1 | grep "Bcast" | awk -F: '{print $3}' | awk '{print $1}'
10.42.0.255
$/sbin/ifconfig eth1 | grep "Bcast" | awk -F: '{print $3}' | awk '{print $1}'
10.42.0.255
-
使用此地址找出您的RPi的IP地址,在我的情况下为10.42.0.96,因为10.42.0.1是我的笔记本电脑
Use this address to find out the IP address of your RPi, it's 10.42.0.96 in my case because 10.42.0.1 is my laptop
$nmap -n -sP 10.42.0.255/24
Starting Nmap 6.40 ( http://nmap.org ) at 2016-02-20 23:07 CET
Nmap scan report for 10.42.0.1
Host is up (0.00031s latency).
Nmap scan report for 10.42.0.96
Host is up (0.0023s latency).
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.71 seconds
-
从笔记本电脑(通过X转发的-Y)登录到RPi
Login to your RPi from your laptop (-Y with X-forwarding)
$ssh -Y pi@10.42.0.96
瞧瞧!现在,您的RPi已连接到笔记本电脑,并且RPi可以共享WiFi连接.
Lo and behold! Now your RPi is connected to your laptop and RPi can share the WiFi connection.
pi@raspberrypi ~ $
共享显示和具有RPi的笔记本电脑键盘
-
在Raspberry Pi上安装 vncserver
$ sudo apt-get update
$ sudo apt-get install tightvncserver
通过下载RealVNC在笔记本电脑上安装 vncviewer (它支持多个平台) http://www.realvnc.com/download/vnc/
Install vncviewer on your laptop by downloading RealVNC (it supports multiple platforms) http://www.realvnc.com/download/vnc/
为了能够复制&从VNC服务器<-> VNC查看器粘贴,您需要在RPi上安装自动剪切.
To be able to copy & paste from VNC server <--> VNC viewer, you need to install autocutsel on your RPi.
$sudo apt-get install autocutsel
如果该站点不起作用,请尝试直接从镜像站点下载.deb,例如
mirror.hmc.edu/debian/pool/main/a/autocutsel/autocutsel_0.10.0-1_armhf.deb
并安装
If this site doesn't work, try to download the .deb directly from a mirror site, e.g.
mirror.hmc.edu/debian/pool/main/a/autocutsel/autocutsel_0.10.0-1_armhf.deb
and install it
$sudo dpkg -i autocutsel_0.10.0-1_armhf.deb
-
在RPi上启动vncserver(安装自动剪切程序后必须重新启动vncserver,可以发出
$vncserver -kill :1
)
$vncserver :1
将autocutsel -fork添加到/home/pi/.vnc/xstartup
Add autocutsel -fork to /home/pi/.vnc/xstartup
#!/bin/sh
xrdb $HOME/.Xresources xsetroot -solid grey
autocutsel -fork
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
-
在笔记本电脑上启动vncviewer
Start vncviewer on your laptop
$vncviewer
将弹出一个vncviewer窗口,并键入RPi的IP地址(由笔记本电脑提供),然后键入端口1,即您的VNC服务器.例如:在我的情况下为10.42.0.96:1.
A vncviewer window will pop up and type in the IP address of your RPi (given by your laptop) followed by port 1, which is your VNC server. for example: 10.42.0.96:1 in my case.
通过输入密码(自行设置密码)将其连接到RPi上托管的vncserver
Connect it to the vncserver hosted on your RPi by typing in a password (set up a password yourself)
12.现在,您可以在笔记本电脑上看到RPi的桌面,然后打开浏览器以显示共享的WiFi连接也正常工作.
12.Now you can see the desktop of RPi on your laptop, and I opened my browser to show the shared WiFi connection is working as well.
这篇关于通过以太网将Raspberry Pi连接到没有路由器的笔记本电脑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!