Debian/Ubuntu Linux:使用Hostapd搭建无线访问点(WAP)

您所在的位置:网站首页 如何搭建无线ap Debian/Ubuntu Linux:使用Hostapd搭建无线访问点(WAP)

Debian/Ubuntu Linux:使用Hostapd搭建无线访问点(WAP)

2024-07-04 12:43| 来源: 网络整理| 查看: 265

NIXCRAFT发表于2012年8月25日,在2014年7月9日更新,适用DEBIAN / UBUNTU, 网络, UBUNTU LINUX, 无线网络。

我们有个闲置的USB无线适配器(WIFI适配器),而我们的ISP路由器却是有线的。怎样把我们的家庭NAS服务器变成无线访问点(WAP),在不用买额外的WPA盒子的情况下,在Debian或Ubuntu系统下使用无线设备访问到它?

你需要使用hostapd作为访问点和认证服务器。它实现了IEEE 802.11访问点管理,IEEE802.1X/WPA/WPA2/EAP授权,RADIUS客户端,EAP服务器和RADIUS授权服务器。最新版本支持Linux:

1、Host AP

2、madwifi

3、mac80211-based

你可以使用USB或PCI/Mini-PCI接口的网卡。请注意不是所有的网卡活驱动支持AP模式。

案例安装

1、wlan0 - 连接到Linux的无线PCI或USB设备,在AP模式里能够使用a/b/g和WPA2。

2、eth0 - 有线网卡,端口连接于尚有路由器或交换机,具有internet访问。

案例网络

Internet \ \\ |\ +------------+ RJ-11/ADSL-线路 \-----+ ISP 路由器 | +--------+ +------------+ RJ-45 (eth0) -------+ 交换机| 192.168.1.2 +--------+ 有 DNS/DHCPD | 服务 + +----> 笔记本无线 防火墙 | +----> 家庭 nas 服务器 无线网卡 wlan0 和 eth0 有线网卡 | 配置 192.168.1.11 静态 IP +----> 台式机有线 | +----> HP 打印机有线 | +----> Andriod 平板无线 | +----> Andriod 手机无线等

步骤1: 安装hostapd

输入命令:# apt-get install hostapd

输出示例:

Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: hostapd 0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded. Need to get 346 kB of archives. After this operation, 877 kB of additional disk space will be used. Get:1 http://debian.osuosl.org/debian/ squeeze/main hostapd amd64 1:0.6.10-2 [346 kB] Fetched 346 kB in 2s (151 kB/s) Selecting previously deselected package hostapd. (Reading database ... 267669 files and directories currently installed.) Unpacking hostapd (from .../hostapd_1%3a0.6.10-2_amd64.deb) ... Processing triggers for man-db ... Setting up hostapd (1:0.6.10-2) ...

步骤2: 配置hostadp

编辑 /etc/default/hostapd,键入:

# vi /etc/default/hostapd

去掉DAEMON_CONF 前的注释,并设置它的值为hostapd配置文件的绝对路径,这样hostapd会随系统一起启动:

DAEMON_CONF="/etc/default/hostapd.conf"

保存,关闭文件。接着创建一个文本文件: /etc/hostapd/hostapd.conf,键入:

设接口名称:

### Wireless network name ### interface=wlan0   ### Set your bridge name ### bridge=br0

设驱动名称

driver=nl80211

设国家名称代码,格式遵循ISO/IEC 3166-1格式。这样做用来设定管理域。根据需要设定,以说明设备在哪个国家操作。这会限定可用的频道和发射功率。

### (IN == INDIA, UK == United Kingdom, US == United Stats and so on ) ### country_code=IN

设定你的SSID:

ssid=nixcraft

设定操作模式(a=IEEE 802.11a,  b = IEEE 802.11b, g = IEEE 802.11g):

hw_mode=g

设定频道(有的驱动仅使用值0):

channel=6

设定wpa模式为2:

wpa=2

设定你的密码短语(Wifi连接密码):

wpa_passphrase=MyWiFiPassword

为WPA2设定密钥和认证管理选项

## 密钥管理算法 ## wpa_key_mgmt=WPA-PSK   ## Set cipher suites (encryption algorithms) ## ## TKIP = Temporal Key Integrity Protocol ## CCMP = AES in Counter mode with CBC-MAC wpa_pairwise=TKIP rsn_pairwise=CCMP   ## 共享密钥认证 ## auth_algs=1   ## 接受所有mac访问 ### macaddr_acl=0

保存并关闭这文件。

我怎样启动/停止/重启AP?

使用下列命令:

# /etc/init.d/hostapd start # /etc/init.d/hostapd stop # /etc/init.d/hostapd restart

步骤3: 配置 /etc/network/interfaces

你可以使wlan0工作于独立模式,也可以把它桥接于eth0。桥接模式允许你的无线客户端访问其他的LAN,而且你能够连接到internet。大多数使用者把无线接口桥接到AP有Internnet连接的接口上。

设定br0(wlan0+eth0)为桥接模式

需要安装bridge-utils包来配置Linux网卡桥接:

# apt-get install bridge-utils

输出:

Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: bridge-utils 0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded. Need to get 32.7 kB of archives. After this operation, 176 kB of additional disk space will be used. Get:1 http://debian.osuosl.org/debian/ squeeze/main bridge-utils amd64 1.4-5 [32.7 kB] Fetched 32.7 kB in 1s (25.5 kB/s) Selecting previously deselected package bridge-utils. (Reading database ... 267692 files and directories currently installed.) Unpacking bridge-utils (from .../bridge-utils_1.4-5_amd64.deb) ... Processing triggers for man-db ... Setting up bridge-utils (1.4-5) ...

编辑 /etc/network/interfaces, 输入:

# vi  /etc/network/interfaces

修改,或设置其配置如下:

auto lo br0 iface lo inet loopback   # wireless wlan0 allow-hotplug wlan0 iface wlan0 inet manual   # eth0 connected to the ISP router allow-hotplug eth0 iface eth1 inet manual   # Setup bridge iface br0 inet static bridge_ports wlan0 eth0 address 192.168.1.11 netmask 255.255.255.0 network 192.168.1.0 ## isp router ip, 192.168.1.2 also runs DHCPD ## gateway 192.168.1.2 dns-nameservers 192.168.1.2

保存并并关闭文件。到此,我建议你重启计算机,或者像下面那样重启所有的服务(使用远端ssh会话可能不工作):

# /etc/init.d/networking restart # /etc/init.d/hostapd restart

或者:

# reboot

关于DHCPD 的注意

既然你让WAP跑在桥接(br0)模式,在WAP上DHCPD不是必需的。它可以使用LAN内任意地方的DHCPD服务器。在本例子中 192.168.1.2是一个ISP路由器,它提供了DHCPD服务。如果你没有使用DHCPD服务器,参照以下安装:

Ubuntu / Debian Linux: Setup An ISC DHCP Server For Your Network

关于防火墙的注意

你可以安装防火墙来抵御进攻。参阅这里:install shorewall on Debian or Ubuntu Linux.

如何处理WAP问题?

WPA的日志信息在 /var/log/syslog文件中:

# tail -f /var/log/syslog

检查DHCPD中继是否工作:

# tcddump -n port 67 或 ort 68

确定防火墙没有阻止需要的端口:

# /sbin/iptables -L -n -v | less

确定br0的mac地址正确,并且它已经在运行:

# ifconfig br0 # ifconfig | grep HW # brctl show # brctl showmacs bro

使用这些命令来查看无线网络速度、信号强度和其他信息。

最后,确认你使用了以下软件的最新版本:

Linux kernelWireless card drivers and firmwarehostapd

参考:

hostapd documentation from the Linux kernel wireless wiki.Download latest version of hostapd from the official web-site or read documentation here or run the commandvi /usr/share/doc/hostapd/examples/hostapd.conf.gzman pages - hostapd, brctl command, and interfaces 原文



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3