首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >关于 hostapd[通俗易懂]

关于 hostapd[通俗易懂]

作者头像
全栈程序员站长
发布于 2022-08-26 01:35:06
发布于 2022-08-26 01:35:06
3.1K00
代码可运行
举报
运行总次数:0
代码可运行

大家好,又见面了,我是你们的朋友全栈君。

关于 hostapd

主页: http://w1.fi/hostapd/

hostapd是一个IEEE 802.11的AP和IEEE 802.1X/WPA/WPA2/EAP/RADIUS验证器.此页面用于怎么在linux系统下使用它.其他操作系统请参考hostapd主页

就Linux而言,版本只能使用以下3个包

所有的基于mac80211的驱动实现AP功能被hostapd’s nl80211 驱动支持

The mac80211 子系统将所有的master模式已经移到用户空间.通过hostapd去处理客户端验证,设置加密密钥,建立密钥转化策略,以及无线公共部分的其他方面. 由此,老的使用’iwconfig <wireless interface> mode master’的方法已经不能使用了. 用户空间程序像hostapd目前使用netlink (the nl80211 driver)去创建master mode接口实现通信,monitor mode接口实现接收和发送管理框架

获得hostapd

Using your distributions hostapd

在编译和安装你的拷贝之前尝试发行版本是很明智的.这将让你以后的干礼轻松,如果你的版本大于0.6.8或更新,你通过简单配置hostapd-minimal.conf文件来进行测试:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=test
channel=1

如果上述配置出现以下错误:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
hostapd $ sudo hostapd ./hostapd-minimal.conf
Configuration file: ./hostapd-minimal.conf
Line 2: invalid/unknown driver 'nl80211'
1 errors found in configuration file './hostapd-minimal.conf'

那就意味着你的hostapd不支持nl80211,你将需要按以下操作编译。如果正常,你可以跳转到配置hostapd章节

下载和编译hostpad

使用基于nl80211的hostapd需要你有至少libnl-1.0 pre8或更新的 genl版本,nl80211依赖Generic Netlink. 大多数发行版都自带有这个或者更新的.在fedora或其它开发包和安装包分开发行版编译 时,你需要libnl-devel 包

使用下面命令在线获取hostapd:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
git clone git://w1.fi/srv/git/hostap.git
cd hostap/hostapd

也可以使用下面的命令

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
wget http://w1.fi/releases/hostapd-x.y.z.tar.gz
tar xzvf hostapd-x.y.z.tar.gz
cd hostapd-x.y.z/hostapd

然后,我们需要在编译时配置enable nl80211支持.复制defconfig为.config,并编辑它.另外这里还有一些其他选项你可以开启支持,如果你的硬件支持,你可以开启802.11n支持. 大多数其他的加密类型和特性在大多数应用程序是不需要的,因此你可以自行考虑是否开启支持.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
cp defconfig .config
vi .config

找到如下行:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#CONFIG_DRIVER_NL80211=y

取消’#’.同样根据你的要求配置其他选项.基本上,只要配置这行就足够让hostapd运行WPA/WPA2 验证和加密

编译:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
make

如果出现以下错误:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
driver_nl80211.c:21:31: warning: netlink/genl/genl.h: No such file or directory
driver_nl80211.c:22:33: warning: netlink/genl/family.h: No such file or directory
driver_nl80211.c:23:31: warning: netlink/genl/ctrl.h: No such file or directory
driver_nl80211.c:24:25: warning: netlink/msg.h: No such file or directory
driver_nl80211.c:25:26: warning: netlink/attr.h: No such file or directory

你需要安装或更新libnl0.6.8或更新.如果成功,尝试配置.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
hostapd # ./hostapd ./hostapd-minimal.conf
Configuration file: ./hostapd-minimal.conf
Using interface wlan1 with hwaddr 00:0d:0b:cf:04:40 and ssid 'test'

如果像例子那样的显示,就可以配置hostapd. 如果出现其他错误,重新上述编译.如果出现以下错误:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Hardware does not support configured mode
wlan0: IEEE 802.11 Hardware does not support configured mode (2)
Could not select hw_mode and channel. (-2)
wlan0: Unable to setup interface.
rmdir[ctrl_interface]: No such file or directory

说明你设置了硬件不支持的hw_mode (a, b or g).

配置hostapd

Establishing Baseline for Configuration

配置之前,你需要了解客户端的能力.不是所有的设备都支持所有的你实现的方法,因此基准配置需被确定 . 你也需要了解你所在地区的channel上有最少的其他APs.当选择哪个channel使用,需要记住的是在20MHz内,channels和其他channels将会重叠 .

例如,你需要确定以下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Encryption: wpa-psk + tkip
Wireless Mode: g
Normal for an environment that has to support semi legacy devices, that don't support ccmp or wpa2
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Encryption: wpa2-psk + ccmp
Wireless Mode: g+n
Normal for an environment that has only up to date hardware and software
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Encryption: wep
Wireless Mode: b
This is the works case scenario, as wep is broken and can be trivially cracked.  Don't consider this as anything more than keeping casual free loaders out.

一旦你确定的基准,你便可以开始编辑hostapd.conf:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Common Options: options that you will probably want to set
Additional Options: options that are likely useful to at least know you have
Extra Options: options that you aren't likely to need for most setups

Common Options

使用nl80211的最基本的配置选项在hostapd-minimal.conf已经提供,此配置不使用加密,不在意频段,在现实中不会这样.

首先,我们将设置无线接口,然后无线环境,最后加密.

Wireless Interface

设置概要:

  • interface:告诉hostapd使用的无线接口
  • bridge: 网络桥接口
  • driver: nl80211

如果你只有一个无线接口,并准备用它来桥接有线接口,一个例子如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
interface=wlan0
bridge=br0
driver=nl80211
Wireless Environment

设置概要:

  • ssid: 设置名字(SSID = service set identifier) ,老版本(iwconfig)叫”essid“.
  • hw_mode: 设置操作mode,channels.有效的值取决于硬件,通常:a, b, g
  • channel:设置hostapd操作的channel.

ssid很容易配置..

hw_mode需要你的硬件支持.’g’大多数都支持, 并向前兼容802.11b..

channel应该与其他AP被选择在 20mhz (4 channels)之外,或者每边10mhz (2 channels).这就意味着一个在channel 3的一个AP将干涉channel 1或者channel 5的AP.选择一个channel.通常用户的APs默认channel 6, 因此你使用channel 1或channel 11大多数情况下最佳. channels也依赖于本地规则.

例如:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
ssid=MyNetwork
hw_mode=g
channel=1

802.11n 设置概要

802.11n在上述构建中添加了额外的功能 如果你的硬件不支持802.11n,或者你不打算用它,可以忽略

  • ieee80211n: 设置1开启802.11n,0禁用
  • ht_capab: 你设备的802.11n特性清单

可以使用 ‘iw list’查看你设备的能力

例如:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
wme_enabled=1
ieee80211n=1
ht_capab=[HT40+][SHORT-GI-40][DSSS_CCK-40]

Authentication and Encryption

hostapd有大量的验证和加密选项. 以下介绍基本的加密wep/wpa/wpa2和其他选项.

设置概要:

  • macaddr_acl: MAC地址过滤. .
  • auth_algs: 加密字段, (1) 打开授权,(2) 共享授权(wep)(3).
  • ignore_broadcast_ssid: 开启或禁用广播ssid.
  • wpa: 类似auth_algs.first bit允许wpa1 (1), 第二位允许wpa2 (2), 都允许(3)
  • wpa_psk/wpa_passphrase: These establish what the pre-shared key will be for wpa authentication.
  • wpa_key_mgmt: This controls what key management algorithms a client can authenticate with.
  • wpa_pairwise: This controls wpa’s data encryption
  • rsn_pairwise: This controls wpa2’s data encryption

First, scratch macaddr_acl and ignore_broadcast_ssid from your priorities as they only enhance security (and even then, only slightly). Also, WEP has been effectively broken now, so unless you HAVE to support wep, scratch that from your list. This just leaves wpa/wpa2. Per the draft standard, wpa2 is required for 802.11n, and as there are known attacks on wpa now, wpa2 is the recommended authentication and encryption suite to use. Fortunately, you can have both enabled at once. If Windows clients are going to be connecting, you should leave ccmp encryption out of the wpa_pairwise option, as some windows drivers have problems with systems that enable it.

A good starting point for a wpa & wpa2 enabled access point is:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=YourPassPhrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

If, alternately, you just want to support wpa2, you could use something like:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=YourPassPhrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

That should be all of the settings that you’ll need to change for a basic, secure, access point using hostapd with an AP enabled mac80211 driver.

Additional Options

Extra Options

Dynamic VLAN tagging

hostapd can be configured to move STAs into separate VLANs based on RADIUS tunnel attributes (as specified in RFC3580, http://tools.ietf.org/html/rfc3580#section-3.31):

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Tunnel-Type=VLAN (13)
Tunnel-Medium-Type=802
Tunnel-Private-Group-ID=VLANID

To enable dynamic VLAN tagging the following options in hostapd.conf need to be set:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
dynamic_vlan=1
vlan_file=/etc/hostapd.vlan

A value of 0 disables dynamic VLAN tagging, a value of 1 allows dynamic VLAN tagging and a value of 2 will reject the authentication if the RADIUS server does not provide the appropriate tunnel attributes.

Furthermore, hostapd needs to know how the VLAN interfaces should be named, this is done through an additional config file as specified in vlan_file.

Example /etc/hostapd.vlan:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1       wlan0.1
*       wlan0.#

This will create a wlan0.1 interface on top of wlan0 and move all STAs with the RADIUS supplied vlantag 1 to that interface. The second entry is used to dynamically create VLAN interfaces on top of wlan0, hostapd will create an interface wlan0.vlantag for each different vlantag as supplied by the RADIUS server. For example, if a STA associates and the RADIUS server attributes contain the vlantag 100 hostapd will create a wlan0.100 interface and map the STA to this new interface.

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/143399.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年5月1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
hostapd 配置「建议收藏」
hostapd is an IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator. This page is dedicated to the Linux documentation of it’s implementation and use. Please refer to the hostapd home page for information for other Operating Systems. As far a Linux is concerned, out of the old drivers you can only use these 3 drivers with hostapd: HostAP madwifi prism54 All new mac80211 based drivers that implement AP functionality are supported with hostapd’s nl80211 driver. The mac80211 subsystem moves all aspects of master mode into user space. It depends on hostapd to handle authenticating clients, setting encryption keys, establishing key rotation policy, and other aspects of the wireless infrastructure. Due to this, the old method of issuing ‘ iwconfig <wireless interface> mode master’ no longer works. Userspace programs like hostapd now use netlink (the nl80211 driver) to create a master mode interface for your traffic and a monitor mode interface for receiving and transmitting management frames. Getting hostapd Using your distributions hostapd It is advisable to try your distributions version of hostapd before taking the time to compile and install your own copy. This will make future maintenance easier as you’ll be able to use the init scripts shipped by the distro and hostapd will be updated by it as well. If your distribution ships 0.6.8 or later, you can test with this bare minimum config by creating the file hostapd-minimal.conf: #change wlan0 to your wireless device interface=wlan0 driver=nl80211 ssid=test channel=1 If that config errors out with something like: hostapd $ sudo hostapd ./hostapd-minimal.conf Configuration file: ./hostapd-minimal.conf Line 2: invalid/unknown driver ‘nl80211’ 1 errors found in configuration file ‘./hostapd-minimal.conf’ that means that your distro is not shipping hostapd with nl80211 driver support and you’ll need to follow the building instructions that follow. If it works, you can skip down to the configuring hostapd secti
全栈程序员站长
2022/08/31
1.4K0
hostapd配置解析「建议收藏」
转载自:老丁的Linux:http://laoding.blog.51cto.com/980622/1697015
全栈程序员站长
2022/08/31
4.9K0
hostapd 移植和使用[通俗易懂]
它实现了IEEE 802.11相关的接入管理,IEEE 802.1X/WPA/WPA2/EAP 认证, RADIUS客户端,EAP服务器和RADIUS 认证服务器。
全栈程序员站长
2022/08/31
4.1K0
嵌入式Linux开发板_WIFI无线网卡驱动移植
有线就插上网线,没什么好说的;无线的话一种是将WIFI模块集成焊接在板子上,另一种是WIFI模块以USB的方式接到板子上。
韦东山
2020/09/30
8.5K0
嵌入式Linux开发板_WIFI无线网卡驱动移植
通过 Hostapd 进行 WIFI 热点共享上网
最近发现自己的Debian之前可以使用GNOME3下的networkmanager进行WIFI共享上网功能因为内核升级导致无法使用。无奈只好再次通过Hostapd来进行WIFI热点设置,同时为了更块的DNS解析,本次顺便也在本地安装了dnsmasq软件实现了本地化的DNS查询服务,成功恢复了我的小本本作为热点的能力。总结方法如下:
Debian中国
2018/12/20
5.7K0
嵌入式系统中启动Hostapd
项目过程中需要添加AP热点的需求,自然会想用到hostapd,具体的不做分析,自行百度,这里主要分析下启动脚本
程序手艺人
2019/02/21
2K0
嵌入式系统中启动Hostapd
项目过程中需要添加AP热点的需求,自然会想用到hostapd,具体的不做分析,自行百度,这里主要分析下启动脚本
全栈程序员站长
2022/08/25
8230
hostapd配置
我们有个闲置的USB无线适配器(WIFI适配器),而我们的ISP路由器却是有线的。怎样把我们的家庭NAS服务器变成无线访问点(WAP),在不用买额外的WPA盒子的情况下,在Debian或Ubuntu系统下使用无线设备访问到它?
全栈程序员站长
2022/08/31
1.9K0
hostapd.conf配置文档「建议收藏」
大家好,又见面了,我是你们的朋友全栈君。##### hostapd configuration file ############################################## # Empty lines and lines starting with # are ignored
全栈程序员站长
2022/09/03
2.5K0
hostapd学习「建议收藏」
hostapd能够使得无线网卡切换为master模式,模拟AP(通常可以认为是路由器)功能,也就是我们说的软AP(Soft AP)。hostapd的功能就是作为AP的认证服务器,负责控制管理stations(通常可以认为带无线网卡的PC)的接入和认证。
全栈程序员站长
2022/08/26
1K0
hostapd.conf详细
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/143200.html原文链接:https://javaforall.cn
全栈程序员站长
2022/08/31
1.2K0
Kali Linux 2025最新WiFi钓鱼
接下来,将无线网卡接入kali,执行命令ifconfig确保正确家中无线网卡wlan0
逍遥子大表哥
2025/07/19
1560
Kali Linux 2025最新WiFi钓鱼
关于 RTL8723BS 同时开启 STA/AP 模式
最近接到一个调试 wifi 驱动的任务,使用的是 rtl8723bs 芯片组。要求是让无线设备工作在 station 模式的时候同时开启一个 ap 热点。简单来讲就是连接其他 wifi 的同时发出一个 wifi 供其他设备使用。保证都能上网。
RainMark
2019/09/10
2.7K6
IoT设备网络数据包抓包改包环境搭建分享
这部分主要还是比较底层的抓包。这里就不过多的介绍了,毕竟好多大神的文章都写的很详细,主要内容还是以第三为主。
FB客服
2020/06/29
3.1K0
IoT设备网络数据包抓包改包环境搭建分享
【WiFi开发全攻略】WIFI常用工具汇总
本节主要介绍我们开发过程中,WiFi常用的开发工具,内容主要介绍工具种类以及基本的使用方法,更多使用可以见后面章节。
董哥聊技术
2024/04/03
4570
【WiFi开发全攻略】WIFI常用工具汇总
robomaster S1(杂文)
这文章,就是个瞎记录的东西。。。 串口的工具,推荐这个~ http://www.xitongzhijia.net/soft/38066.html 功能齐全 这段代码我也忘了是啥了。。。可能是个转换的代码吧 variable_motorSpeed = 0 def start(): global variable_motorSpeed robot_ctrl.set_mode(rm_define.robot_mode_free) while True: variable
云深无际
2021/09/14
6700
robomaster S1(杂文)
树莓派命令连接wifi_树莓派连接无线网wifi配置方法
我的Wifi配置基本上是跟着这个教程来的,下面将过程简述,并解释每个命令/语句的作用。
全栈程序员站长
2022/09/06
3.3K0
树莓派命令连接wifi_树莓派连接无线网wifi配置方法
hostapd_acs 源码分析
Main() ../hostapd/main.c + 552
全栈程序员站长
2022/08/31
1K0
hostapd_acs 源码分析
Kali制作钓鱼WIFI
一、环境准备 0x01 kali虚拟机 0x02 USB无线网卡 二、制作钓鱼WIFI 0x01 接入无线网卡到kali 0x02 配置无线网卡 在终端执行ifconfig查看是否有wlan0如果存在,我们需要激活为监听模式。 ifconfig airmon-ng start wlan0 0x03 配置hostapd vim hostapd.conf interface=wlan0mon driver=nl80211 ssid=Free-Wifi #无线名称 随意即可 hw_
用户6343818
2021/11/12
3.8K0
Kali制作钓鱼WIFI
几种常见网络抓包方式介绍
无论作为网络运维人员,还是安全渗透工程师,在工作中都会无可避免地碰到网络抓包的需求。
天存信息
2021/05/27
3.4K0
几种常见网络抓包方式介绍
相关推荐
hostapd 配置「建议收藏」
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档