文档章节

树莓派变身智能无线路由器

素人派
 素人派
发布于 2015/07/22 07:55
字数 911
阅读 53
收藏 0
  • 选购合适的无线网卡
进过我测试的网卡包括:腾达(TENDA)、360随身wifi 通过lsusb命令可以看到USB接口的网卡型号,可能类似如下: Ralink Technology, Corp. RT5370 Wireless Adapter
  • 安装软件
apt-get update apt-get upgrade apt-get install hostapd dhcpd hostapd是用于AP用户认证的守护进程 udhcpd是用于提供DHCP服务
  • 配置dhcp
/etc/udhcpd.conf [codesyntax lang="java"]
# Sample udhcpd configuration file (/etc/udhcpd.conf)

# The start and end of the IP lease block

start		192.168.19.20	#default: 192.168.0.20
end		192.168.19.254	#default: 192.168.0.254


# The interface that udhcpd will use

interface	wlan0		#default: eth0


# The maximim number of leases (includes addressesd reserved
# by OFFER's, DECLINE's, and ARP conficts

#max_leases	254		#default: 254


# If remaining is true (default), udhcpd will store the time
# remaining for each lease in the udhcpd leases file. This is
# for embedded systems that cannot keep time between reboots.
# If you set remaining to no, the absolute time that the lease
# expires at will be stored in the dhcpd.leases file.

remaining	yes		#default: yes


# The time period at which udhcpd will write out a dhcpd.leases
# file. If this is 0, udhcpd will never automatically write a
# lease file. (specified in seconds)

#auto_time	7200		#default: 7200 (2 hours)


# The amount of time that an IP will be reserved (leased) for if a
# DHCP decline message is received (seconds).

#decline_time	3600		#default: 3600 (1 hour)


# The amount of time that an IP will be reserved (leased) for if an
# ARP conflct occurs. (seconds

#conflict_time	3600		#default: 3600 (1 hour)


# How long an offered address is reserved (leased) in seconds

#offer_time	60		#default: 60 (1 minute)

# If a lease to be given is below this value, the full lease time is
# instead used (seconds).

#min_lease	60		#defult: 60


# The location of the leases file

lease_file	/var/lib/misc/udhcpd.leases	#defualt: /var/lib/misc/udhcpd.leases

# The location of the pid file
#pidfile	/var/run/udhcpd.pid	#default: /var/run/udhcpd.pid

# Everytime udhcpd writes a leases file, the below script will be called.
# Useful for writing the lease file to flash every few hours.

#notify_file				#default: (no script)

#notify_file	dumpleases	# <--- useful for debugging

# The following are bootp specific options, setable by udhcpd.

#siaddr		192.168.0.22		#default: 0.0.0.0

#sname		zorak			#default: (none)

#boot_file	/var/nfs_root		#default: (none)

# The remainer of options are DHCP options and can be specifed with the
# keyword 'opt' or 'option'. If an option can take multiple items, such
# as the dns option, they can be listed on the same line, or multiple
# lines. The only option with a default is 'lease'.

#Examles
opt	dns	192.168.19.1 192.168.18.1
option	subnet	255.255.255.0
opt	router	192.168.19.1
opt	wins	192.168.10.10
option	dns	129.219.13.81	# appened to above DNS servers for a total of 3
option	domain	local
option	lease	864000		# 10 days of seconds


# Currently supported options, for more info, see options.c
#opt subnet
#opt timezone
#opt router
#opt timesrv
#opt namesrv
#opt dns
#opt logsrv
#opt cookiesrv
#opt lprsrv
#opt bootsize
#opt domain
#opt swapsrv
#opt rootpath
#opt ipttl
#opt mtu
#opt broadcast
#opt wins
#opt lease
#opt ntpsrv
#opt tftp
#opt bootfile
#opt wpad

# Static leases map
#static_lease 00:60:08:11:CE:4E 192.168.0.54
#static_lease 00:60:08:11:CE:3E 192.168.0.44
static_lease CC:07:AB:4F:97:F7 192.168.19.2
static_lease 68:17:29:43:D2:4E 192.168.19.3
[/codesyntax]
  • 配置网卡
/etc/network/interfaces [codesyntax lang="php"]
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
address 192.168.1.123
netmask 255.255.255.0
gateway 192.168.1.1

auto wlan0
iface wlan0 inet static
address 192.168.19.1
netmask 255.255.255.0
#gateway 192.168.19.1
#allow-hotplug wlan0
[/codesyntax]  
  • 配置AP
/etc/hostapd/hostapd.conf [codesyntax lang="php"]
interface=wlan0
driver=nl80211
ssid=suren_pi
hw_mode=g
channel=6
auth_algs=1
ignore_broadcast_ssid=0

wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

#wpa=1
#wpa_passphrase=surenyufu
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP
#rsn_pairwise=CCMP

macaddr_acl=0
accept_mac_file=/etc/hostapd/hostapd.accept
deny_mac_file=/etc/hostapd/hostapd.deny
[/codesyntax]  
  • 配置数据包转发
echo 1 > /proc/sys/net/ipv4/ip_forward 在/etc/rc.local中添加如下代码: iptables-restore /etc/hostapd/ip_ruler 以下是文件/etc/hostapd/ip_ruler的内容 [codesyntax lang="php"]
# Generated by iptables-save v1.4.14 on Thu Jul  3 09:31:08 2014
*nat
:PREROUTING ACCEPT [193:31412]
:INPUT ACCEPT [49:4920]
:OUTPUT ACCEPT [70:4419]
:POSTROUTING ACCEPT [1:108]
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Thu Jul  3 09:31:08 2014
# Generated by iptables-save v1.4.14 on Thu Jul  3 09:31:08 2014
*filter
:INPUT ACCEPT [794:69937]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [611:63929]
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
COMMIT
# Completed on Thu Jul  3 09:31:08 2014
[/codesyntax] 注意:上面的eth0是可以上网的网卡名称,wlan0是要分配ip地址的网卡名称,实际中要做相应的修改。
  • 服务启动
service hostapd restart service udhcpd restart
  • 功能验证
到此时,你就可以通过手机或者笔记本连接到suren的wifi了。

本文转载自:http://surenpi.com/2015/03/05/%e6%a0%91%e8%8e%93%e6%b4%be%e5%8f%98%e8%ba%ab%e6%99%ba%e8%83%bd%e6%...

上一篇: SLF4J
素人派
粉丝 26
博文 1907
码字总数 10223
作品 6
东城
程序员
私信 提问
网线直连树莓派及其利用笔记本共享上网的步骤

1.无线网络连接设置为 IP:192.168.0.58 子网掩码:255.255.255.0 默认网关:192.168.0.10(路由器地址) 本地连接属性设置为: IP:192.168.0.1(貌似要结尾是.1树莓派才能上网) 子网掩码:...

Okimbin
2014/02/14
0
0
搭载Wi-Fi和蓝牙的树莓派三代,仅售229软妹币

别看树莓派小,这家伙的粉丝可一点都不少,日前树莓派推出了新款的树莓派3,换装了全新的处理器,此外,它还顺应民意搭载了Wi-Fi和蓝牙,售价依然走亲民路线,仅售35美元(约合人民币229元)...

大壮旅
2016/03/01
0
0
借助树莓派自己写代码突破联通对80端口的封锁

  *本文作者:xutiejun,本文属 FreeBuf 原创奖励计划,未经许可禁止转载。   为了方便管理家里的无线路由器,特意在无线路由器的设置里开通了外网访问功能,但最新发现外网无论如何也无...

FreeBuf
2018/08/07
0
0
Raspberry Pi 快速入门

最近 我购买并安装好了第二块树莓派系统,下列购买清单将对你购买树莓派有所帮助。 Parts List RaspberryPi - 512MB version Enclosure for the RaspberryPi - Clear and contains cutous f...

oschina
2013/01/06
1K
0
树莓派+一根网线直连笔记本电脑

用网线直连电脑,不经过路由器。这个方法最大的特点用最少的工具玩树莓派。 一、材料:树莓派一部、网线一根,笔记本电脑一台。 1、树莓派:带供电系统和烧好Raspbian系统的SD卡; 2、网线:...

maweitao
2014/07/31
0
1

没有更多内容

加载失败,请刷新页面

加载更多

【阴阳师】真蛇10层记录

蛇切黑体系 追月神 散件一速,速度越高越好(220+) 镰鼬 招财二速,速度211以上; 山兔 火灵三速,速度180-200均可; 丑女 心眼四速,速度170左右即可; 大蛇 蚌精暴击套。速度高于阴阳师即...

Areya
昨天
4
0
js动态设置元素高度

this.$refs.xxx.style.height= this.contentHeight; 元素需要绑定

Carbenson
昨天
2
0
今天的学习

今天学到了ci框架中的查询语句的where条件语句: 1、$this->db->select('')->from('')->where('id = ??')->get()->result_array();2、$this->db->select('')->from('')->where('id', '??'......

墨冥
昨天
2
0
MySQL在高并发下的订单撮合、系统使用、共享锁与排他锁保证数据一致性

前序 距离上次择文发表,两月余久。2018年也即将要结束了,目前的工作依然是与区块链应用相关的,也很荣幸在9月初受邀签约出版暂名为《区块链以太坊DApp实战开发》一书,预计在明年年初出版。...

我最喜欢三大框架
昨天
2
0
深入理解Flutter多线程

该文章属于<简书 — 刘小壮>原创,转载请注明: <简书 — 刘小壮> https://www.jianshu.com/p/54da18ed1a9e Flutter默认是单线程任务处理的,如果不开启新的线程,任务默认在主线程中处理。 ...

刘小壮
昨天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部