使用 hostapd 和 isc-dhcp-server 使 WiFi AP 工作

使用 hostapd 和 isc-dhcp-server 使 WiFi AP 工作

我尝试使用 WebUpd8 中的 ap-hotspot,但在 13.10 或 14.04 中无法使用,因此我一直在尝试手动设置 hostapd,isc-dhcp-server因为 dnsmasq 对我来说存在冲突。我能够连接到 AP,并获得IP,但路由似乎无法正常工作。这是我的构建日志以及我一直遵循的指南:

配置文件:

/etc/network/interfaces

auto lo
iface lo inet loopback
auto wlan0
iface wlan0 inet static
hostapd -dd /etc/hostapd/hostapd.conf
address 10.10.0.1
netmask 255.255.255.0

/etc/default/hostapd

RUN_DAEMON="yes"
DAEMON_CONF="/etc/hostapd/hostapd.conf"
DAEMON_OPTS="-dd"

/etc/hostapd/hostapd.conf

# WiFi Hotspot
interface=wlan0
driver=nl80211
#Access Point
ssid=workshop
hw_mode=g
# WiFi Channel:
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypass
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

/etc/dhcp/dhcpd.conf

ddns-update-style none;
#default-lease-time 600;
#max-lease-time 7200;
log-facility local7;
subnet 10.10.0.0 netmask 255.255.255.0 {
    range 10.10.0.2 10.10.0.32;
    option domain-name-servers 208.67.222.222, 208.67.220.220;
    option routers 10.10.0.1;
}

/etc/rc.local

iptables -t nat -A POSTROUTING -s 10.10.0.0/32 -o eth1 -j MASQUERADE
exit 0

运行了以下命令:

sudo ifconfig wlan0 10.10.0.1
sudo sysctl net.ipv4.ip_forward=1
sudo ip link set dev wlan0 up
sudo service hostapd start

我已经安装了bridge-utils,但还没有添加,br0因为我不确定如何更改配置的其他部分来反映它...

编辑:通过另一本(较旧的)指南仔细检查我的配置后,再次尝试并决定添加连接时在日志中显示的内容。连接的设备是我的 Android 手机,它可以通过普通路由器正常连接。

(我了解日志中发生的大部分事情,并且启动看起来很好。然后随机滚动......)

Add randomness: count=52 entropy=51
mgmt::auth
authentication: STA=a0:f4:50:18:a2:c3 auth_alg=0 auth_transaction=1 status_code=0 wep=0
  New STA
wlan0: STA a0:f4:50:18:a2:c3 IEEE 802.11: authentication OK (open system)
wlan0: STA a0:f4:50:18:a2:c3 MLME: MLME-AUTHENTICATE.indication(a0:f4:50:18:a2:c3, OPEN_SYSTEM)
wlan0: STA a0:f4:50:18:a2:c3 MLME: MLME-DELETEKEYS.request(a0:f4:50:18:a2:c3)
authentication reply: STA=a0:f4:50:18:a2:c3 auth_alg=0 auth_transaction=2 resp=0 (IE len=0)
Add randomness: count=53 entropy=52
mgmt::auth cb
wlan0: STA a0:f4:50:18:a2:c3 IEEE 802.11: authenticated
mgmt::assoc_req
association request: STA=a0:f4:50:18:a2:c3 capab_info=0x431 listen_interval=20
  new AID 1
wlan0: STA a0:f4:50:18:a2:c3 IEEE 802.11: association OK (aid 1)
Add randomness: count=54 entropy=53
mgmt::assoc_resp cb
wlan0: STA a0:f4:50:18:a2:c3 IEEE 802.11: associated (aid 1)
wlan0: STA a0:f4:50:18:a2:c3 MLME: MLME-ASSOCIATE.indication(a0:f4:50:18:a2:c3)
wlan0: STA a0:f4:50:18:a2:c3 MLME: MLME-DELETEKEYS.request(a0:f4:50:18:a2:c3)
wpa_driver_nl80211_set_key: ifindex=3 alg=0 addr=0x9f8ac90 key_idx=0 set_tx=1 seq_len=0 key_len=0
   addr=a0:f4:50:18:a2:c3
wlan0: STA a0:f4:50:18:a2:c3 WPA: event 1 notification
wpa_driver_nl80211_set_key: ifindex=3 alg=0 addr=0x9f8ac90 key_idx=0 set_tx=1 seq_len=0 key_len=0
   addr=a0:f4:50:18:a2:c3
IEEE 802.1X: Ignore STA - 802.1X not enabled or forced for WPS
wlan0: STA a0:f4:50:18:a2:c3 WPA: start authentication
WPA: a0:f4:50:18:a2:c3 WPA_PTK entering state INITIALIZE
wpa_driver_nl80211_set_key: ifindex=3 alg=0 addr=0x9f8ac90 key_idx=0 set_tx=1 seq_len=0 key_len=0
   addr=a0:f4:50:18:a2:c3
wlan0: STA a0:f4:50:18:a2:c3 IEEE 802.1X: unauthorizing port
WPA: a0:f4:50:18:a2:c3 WPA_PTK_GROUP entering state IDLE
WPA: a0:f4:50:18:a2:c3 WPA_PTK entering state AUTHENTICATION
WPA: a0:f4:50:18:a2:c3 WPA_PTK entering state AUTHENTICATION2
WPA: Re-initialize GMK/Counter on first station
Get randomness: len=32 entropy=54
GMK - hexdump(len=32): [REMOVED]
Get randomness: len=32 entropy=22
Key Counter - hexdump(len=32): [REMOVED]
Get randomness: len=16 entropy=0
GTK - hexdump(len=16): [REMOVED]
wpa_driver_nl80211_set_key: ifindex=3 alg=3 addr=0x80dd6be key_idx=1 set_tx=1 seq_len=0 key_len=16
   broadcast key
WPA: Assign ANonce - hexdump(len=32): 12 53 6f 26 8a a3 87 09 b4 31 e2 81 ef c3 ea 3e 6c 3d 0c a5 fb 85 07 f2 0a 2a 4a 5e a2 00 59 e9
WPA: a0:f4:50:18:a2:c3 WPA_PTK entering state INITPSK
WPA: a0:f4:50:18:a2:c3 WPA_PTK entering state PTKSTART
wlan0: STA a0:f4:50:18:a2:c3 WPA: sending 1/4 msg of 4-Way Handshake
WPA: Send EAPOL(version=2 secure=0 mic=0 ack=1 install=0 pairwise=8 kde_len=0 keyidx=0 encr=0)
WPA: Use EAPOL-Key timeout of 100 ms (retry counter 1)
nl80211: Event message available
nl80211: New station a0:f4:50:18:a2:c3
IEEE 802.1X: a0:f4:50:18:a2:c3 TX status - version=2 type=3 length=95 - ack=1
WPA: EAPOL-Key TX status for STA a0:f4:50:18:a2:c3 ack=1
WPA: Increase initial EAPOL-Key 1/4 timeout by 1000 ms because of acknowledged frame
IEEE 802.1X: 121 bytes from a0:f4:50:18:a2:c3
   IEEE 802.1X: version=1 type=3 length=117
WPA: Received EAPOL-Key from a0:f4:50:18:a2:c3 key_info=0x10a type=2 key_data_length=22
WPA: Received Key Nonce - hexdump(len=32): 7c 4d 99 9f 10 56 93 84 a9 8a f8 15 d8 8e 1e 6d 2f 39 95 8f bc 99 9a 4c 06 3d 37 65 e6 db 49 fa
WPA: Received Replay Counter - hexdump(len=8): 00 00 00 00 00 00 00 01
Add randomness: count=55 entropy=0
wlan0: STA a0:f4:50:18:a2:c3 WPA: received EAPOL-Key frame (2/4 Pairwise)
WPA: a0:f4:50:18:a2:c3 WPA_PTK entering state PTKCALCNEGOTIATING
WPA: PTK derivation - A1=90:4c:e5:55:94:4d A2=a0:f4:50:18:a2:c3
WPA: Nonce1 - hexdump(len=32): 12 53 6f 26 8a a3 87 09 b4 31 e2 81 ef c3 ea 3e 6c 3d 0c a5 fb 85 07 f2 0a 2a 4a 5e a2 00 59 e9
WPA: Nonce2 - hexdump(len=32): 7c 4d 99 9f 10 56 93 84 a9 8a f8 15 d8 8e 1e 6d 2f 39 95 8f bc 99 9a 4c 06 3d 37 65 e6 db 49 fa
WPA: PMK - hexdump(len=32): [REMOVED]
WPA: PTK - hexdump(len=48): [REMOVED]
WPA: a0:f4:50:18:a2:c3 WPA_PTK entering state PTKCALCNEGOTIATING2
WPA: a0:f4:50:18:a2:c3 WPA_PTK entering state PTKINITNEGOTIATING
wlan0: STA a0:f4:50:18:a2:c3 WPA: sending 3/4 msg of 4-Way Handshake
WPA: Send EAPOL(version=2 secure=1 mic=1 ack=1 install=1 pairwise=8 kde_len=46 keyidx=1 encr=1)
Plaintext EAPOL-Key Key Data - hexdump(len=56): [REMOVED]
WPA: Use EAPOL-Key timeout of 100 ms (retry counter 1)
IEEE 802.1X: a0:f4:50:18:a2:c3 TX status - version=2 type=3 length=151 - ack=1
WPA: EAPOL-Key TX status for STA a0:f4:50:18:a2:c3 ack=1
IEEE 802.1X: 99 bytes from a0:f4:50:18:a2:c3
   IEEE 802.1X: version=1 type=3 length=95
WPA: Received EAPOL-Key from a0:f4:50:18:a2:c3 key_info=0x30a type=2 key_data_length=0
WPA: Received Key Nonce - hexdump(len=32): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
WPA: Received Replay Counter - hexdump(len=8): 00 00 00 00 00 00 00 02
wlan0: STA a0:f4:50:18:a2:c3 WPA: received EAPOL-Key frame (4/4 Pairwise)
WPA: a0:f4:50:18:a2:c3 WPA_PTK entering state PTKINITDONE
wpa_driver_nl80211_set_key: ifindex=3 alg=3 addr=0x9f8ac90 key_idx=0 set_tx=1 seq_len=0 key_len=16
   addr=a0:f4:50:18:a2:c3
wlan0: AP-STA-CONNECTED a0:f4:50:18:a2:c3
wlan0: STA a0:f4:50:18:a2:c3 IEEE 802.1X: authorizing port
wlan0: STA a0:f4:50:18:a2:c3 RADIUS: starting accounting session 536C1843-00000000
wlan0: STA a0:f4:50:18:a2:c3 WPA: pairwise key handshake completed (RSN)
Add randomness: count=56 entropy=1

(更加随机,直到我按 ctrl+c)

答案1

尝试以下操作

sudo apt-get install hostapd dnsmasq dhcp3-server isc-dhcp-server haveged

设置 hostapd

hostapd 用于无线路由器功能:

leafpad /etc/hostapd.conf

常规热点配置:

定义接口

interface=wlan#
bridge=br0

选择驱动程序:

driver=nl80211

将接入点硬件模式设置为 802.11a/b/g/n(硬件支持吗?):

hw_mode=g
logger_stdout=-1
logger_stdout_level=2
require_ht=0
ht_capab= [HT40+] [HT40-] [SHORT-GI-40] [RX-STBC1]
ieee80211d=1
ieee80211n=1
macaddr_acl=0
wmm_enabled=1

配置无线特性:

beacon_int=50
country_code=US
disassoc_low_ack=1

设置Wi-Fi信道:

channel=6

设置接入点名称:

ssid=nametobroacdcast
ignore_broadcast_ssid=0

设置加密标准(1代表WPA,2代表WPA2,3代表WPA+WPA2):

auth_algs=1
wpa=3
wpa_passphrase=yourpassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP

wpa_key_mgmt 的其他选项=WPA-EAP WPA-PSK-SHA256 WPA-EAP-SHA256


创建并保存./######.sh脚本

#!/bin/bash
# Configure IP address for WLAN
sudo ifconfig wlan0 up 192.168.3.1 netmask 255.255.255.0
sleep 2

# Start DHCP/DNS server (Can replace `dnsmasq` with `dhcpd` or `isc-hdcp-server`):
sudo service dnsmasq restart

# Replace "dnsmasq restart" line above with this area between ## ## if that does not work
if [ “$(ps –e | grep dhcpd)” == “” ]; then
dhcpd $1 &
fi

# Enable routing
sudo sysctl net.ipv4.ip_forward=1

# Enable Network Address Translation (NAT)
sudo iptables --flush
sudo iptables –-table nat --flush
sudo iptables --delete-chain
sudo iptables --table nat --delete-chain
sudo iptables --table nat --flush
sudo iptables -t nat -A POSTROUTING --out –interface $1 -j MASQUERADE

# “$1” = computer acting as AP output interface (to internet)
sudo iptables –A FORWARD –in-interface $2 –j ACCEPT

# “$2” = client input interface (to client)
echo 1 > /proc/sys/net/ipv4/ipforward

# Run access point daemon
sudo hostapd /etc/hostapd.conf

# Stopping DHCP/DNS server

# Disable NAT
sudo iptables -D POSTROUTING -t nat -o ppp0 -j MASQUERADE

# Disable routing
sudo sysctl net.ipv4.ip_forward=0

# Disable DHCP/DNS server
sudo service dnsmasq stop
# Can replace with “dhcpd” or “isc-hdcp-server”

# Start HOSTAPD
sudo service hostapd start

开始设置 DNS/DHCP

dnsmasq dhcp3-server isc-dhcp-server 用于 DNS/DHCP 功能(选择一个):

例子:

leafpad /etc/dhcp/dhcpd.conf

常规 DHCP 配置:

ddns-update-style none;
ignore clients-updates;
authoritative;
option local-wpad code 252 = test;
log-facility local7;
default-lease-time 3600;
max-lease-time 7200;
subnet
192.168.3.0 netmask 255.255.255.0 {
    # Broadcast address
    option broadcast-address 192.168.3.2;
    # Netmask
    option subnet-mask 255.255.255.0;
    # Default gateway
    option routers 192.168.3.1;

    # Domain Name Servers for directing client traffic 
    option domain-name-servers 8.8.8.8, 8.8.4.4;
    option time-offset 0;

    # Set IP address range available to clients
    range 192.168.3.2, 192.168.3.100;
}

允许./#####.sh运行创建的脚本

使hostapdfilecreated.sh可执行文件:

sudo chmod +x nameoffilecreated.sh

您必须进入文件所在的目录######.shcd然后运行命令。

执行脚本启动基于计算机的接入点广播:

sudo ./nameoffilecreated.sh

相关内容