[转]Raspberry Pi做成路由器
http://raspjason.blog.51cto.com/8565009/1426561/
曾经看到很多文章把Raspberry Pi制作成无线AP,但是我今天要做的是把Raspberry Pi做成一个有NAT功能的路由器,我做这个的初衷是因为到荷兰出差后发现我的bambook无法接入宿舍里的WiFi,也许是因为宿舍无线路由器是WEP的认证方式,总之死活连不上。后来决定用Raspberry Pi+北极星光无线路由器来解决问题。
思路:
【无线路由器】-----【无线网卡--Raspberry Pi--有线RJ45端口】------【有线RJ45端口--北极星光无线路由器--无线】----Bambook
步骤一:
配置Raspberry Pi的无线网卡与有线网卡
无线网卡通过WEP连到宿舍无线路由器,并配置一个固定IP,有线网卡也配置固定IP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
pi@raspberrypi:~$ cat /etc/network/interfaces auto lo iface lo inet loopback iface eth0 inet static address 172.16.1.100 netmask 255.255.255.0 gateway 172.16.1.1 ######################################### allow-hotplug wlan0 iface wlan0 inet static #wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf #iface default inet dhcp wireless-essid ADSL-WiFi-c91f44 wireless-key 1234567890 address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.254 |
步骤二:
在Raspberry Pi上架设DHCP服务器
1
|
pi@raspberrypi:~$ sudo apt-get install isc-dhcp-server |
编辑dhcp.conf文件
1
|
pi@raspberrypi:~$ sudo vi /etc/dhcp/dhcpd .conf |
在dhcp.conf文件的最后加上以下几行
1
2
3
4
5
|
subnet 172.16.1.0 netmask 255.255.255.0 { range 172.16.1.1 172.16.1.99; option routers 172.16.1.100; option domain-name-servers 8.8.8.8,8.8.4.4; } |
在Raspberry Pi的RJ45口上连上笔记本后测试是否可以分配IP地址
1
2
3
|
pi@raspberrypi:~$ sudo service isc-dhcp-server restart Stopping ISC DHCP server: dhcpd. Starting ISC DHCP server: dhcpd. |
步骤三:
启用Raspberry Pi的路由转发功能,并开启NAT
开启路由转发功能
1
|
pi@raspberrypi:~$ sudo vi /etc/sysctl .conf |
把sysctl.conf里的 net.ipv4.ip_forward=1前的"#"号去掉后保存
开启NAT功能
制作一个开启NAT的脚本,保存为nat
1
2
3
4
|
#!/bin/sh sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT |
运行此脚本
1
2
3
|
pi@raspberrypi:~$ ls | grep nat nat pi@raspberrypi:~$ sh . /nat |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
pi@raspberrypi:~$ sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) target prot opt source destination pi@raspberrypi:~$ sudo iptables -t nat -L Chain PREROUTING (policy ACCEPT) target prot opt source destination Chain INPUT (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain POSTROUTING (policy ACCEPT) target prot opt source destination MASQUERADE all -- anywhere anywhere pi@raspberrypi:~$ |
在/etc/network/目录下创建一个iptables的文件
1
|
pi@raspberrypi:~$ sudo touch /etc/network/iptables |
把iptables内容保存到/etc/network/iptables中
1
|
pi@raspberrypi:~$ sudo sh -c "iptables-save > /etc/network/iptables" |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
pi@raspberrypi:~$ cat /etc/network/iptables # Generated by iptables-save v1.4.14 on Sun Jun 15 05:45:28 2014 *filter :INPUT ACCEPT [22972:1979567] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [2421:275063] -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT -A FORWARD -i eth0 -o wlan0 -j ACCEPT COMMIT # Completed on Sun Jun 15 05:45:28 2014 # Generated by iptables-save v1.4.14 on Sun Jun 15 05:45:28 2014 *nat :PREROUTING ACCEPT [9719:1105033] :INPUT ACCEPT [1273:238753] :OUTPUT ACCEPT [675:88515] :POSTROUTING ACCEPT [219:34192] -A POSTROUTING -o wlan0 -j MASQUERADE COMMIT # Completed on Sun Jun 15 05:45:28 2014 pi@raspberrypi:~$ |
在/etc/network/interfaces上加上一句up iptables-restore < /etc/network/iptables使得每次启动的时候自动生效
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
pi@raspberrypi:~$ cat /etc/network/interfaces auto lo iface lo inet loopback iface eth0 inet static address 172.16.1.100 netmask 255.255.255.0 gateway 172.16.1.1 ######################################### allow-hotplug wlan0 iface wlan0 inet static #wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf #iface default inet dhcp wireless-essid ADSL-WiFi-c91f44 wireless-key 1234567890 address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.254 up iptables-restore < /etc/network/iptables |
保存重启发现连上Raspberry Pi的RJ45口的便携机能自动获取IP地址,并且可以ping通外网了。
[转]Raspberry Pi做成路由器的更多相关文章
- 【树莓派】【转】将树莓派Raspberry Pi设置为无线路由器(WiFi热点AP,RTL8188CUS芯片)
下文为转载,文章转自:http://wangye.org/blog/archives/845/,仅供本次学习实践参考. 最近又开始折腾起Raspberry Pi来了,因为某处上网需要锐捷拨号,于是我就 ...
- RASPBERRY PI wifi配置
Raspberry Pi 手把手教你在树莓派上安装USB无线网卡支持WIFI 树莓派虽然已经有了有线网卡,但是并未配置无线网卡,移动性不够强,好在机器配备了2个USB口,当然要分一个出来给WIFI无线 ...
- Hello Raspberry Pi
Raspberry Pi 入手好一段时间了,原意是想撸 linux,但是后来一整年都在忙孩子房子户口本子的事,这玩意也就搁了一年尘. 最近终于被生活折腾到了尾声,开始找一些东西来折腾折腾. 一.什么是 ...
- 将树莓派Raspberry Pi设置为无线路由器(WiFi热点AP,RTL8188CUS芯片)
http://wangye.org/blog/archives/845/ 最近又开始折腾起Raspberry Pi来了,因为某处上网需要锐捷拨号,于是我就想能不能让我的树莓派代劳,当然首先要将其改造为 ...
- 转:Raspberry Pi(树莓派)试用小记
近期入手一树莓派卡片机,体验了一下它的强大,写篇报告,推广一下哈! 机器截图: 基础参数: CPU:700 MHz, ARM11 内存:512M(还有一种是256M的) 支持GPU加速(高清视频无压力 ...
- Raspberry Pi(树莓派)上从零开始构建Linux系统(简称PiLFS)(一)
一. 准备工作 1. 装有Linux宿主系统的树莓派主板,可参考 Raspberry Pi(树莓派)上安装Raspbian(无路由器,无显示器) 2. 参考网址:Linux From Scratch ...
- 如何在Raspberry Pi 3B中安装RASPBIAN
RASPBIAN简介 RASPBIAN是树莓派官方支持的基于Debian的Linux系统.RASPBIAN预装了很多常用的组件,使用起来十分方便. 官方有RASPBIAN STRETCH WITH D ...
- 树莓派(1)- Raspberry Pi 3B 安装系统并联网
一.背景 昨天到手淘宝买的3B,既然买了就不能让它吃灰,动起来. 二.物料 名称 说明 硬件 树莓派3B 主体 树莓派电源 5V 2A sd卡 4G低速(推荐是16G class10),我手头只有这 ...
- 树莓派3代B型 Raspberry Pi Model 3 B 安装 centos7系统
板子类型: Raspberry Pi Model 3 B 搭配 32G的SD卡: 下载支持树莓派版本的centos7系统 https://buildlogs.centos.org/centos/7/i ...
随机推荐
- 第43讲:Scala中类型变量Bounds代码实战及其在Spark中的应用源码解析
今天学习了scala的界定,先来看看下面这段代码 //class Pair[T] (val first : T,val second : T)class Pair[T <: Comparable ...
- Fire uva 11624
题目连接:http://acm.hust.edu.cn/vjudge/problem/28833 /* 首先对整个图bfs一次得到火焰燃烧的时刻表 之后在bfs搜路径时加一个火烧表的判断 坑点在于:如 ...
- SQLSERVER truncate table之后是否会重置表的自增值
SQLSERVER truncate table之后是否会重置表的自增值 今天清理业务库数据的时候,开发人员说可以使用truncate table把两个表的所有数据清理掉 这两个表都有自增ID,都做了 ...
- Hyper-V的使用方法
win8和win8.1以及win10自带虚拟机,无需再装第三方虚拟机软件. 首先需要在“启用或关闭windows功能”中,启用Hyper-V
- C#的惰性枚举
Ruby 2.0有一个新的特性是惰性枚举器,Soi Mort 的博客举了一个例子:可以将下面的代码 File.open(path) {|fp| fp.each_line. \ select {|lin ...
- 检查密码复杂度的C#正则表达式
在用户注册与修改.重置密码时,强制密码达到一定的复杂度,是减少盗号的有效措施之一. 而在代码中检查密码复杂度就需要用到正则表达式,比如要求密码必须包含数字.小写或大写字母.特殊字符.字符数在8-30之 ...
- Swift 笔记
苹果官方文档 https://developer.apple.com CocoaChina帮助文档 http://www.cocoachina.com/special/swift/ 74个Swift标 ...
- Sqoop2 环境搭建
原文地址:http://www.cnblogs.com/luogankun/p/4209017.html 正在准备做Spark SQL external data source与关系型数据库交互的部分 ...
- [ACM_搜索] ZOJ 1103 || POJ 2415 Hike on a Graph (带条件移动3盘子到同一位置的最少步数 广搜)
Description "Hike on a Graph" is a game that is played on a board on which an undirected g ...
- httpwebrequest 请求压缩,接受压缩的字符流请求
请看图,客户端和服务端都使用gzip压缩. 客户端参数以json字符串形式gzip压缩,以二进制流发送到服务端:服务端接收到请求,解压缩gzip后,进行业务逻辑处理:处理完后在将返回值以json形式, ...