[RBP] RaspberryPi系列之一:Linux下网络配置

1. 引言

买了个RBP玩。等了一个多礼拜才全部到齐。又断断续续折腾了差不多一个礼拜今天才终于看见图像了。

目前的目标是把OpenCV中几个简单的应用跑起,比如人脸识别。主要是网上有很详细的教程,应该很straightforward

2. 配置

camera module是今年5月出的,到现在软件已经比较稳定了。参照官网的步骤一点问题都没有。

3. 其他

因为实验室网络资源的限制,如何把pi折腾上网确实费了些脑筋。

3.0 尝试

先想用mac共享无线网络---和网上大多数例子不同(即mac通过网线连接internet,wifi连接其他设备共享网络),这里只能用mac 无线上网, 然后用网线连接RBP。但如果在systemPreference--->Sharing里选了这个组合,弹出对话框"Your Internet connection cannot be shared because it is protected by 802.1X"。

新一点的mac的例子也有(2013年),

How to setup wireless connectivity on Raspberry Pi (A crossover cable is not necessary

Running Mac OS X's built-in DHCP server

How to connect Raspberry Pi to Internet via Mac

不过第1,2篇应该只是用mac做DHCP Server,要上网还需要在RBP上配置DNS和路由;

或者象第一篇那样在mac上装一个HTTP proxy server (Squidman),然后在RBP上配置apt package manager 

sudo vim.tiny /etc/apt/apt.conf.d/01proxy
Acquire::http::Proxy "http://192.168.33.1:8080";
这样用apt-get来更新firmware,

  
  
  
  
sudo apt-get update
sudo apt-get install --reinstall libraspberrypi-doc  libraspberrypi-dev  libraspberrypi-bin libraspberrypi0 raspberrypi-bootloader
最后在RBP上接一个USB wireless adaptor就可以无线上网---巨麻烦。现在的步骤简单多了

第三篇的配置方法最省事,并且包括了DHCP/DNS/ROUTER等的设置;网络环境跟我的情况最接近,不过看截图他的mac3G connection 应该是用第一篇中说的3G dongle connected to laptop来上网的,而不是通过WiFi


最后还是只有通过PC上网。先在Linux下通过了,W7也应该可以

Ubuntu as a firewall/gateway router

Ubuntu 12.04 IPv4 NAT Gateway and DHCP Server

Using Ubuntu 12.04 as router/firewall (这里面ufw的安装及其配置/etc/default/ufw, /etc/ufw/before.rules是不需要的)

3.1 关键步骤

基本上,4个主要步骤,涉及到修改5个文件

1. /etc/network/interfaces

分别配置连Internet的网卡和内部LAN的网卡

2. 安装DHCP Server dhcp3-server (只是个dummy package, 实际安装isc-dhcp-server)

sudo apt-get install dhcp3-server

sudo aptitude install isc-dhcp-server

然后修改 /etc/dhcp/dhcpd.conf, 主要包括下面几项就可以

ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
option subnet-mask 255.255.255.0;
option broadcast-address 10.10.10.255;
option routers 10.10.10.1;
option domain-name-servers 10.10.10.1;
option domain-name "ubuntu.firewall";
subnet 10.10.10.0 netmask 255.255.255.0 {
range 10.10.10.50 10.10.10.200;
}
然后是  /etc/default/isc-dhcp-server, 

INTERFACES="eth1"
3.  /etc/sysctl.conf

net.ipv4.ip_forward=1

4. 最后配置防火墙iptables。在/etc/rc.local里,

/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables --table nat -A POSTROUTING -o eth0 -j MASQUERADE


3.2 如果不想重启,就需要下面的等价命令

sudo /etc/init.d/networking restart

sudo service isc-dhcp-server stop (if the service is already running; skip if it’s not running)

sudo service isc-dhcp-server start

sudo sysctl -w net.ipv4.ip_forward=1

sudo iptables -P FORWARD ACCEPT

sudo iptables  --table nat -A POSTROUTING -o eth0 -j MASQUERADE

3.3 其其他

Change the Network Card name in Ubuntu 12.04

sudo nano /etc/udev/rules.d/70-persistent-net.rules
Change it exactly the same as we assigned in the  /etc/udev/rules.d/70-persistent-net.rules  file, like  WAN  for  eth0  and  LAN  for  eth1

3.4 升华

折腾了一圈,无意中又看见了 Internet Connection Sharing in Ubuntu 12.04 Precise Pangolin

才发现Linux有更简单的解决方案:在RBP上把PC配置成网关就好了:

PC上:

$ sudo ifconfig eth1 192.168.0.1 netmask 255.255.255.0

then on the device:

$ sudo ifconfig eth0 192.168.0.2 netmask 255.255.255.0

Then set the gateway, pointing to the PC’s address:
$ sudo route add default gw 192.168.0.1

就是完全省去了DHCP-Server的安装/配置和iptables的配置---不知道能行不,whatever!!!





你可能感兴趣的:([RBP] RaspberryPi系列之一:Linux下网络配置)