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

推荐订阅源

博客园 - 三生石上(FineUI控件)
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
T
Tailwind CSS Blog
T
The Blog of Author Tim Ferriss
U
Unit 42
B
Blog
N
Netflix TechBlog - Medium
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
O
OpenAI News
M
MIT News - Artificial intelligence
D
DataBreaches.Net
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
LINUX DO - 热门话题
C
CERT Recently Published Vulnerability Notes
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
Vercel News
Vercel News
T
Tenable Blog
Security Latest
Security Latest
C
Check Point Blog
云风的 BLOG
云风的 BLOG
PCI Perspectives
PCI Perspectives
月光博客
月光博客
TaoSecurity Blog
TaoSecurity Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Project Zero
Project Zero
雷峰网
雷峰网
IT之家
IT之家
H
Hacker News: Front Page
Microsoft Security Blog
Microsoft Security Blog
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Last Week in AI
Last Week in AI
G
Google Developers Blog
Forbes - Security
Forbes - Security
The Register - Security
The Register - Security
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Martin Fowler
Martin Fowler
K
Kaspersky official blog
P
Proofpoint News Feed
T
Threatpost
Google Online Security Blog
Google Online Security Blog
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - 火腿骑士

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

http://shumeipai.nxez.com/2013/09/11/raspberry-pi-configured-as-a-wireless-router.html

准备拿树莓派做个应用,当作无线路由器,配置的结果就是把树梅派的网络连接通过无线网卡分享出来。做分享的无线网卡当然就不能同时来连接网络了。
实现无线共享需要的软件包是hostapd。raspbian官方安装源提供的hostapd需要无线网卡支持nl80211协议,不是所有的网卡都能配置成功,如果不慎购买了不支持nl80211协议的网卡,需要自行编译适合网卡的hostapd软件包。
因此选用无线网卡的时候要留意,我选用的网卡型号是Tenda w311mi,芯片是Ralink Rt5370 可以完美支持hostapd,同款芯片的都应该可以成功配置。以下是配置全过程。

1.配置无线网卡为固定ip地址
输入命令


sudo nano /etc/network/interfaces
编辑网络配置文件,找到这几行注释掉。


#allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp
添加以下几行。

iface wlan0 inet static
address 192.168.10.1
netmask 255.255.255.0
这里需要说明的是 192.168.10.1是给raspberry pi 做的路由器分配的网关 ip,这个不能跟局域网里其他路由网关ip重复。

2 安装hostapd
输入命令


sudo apt-get install hostapd
编辑hostapd 默认配置文件


sudo nano /etc/default/hostapd
找到

#DAEMON_CONF= ""
修改如下

DAEMON_CONF="/etc/hostapd/hostapd.conf"
编辑 hostapd 配置文件

sudo nano /etc/hostapd/hostapd.conf

# 把无线网卡wlan0 作为接入点
interface=wlan0
# 使用nl80211驱动
driver=nl80211
#共享网络的SSID是RaspberryPi
ssid=RaspberryPi
# 网卡工作在802.11G模式
hw_mode=g
#无线网卡选用11信道
channel=11
# WPA2 配置
wpa=2
#wpa密码是raspberry
wpa_passphrase=raspberry
#认证方式为WPA-PSK 加密方式为CCMP
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
beacon_int=100
auth_algs=3
wmm_enabled=1
保存退出,输入命令。

sudo service hostapd restart
启动hostapd 服务。

3.安装dhcp服务
输入命令


sudo apt-get install isc-dhcp-server
备份配置文件


sudo mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak
编辑新的配置文件

sudo nano /etc/dhcp/dhcpd.conf
复制粘贴以下内容

default-lease-time 600;
max-lease-time 7200;
log-facility local7;

subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.10 192.168.10.100;
option routers 192.168.10.1;
option broadcast-address 192.168.10.127;
option domain-name-servers 8.8.8.8,8.8.4.4;
default-lease-time 600;
max-lease-time 7200;
}
保存退出,重新启动服务。


sudo service isc-dhcp-server restart
这个时候可以在无线网络列表里面连接RaspberryPi,连接成功以后会分配一个IP。

4.配置路由转发
通过前面的配置过程,已经可以通过无线网络连接到Raspberry pi的无线网卡,但是还不能连接到互联网,下一步就是让从无线网卡 wlan0 进来的数据 转发到 有线网卡 eth0上面 通过有线网卡连接网络接到互联网。
因为eth0是获取的动态ip,所以这里通过iptables来实现简单的路由转发。
输入命令


sudo iptables -F
sudo iptables -X
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo bash
iptables-save > /etc/iptables.up.rules
exit
输入命令

sudo nano /etc/network/if-pre-up.d/iptables
把下面两行复制粘贴到编辑窗口


#!/bin/bash
/sbin/iptables-restore < /etc/iptables.up.rules
保存退出,输入命令。

sudo chmod 755 /etc/network/if-pre-up.d/iptables
开启内核转发,输入命令。


sudo nano /etc/sysctl.conf
找到这里。


# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1
去掉 net.ipv4.ip_forward 前面的#,保存退出,输入命令。

sudo sysctl -p
配置完毕 通过无线连接上以后ping一下外网,可以通了,这样就可以把Raspberry Pi 当作路由器来用了。