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

推荐订阅源

The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
Y
Y Combinator Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
博客园_首页
小众软件
小众软件
I
InfoQ
J
Java Code Geeks
月光博客
月光博客
S
Secure Thoughts
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Latest news
Latest news
G
GRAHAM CLULEY
IT之家
IT之家
C
Cisco Blogs
Last Week in AI
Last Week in AI
Engineering at Meta
Engineering at Meta
L
LangChain Blog
The Register - Security
The Register - Security
SecWiki News
SecWiki News
M
MIT News - Artificial intelligence
NISL@THU
NISL@THU
T
Tenable Blog
博客园 - Franky
美团技术团队
I
Intezer
U
Unit 42
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 火腿骑士

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 当作路由器来用了。