惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
博客园_首页
GbyAI
GbyAI
罗磊的独立博客
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
U
Unit 42
V
Visual Studio Blog
F
Fortinet All Blogs
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
T
Tor Project blog
Martin Fowler
Martin Fowler
K
Kaspersky official blog
Scott Helme
Scott Helme
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
D
DataBreaches.Net
博客园 - Franky
阮一峰的网络日志
阮一峰的网络日志
博客园 - 【当耐特】
P
Proofpoint News Feed
N
Netflix TechBlog - Medium
美团技术团队
S
Secure Thoughts
C
Cisco Blogs
M
MIT News - Artificial intelligence
L
Lohrmann on Cybersecurity
T
Tenable Blog
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Spread Privacy
Spread Privacy
S
Security @ Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
A
Arctic Wolf
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
O
OpenAI News
V
Vulnerabilities – Threatpost

博客园 - 火腿骑士

webstorm+nodejs+express配置 树莓派raspberry pi配置无线路由器AP 树莓派raspberry pi配置 html5使用canvas实现毫秒级画心电图 html5使用canvas动态画医学设备毫秒级数据波形图 IntelliJ IDEA web项目 工程构建运行部署 H5调用本地摄像头[转] [转]把树莓派配置成无线路由器 websocket for python Linux 升级 Python 至 3.x 防抖(Debounce)与节流( throttle)区别 spring mvc 实战化项目之三板斧 vue开发资料 asp.net mvc 实战化项目之三板斧 [转]gulp构建前端工程 gulp前端自动化构建工具使用 laravel实战化项目之三板斧 免费网络视频监控软件cmsclient awesomes前端资源库网站
[转]Raspberry Pi做成路由器
火腿骑士 · 2016-12-19 · via 博客园 - 火腿骑士

  http://raspjason.blog.51cto.com/8565009/1426561/

曾经看到很多文章把Raspberry Pi制作成无线AP,但是我今天要做的是把Raspberry Pi做成一个有NAT功能的路由器,我做这个的初衷是因为到荷兰出差后发现我的bambook无法接入宿舍里的WiFi,也许是因为宿舍无线路由器是WEP的认证方式,总之死活连不上。后来决定用Raspberry Pi+北极星光无线路由器来解决问题。

wKiom1OlsIvz4mEEAB3G8fMyw1o975.jpg

思路:

    【无线路由器】-----【无线网卡--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

  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 

*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

*nat

:PREROUTING ACCEPT [9719:1105033]

:INPUT ACCEPT [1273:238753]

:OUTPUT ACCEPT [675:88515]

:POSTROUTING ACCEPT [219:34192]

-A POSTROUTING -o wlan0 -j MASQUERADE

COMMIT

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

  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通外网了。