Translate-By disylee

This commit is contained in:
disylee
2014-05-18 18:24:05 +08:00
parent 9f3f78f754
commit 6ca90a36dc
2 changed files with 138 additions and 186 deletions

View File

@@ -1,186 +0,0 @@
disylee20140516的翻译这年头我先占个坑第一次
[sailing]
5 Pointers To Supercharge Your Raspberry Pi Projects
================================================================================
> From SSH to port forwarding, these advanced techniques will ease Raspberry Pi development.
Youre in command of the command line. Youre not a noob at setting up NOOBS. Slowly but surely, youre learning your way around the affordable, credit card-size computer for DIY tinkering, Raspberry Pi.
> See also: [The Quantified Fish: How My Aquarium Uses Raspberry Pi][1]
However, theres a steep jump-off point between the basics and the intermediate stuff. When you move from “setting up your Pi” tutorials to stuff like “building a media server,” the pre-project requirements start to get a little dicey. Many intermediate Pi tutorials, including some of the ones here on ReadWrite, assume a few things about your Raspberry Pi setup.
Not every project will require all of the techniques suggested here, but knowing these procedures will make projects that do require them go much more smoothly later.
When youre ready to go beyond the basics, here are some things you can do to prepare your Raspberry Pi for any pre-requirements that a tutorial could throw at you.
### 1) Using SSH ###
SSH, which stands for [Secure Shell][2], is a cryptographic network protocol that lets you securely transfer data between your computer and your Raspberry Pi. Projects might require it so you can control your Raspberry Pi from your computer's command line without hooking it up to a monitor or keyboard.
SSH now comes pre-installed in Raspberry Pi operating system [Raspbian][3], so if you have installed the latest or close-to-latest version of NOOBS, you already have it.
To use SSH, first you need your Pis IP address. Boot your Pi to the command line and type:
sudo ifconfig
[Three paragraphs will appear][4]. Your IP address will show up in either the first or the third line, depending on whether your Raspberry Pi is hooked up to an ethernet cable or via a wifi adaptor. If it's ethernet, look in the first paragraph, which starts with "eth0." If it's wifi, look in the third paragraph, which starts with "wlan0."
Either way, you'll see the words “inet addr” followed by an IP—something like 192.168.2.2, a pretty common default IP address that well use for the duration of this article.
Now you have the address that'll allow you to access the Pi from your computer. If youre on a Mac, you already have built-in SSH. Launch the Terminal application and type:
ssh pi@192.168.2.2
Itll ask for your password. By default, this is always "raspberry." If youve changed it to something else, use that instead. Now, youre in!
If youre on a PC, theres an extra step.
![](http://readwrite.com/files/putty2.jpg)
Download and run [PuTTY][5] or another SSH client for Windows. Enter your IP address in the field, as shown in the above screenshot. Keep the default port at 22. Hit enter, and PuTTY will open a terminal window which will prompt you for your username and password. Fill those in, and begin working remotely on your Pi.
### 2) Remote Desktop Your Raspberry Pi ###
SSH is great for remote controlling your Pi from the command line. But what if youd like to work off of its Graphical User Interface (GUI)? Fortunately, this is already built in for Macs and PCs.
On your Raspberry Pis command line, (and yes, you can do this with SSH), type:
sudo apt-get install xrdp
Xrdp is a [daemon][6], a computer process that runs in the background that can support Microsoft Remote Desktop Client on both Mac and PC. Once it's installed on your Raspberry Pi, your Mac or PC will be able to access it through the client.
Search your computer for a program called Remote Desktop Client. Its not exactly hidden per se, but its not stored in your application folder.
![](http://readwrite.com/files/Screen%20Shot%202014-04-07%20at%2010.14.13%20PM.png)
Input the IP address when prompted. Next, an xrdp window will pop up, prompting you for your username and password.
![](http://readwrite.com/files/Screen%20Shot%202014-04-07%20at%2010.14.31%20PM.png)
If all goes well, youll see your Raspberry Pis desktop in a window on your computer screen.
![](http://readwrite.com/files/Screen%20Shot%202014-04-07%20at%2010.14.48%20PM.png)
### 3) Static IP For Your Pi On The Home Network ###
That Raspberry Pi IP we found earlier (in Step 1) may work for now, but theres no guarantee your router will keep assigning the same IP address to your Pi forever. That means the other computers on your network wont know which IP address the Pi lives at. So how do you assign it a static IP instead of having to use the “sudo ifconfig” command every few days, or worse, hours?
Predictably, we begin with "ifconfig." So type:
sudo ifconfig
Get a pen and paper ready, and record the following three addresses [listed after eth0][7] (The comments after the hashes are my descriptions. They won't show up in the code.):
inet addr: 192.168.2.2 # Pi's Current IP Address
Bcast: 192.168.0.255 # The Broadcast IP Range
Mask: 255.255.255.0 # Subnet Mask Address
You still need two more pieces of information. So type the following line to get the Gateway and Destination addresses:
netstat -nr
Next, go to your routers configuration. (How you do this is dependent on which router you have, so check the manual.) Find out which addresses the Dynamic Host Configuration Protocol (DHCP) is giving out to your devices. These are off-limits addresses, since the protocol is already using them. So pick one that isnt being used—for example, 192.168.2.2. Your router may allow you to reserve an unused IP address and assign it to a local device like the Raspberry Pi. (If you have a Belkin router, this is probably the case.) **If so, you can stop here**.
If not, you need to let the Raspberry Pi know what its new IP address is. Well do this by editing a configuration file on the Pi in the nano text editor:
sudo nano /etc/network/interfaces
Change the line “iface eth0 inet dhcp” to “iface eth0 inet static” to inform it that its now static.
Then enter the following, but replace the X's with the addresses you copied down earlier! The top address is the one weve decided to assign after looking at what our DHCP wasnt already using.
address 192.168.2.2
netmask XXX.XXX.XXX.X
network XXX.XXX.X.X
broadcast XXX.XXX.X.X
gateway XXX.XXX.X.X
Reboot the Raspberry Pi with “sudo reboot” and run “ifconfig” one more time. Your new static settings should appear!
### 4) Forwarding Ports To Raspberry Pi ###
Some Pi projects may require you forward a specific Internet port to your Raspberry Pi. Ports are virtual pathways where information travels on the Internet. You sometimes need to forward a port in order to make a computer, like the Raspberry Pi, accessible to the Internet even if its behind a router. It's kind of like dialing an extension on a phone network.
Port forwarding can be used for projects like a [Raspberry Pi web server][8], Voice Over IP on the Pi, or simply for peer-to-peer downloading. There are 65,000+ ports to choose from, so you can assign a different port for traffic for every Raspberry Pi project you do.
Some ports are default for certain things. Port 80 is default for HTML pages. Port 21 is default for FTP (File Transfer Protocol) transferring. Port 1194 is default for setting up a VPN server. So a lot of the time, you can just go with whichever port is set as the default.
The way to set up port forwarding is entirely dependent on your router, so its difficult to create a tutorial for port forwarding beyond [what it actually does][9]. Read the documentation that comes with your router in order to customize and define ports to forward.
Here are some port forwarding tutorials for major router manufacturers:
- [Belkin][10]
- [Netgear][11]
- [Linksys][12]
### 5) Static IP For Your Pi On The Internet ###
Once again, if your ISP already gives you a static IP address, you don't need to worry about this section.
Weve already set up a static internal IP address for the Raspberry Pi, which means computers inside your local network will always know where to find your Pi. But what about projects that require Raspberry Pi to be connected to the Internet? If you want to build a Web server with your Raspberry Pi, people outside your network need to know where your Pi lives, which means setting a public IP that always looks the same.
I say “looks the same” because were really setting up a pseudo-static IP. Your ISP will continue to change the address as usual. So every time somebody connects to your Pi, the script were about to write will say, “Looks like the Pi has moved! Let me redirect you to the new address."
We do this with a [Dynamic DNS][13] (DDNS), which maintains a name server that gets updated in real-time, and [DDClient][14], a program that will correspond with DDNS directly from your Pi.
First sign up for a free dynamic host service like [DNS Dynamic][15]. Follow the instructions and create a new nameserver like Yourserver.dnsdynamic.com.
Now go to the command line on your Raspberry Pi and install DDClient with the following line:
sudo apt-get install ddclient
We need to edit the DDClient configuration with our DDNS's new name server:
sudo nano /etc/ddclient/ddclient.conf
Every service will have slightly different configuration, but the DDNS website should tell you what you need to do to configure this file. A standard configuration for DNS Dynamic, for example, [goes like this][16]. Copy and paste it in.
Your ISP isnt going to just stop updating the Raspberry Pis IP address because of this file, however, so we need to put a daemon at the very top of this script to tell it to continually check whether or not the IP address has changed.
daemon=600
# check every 600 seconds
This one checks every 10 minutes, which is just good practice. If you set it up to check every second, your dynamic service may not appreciate it because you'll be literally spamming their servers. Press Control + X to save and exit this configuration file.
After this, type:
ddclient
> See also: [12 Cool Projects For Your Raspberry Pi][17]
Simply typing the name of the program will run it. Itll continue to run as long as your Raspberry Pi is turned on. If you reboot your Pi, write “ddclient” to start running it again.
Now your Raspberry Pi is tricked out and ready for more advanced tutorials. Have fun and learn lots!
--------------------------------------------------------------------------------
via: http://readwrite.com/2014/04/09/raspberry-pi-projects-ssh-remote-desktop-static-ip-tutorial#feed=/hack&awesm=~oB1b7zvteUQGOV
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://readwrite.com/2014/03/04/raspberry-pi-quantified-fish-acquarium#awesm=~oAWz5ZbkX6w7ZL
[2]:http://en.wikipedia.org/wiki/Secure_Shell
[3]:http://www.raspbian.org/
[4]:https://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup/finding-your-pis-ip-address
[5]:http://www.chiark.greenend.org.uk/~sgtatham/putty/
[6]:http://en.wikipedia.org/wiki/Daemon_(computing)
[7]:https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address
[8]:http://raspberrywebserver.com/serveradmin/get-your-raspberry-pi-web-site-on-line.html
[9]:http://portforward.com/help/portforwarding.htm
[10]:http://www.belkin.com/us/support-article?articleNum=10790
[11]:http://kb.netgear.com/app/answers/detail/a_id/24046/~/how-do-i-configure-port-forwarding-on-routers-with-the-netgear-genie-interface%3F
[12]:http://kb.linksys.com/Linksys/ukp.aspx?pid=80&vw=1&articleid=21470
[13]:http://en.wikipedia.org/wiki/Dynamic_DNS
[14]:http://sourceforge.net/p/ddclient/wiki/Home/
[15]:https://www.dnsdynamic.org/
[16]:http://dnsdynamic.blog.com/2011/06/26/using-ddclient-with-dnsdynamic/
[17]:http://readwrite.com/2014/01/21/raspberry-pi-great-projects#feed=/search?keyword=raspberry+pi&awesm=~oAWzuuuChYu9vm

View File

@@ -0,0 +1,138 @@
5个指引提升你的树莓派项目
> 从SSH到端口转发这些先进技术将使树莓派的发展轻松前进。
当你命令行输入命令时你将不再是一个新手在做一些陌生的设置了。虽然进度缓慢但是你正在通过你的方式去学习使用这廉价的信用卡尺寸的大计算机去满足一些DIY想法这就是树莓派。
> 然而在基础和中间的东西之间还是存在较大差距。当你从“设置你的派”的教程例如“创建一个媒体服务器”前期项目的需求就变得有点冒险了。许多中级的Pi教程包括其中的一些读写操作例如一些关于树莓派的安装设置。 并非每一个项目都需要教程里的所有建议,但是知道这些步骤可以使项目更顺利地贴合需求。当你准备超越基础知识时,这里有一些关于树莓派的教程将提前为你准备。
### 1) Using SSH ###
使用SSH登录
SSH代表Secure Shell是一种加密网络协议用于安全地传输你的计算机与树莓派之间的数据。项目中也许需要你通过计算机的命令行而不是直接通过链接显示器和键盘来实现。如今SSH已经提前安装在树莓派系统中所以如果你安装的是最新版本或者接近最新版本的树莓派都是支持SSH使用的。
如何使用SSH第一你需要知道你的派的IP地址在你的派中输入一下命令
sudo ifconfig
你的IP地址将会在第一段或者第三段显示这主要看你的树莓派是通过线缆还是通过WIFI适配器连接网络的。如果是通过线缆连接那请查看第一段在“eth0”那行开始显示。如果是通过wifi链接将在第三段“wlan0”开头的地方显示。
无论通过哪种方式你将会看到以“inet addr”开头后面跟着像192.168.2.2这样类型的IP地址这是我们在这篇文章中经常引用到的一种默认IP地址格式。
现在你有一个可以链接树莓派与你的电脑的IP地址了如果你使用的是Mac你已经建立了SSH链接启动你的终端应用并输入
ssh pi@192.168.2.2
连接之后将会要求输入密码默认情况下密码一般是“respberry”.如果你修改了默认密码,请输入新的密码取而代之。这样,您将进入树莓派系统。
如果你在一台PC那这是一个多余的步骤。
下载并运行PuTTY或者另一种支持Windows系统的SSH客户端。输入你的IP地址在空格 中如一下截图所示。将默认端口设置成22.点击enterPuTTY将会提示你输入用户名和密码。填完之后将可以开始在你的Pi里远程工作了。
### 2) Remote Desktop Your Raspberry Pi ###
使用远程桌面工具到你的树莓派
使用SSH去从命令行远程控制你的Pi是极好的但是如果你想通过图形界面去管理你的Pi。幸运的是MAC和PC都已经建立了这种接口。
在你的树莓派中的命令行当然你也可以通过SSH来操作输入
sudo apt-get install xrdp
Xdrp是一种在可以在后台运行的计算机守护进程并可以在Mac和PC中支持微软远程桌面客户端。通过一旦在树莓派中安装了你的MAC或者PC将可以通过客户端登录到Pi中。
找到你电脑中一个叫远程桌面的客户端。它本身是不完全隐藏起来的,但不会隐藏在应用程序的文件夹中。
出现提示时输入你的IP地址。接下来会弹出xrdp窗口提示你输入用户名和密码。
如果进展顺利,你的树莓派桌面就会在你的窗口或者在电脑屏幕上显示。
### 3) Static IP For Your Pi On The Home Network ###
在您的同网段给树莓派设置静态IP地址
我们发现如第一步所说很容易就可以管理树莓派但是不能保证你的路由器会一直给你的树莓派分配一个永久固定的IP地址。这意味着在你网段中的计算机无法知道树莓派被分配了什么IP地址。那么如何来给树莓派分配静态的IP地址而不是每隔几天就在树莓派上执行“sudo ifconfig”命令有时候情况糟糕几个小时就更变了一次IP。
可想而知我们从“ifconfig”命令开始所以输入
sudo ifconfig
拿出笔和纸做准备记录下面的三个IP地址。#后面的代码是注释,不会在显示.
inet addr: 192.168.2.2 # Pi's Current IP Address
Bcast: 192.168.0.255 # The Broadcast IP Range
Mask: 255.255.255.0 # Subnet Mask Address
此外你还需要知道另外2个信息。请输入一下命令获取网关和目的地址。
netstat -nr
接下来去查看你路由器上的配置。如何进行这一步主要取决于你用什么路由器所以还是查看下说明书吧找出你的设备通过DHCP设置了哪段ip地址。有些地址是被禁止使用的因为有些协议中已经使用了。所以要选择没有被使用过的例如192.168.2.2.你的路由器会保留一个未使用的IP地址分配给想树莓派这样的设备。如果你的路由器是Belkin那大概就是这样
如果不是你需要让树莓派知道它的新的ip地址。我们通过nano编辑器来编辑树莓派中相关的文件。
sudo nano /etc/network/interfaces
将“iface eth0 inet dhcp”这一段修改成“iface eth0 inet static”也就是将动态获取IP修改成静态IP。
接下来输入如下将下列X取代成你之前所复制的IP地址。最上面的地址是我们将要把DHCP中没有使用的IP地址分配作为树莓派的静态IP地址。
address 192.168.2.2
netmask XXX.XXX.XXX.X
network XXX.XXX.X.X
broadcast XXX.XXX.X.X
gateway XXX.XXX.X.X
使用“sudo reboot”的命令重启树莓派系统后再命令行在再输入“ifconfig”我们刚刚新设置的静态IP设置就会呈现。
### 4) Forwarding Ports To Raspberry Pi ###
端口转发至树莓派
一些Pi程序可能需要你转发一个特定的网络端口号到你的树莓派。端口是信息在互联网传送的虚拟路径。有时候你需要转发一个端口来使像树莓派的计算机可以访问互联网即使绕过了路由器。这种情况有点像拨电话在网络上的延升。
端口转发能够用于像树莓派网页服务器树莓派的IP语音服务器或者简单的点对点下载。奖金65000个端口可供选择你可以分配不同的端口给不同的树莓派项目用来进行通信。
默认情况下某些端口代表着特定的应用。例如80端口默认为HTML页面21端口默认代表文件传输协议1194端口默认为设置VPN服务器。所以大多情况下你需要选择一些没有被默认制定的端口号来设置。
设置端口转发的方法完全取决于你的路由器,于是很难创建一个固定的关于设置端口转发教程。你只能阅读你路由器的说明书来定义端口和转发了。
下面链接了几个主流路由器厂商的端口转发教程。
- [Belkin][10]
- [Netgear][11]
- [Linksys][12]
### 5) Static IP For Your Pi On The Internet ###
在网络中给你的Pi设置静态IP
再次声明如果你的运营商给了你一个静态IP你就不需要担心这个部分了。
我们已经给树莓派设置了一个静态的内部IP地址这意味着在你的内部网络中总是能够连到你的树莓派。但是如果程序需要树莓派连接到互联网呢如果你想要在你的树莓派上搭建一个Web服务器在你网络之外的人们需要知道你的Pi在哪里这意味着我们要来设置一个像静态IP的公有IP地址。
我之所以说“看起来像”是因为我们已经设置了一个伪静态IP地址。通常你所在的运营商将会继续更变。所以每一次有人连接到你的树莓派时将要重新写脚本时都会发现得树莓派已经移动我们需要重新更改新的IP地址。
我们是可以通过DDNS即动态DNS,这可以保持一个名称服务器得到实时更新相关程序和树莓派就通过DDNS保持相对应。
首先需要注册一个动态的主机服务。根据指示并创建新的名称服务器类似Yourserver.dnsdynamic.com.
接下来进入树莓派中的命令行根据下面命令来安装DDNS客户端
sudo apt-get install ddclient
我们需要编辑DDNS客户端配置更改新的名称服务器
sudo nano /etc/ddclient/ddclient.conf
每种服务配置都会有略微的不同但是DDNS网址会告诉你需要配置相关文件中的内容。一个标准的DDNS配置将会举例可以从中复制和粘贴。
由于这个文件的存在你所在的运营商将不会停止更新树莓派的IP地址因此我们需要设置一个守护进程在脚本的最前面以确保检查IP地址是否已经更改。
daemon=600
# check every 600 seconds
这里设置的是每10分钟检查一次这里只是一个练习。如果你设置成每秒钟检查一次你的动态服务器应该不会接受因为这样就像扔垃圾邮件到服务器。同事按下ctrl+x保存并退出配置文件。
接下来,输入:
ddclient
只需要输入程序的名称就可以运行了。当你的树莓派开着的时候就会持续运行了。如果你重启树莓派,键入 “ddclient”就会重新开始运行了。
现在你的树莓派已经被装修一番和准备了更高级的教程了,请从中获得更多乐趣吧!
--------------------------------------------------------------------------------
via: http://readwrite.com/2014/04/09/raspberry-pi-projects-ssh-remote-desktop-static-ip-tutorial#feed=/hack&awesm=~oB1b7zvteUQGOV
译者disylee(https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://readwrite.com/2014/03/04/raspberry-pi-quantified-fish-acquarium#awesm=~oAWz5ZbkX6w7ZL
[2]:http://en.wikipedia.org/wiki/Secure_Shell
[3]:http://www.raspbian.org/
[4]:https://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup/finding-your-pis-ip-address
[5]:http://www.chiark.greenend.org.uk/~sgtatham/putty/
[6]:http://en.wikipedia.org/wiki/Daemon_(computing)
[7]:https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address
[8]:http://raspberrywebserver.com/serveradmin/get-your-raspberry-pi-web-site-on-line.html
[9]:http://portforward.com/help/portforwarding.htm
[10]:http://www.belkin.com/us/support-article?articleNum=10790
[11]:http://kb.netgear.com/app/answers/detail/a_id/24046/~/how-do-i-configure-port-forwarding-on-routers-with-the-netgear-genie-interface%3F
[12]:http://kb.linksys.com/Linksys/ukp.aspx?pid=80&vw=1&articleid=21470
[13]:http://en.wikipedia.org/wiki/Dynamic_DNS
[14]:http://sourceforge.net/p/ddclient/wiki/Home/
[15]:https://www.dnsdynamic.org/
[16]:http://dnsdynamic.blog.com/2011/06/26/using-ddclient-with-dnsdynamic/
[17]:http://readwrite.com/2014/01/21/raspberry-pi-great-projects#feed=/search?keyword=raspberry+pi&awesm=~oAWzuuuChYu9vm