基于 hostapd udhcpd 的热点配置

概述

其它关于 hostapd udhcpd 的热点配置,网上有很多资料,基本上一搜都能搜到,但是还是记录一下自己操作的过程,有时候有些问题可能不是网上讲到的吧。

准备

也就是确定一下,你的硬件是支持的,有 wifi 芯片的。

配置

hostapd 的配置文件,这个在文尾放一个我的配置吧,udhcpd 也是一样文尾放一个我的配置,这里简单说点。

主要配置也就是配置使用哪个接口,一般就是 wlan0,对应的系统,可能会不一样,反正找对就行,如果没有,尝试 ifconfig wlan0 up 启动,如果启动不了可能就是真的没有,可者驱动等底层有问题吧。

然后在 hostapd 中主要就是配置加密方式,ssid,其它的配置项,可以根据需要再搜索,找官司方档等。

udhcpd 在嵌入式中一般都是来源于 busybox,编译时在busybox 中找到它,同样配置文件就是配置接口,然后再说置可分配的网段,一般源码中给的默认配置用来改改就可以了。

操作过程

  1. 系统启动,ifconfig wlan0 up 开启
  2. ifconfig wlan0 192.168.xx.1 设置地址,这个地址应该跟 udhcpd.conf 中配置的的网段是一样,同时其中的router也就是网关部分应该是一样的
  3. hostapd xxx/hostapd.conf 启动热点
  4. udhcpd xxx/udhcpd.conf 启动地址分配程序
  5. 基本这样就可以了,下面就可以用手机连接了

其它问题

  1. 记得在使能的时候先 ifconfig wlan0 down 再 ifconfig wlan0 up 如果之前系统连接了其它的地方已经分配了地址,再去启动热点,又没有给 wlan0 重新设置成网关地址就会有问题

附件

hostapd.conf

interface=wlan0
ssid=jmdvirus-hostapd
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0

# channel 1-14 is 2.4 GHz ; channel 36, 40, 44, 46, 48, 52, 56, 60,
# 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149,
# 153, 157, 161 is 5GHz
# The channels that are available for use in a particular country differ
# according to the regulations of that country.
channel=7

# Operation mode (a = IEEE 802.11a, b = IEEE 802.11b, g = IEEE
# 802.11g, Default: IEEE 802.11b )
hw_mode=g

#If the wireless interface is included in a bridge,
#an additional configuration parameter, bridge, is needed
#bridge=br0
# This field is a bit field that can be used to enable WPA
# (IEEE 802.11i/D3.0)
# and/orWPA2 (full IEEE 802.11i/RSN):
# bit1 = IEEE 802.11i/RSN (WPA2) (dot11RSNAEnabled)
#wpa=2
#wpa_passphrase=12345678
# Set of accepted key management algorithms
# (WPA-PSK, WPA-EAP, or both).
#wpa_key_mgmt=WPA-PSK
# Set of accepted cipher suites (encryption algorithms)
# for pairwise keys
#wpa_pairwise=CCMP TKIP

# ieee80211n: Whether IEEE 802.11n (HT) is enabled
# 0 = disabled (default)
# 1 = enabled
ieee80211n=1
# ht_capab: HT capabilities (list of flags)
# Supported channel width set: [HT40-] = both 20 MHz and 40 MHz
# with secondary channel below the primary channel;
# [HT40+] = both 20 MHz and 40 MHz with secondary channel upon
# the primary channel
# Note:There are limits on which channels can be used with HT40- and
# HT40+.Following table shows the channels that may be available for
# HT40- and HT40+ use per IEEE 802.11n Annex J:
# freq HT40- HT40+
# 2.4 GHz 5-13 1-7 (1-9 in Europe/Japan)
# 5 GHz 40,48,56,64 36,44,52,60
# Short GI for 20 MHz: [SHORT-GI-20] (disabled if not set)
# Short GI for 40 MHz: [SHORT-GI-40] (disabled if not set)
#ht_capab=[SHORT-GI-20][SHORT-GI-40]

udhcpd.conf

# Sample udhcpd configuration file (/etc/udhcpd.conf)
# Values shown are defaults

# The start and end of the IP lease block
start       192.168.188.2
end     192.168.188.20

# The interface that udhcpd will use
interface   wlan0

# The maximum number of leases (includes addresses reserved
# by OFFER's, DECLINE's, and ARP conflicts). Will be corrected
# if it's bigger than IP lease block, but it ok to make it
# smaller than lease block.
max_leases  16

# 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

# The amount of time that an IP will be reserved (leased to nobody)
# if a DHCP decline message is received (seconds)
#decline_time   3600

# The amount of time that an IP will be reserved
# if an ARP conflict occurs (seconds)
#conflict_time  3600

# How long an offered address is reserved (seconds)
offer_time  20

# If client asks for lease below this value, it will be rounded up
# to this value (seconds)
#min_lease  60

# The location of the leases file
lease_file  /tmp/conf/udhcpd.leases

# The location of the pid file
pidfile /tmp/udhcpd.pid

# Every time udhcpd writes a leases file, the below script will be called
#notify_file            # default: no script
#notify_file    dumpleases  # useful for debugging

# The following are bootp specific options
# next server to use in bootstrap
#siaddr     192.168.10.22   # default: 0.0.0.0 (none)
# tftp server name
#sname      zorak       # default: none
# tftp file to download (e.g. kernel image)
#boot_file  /var/nfs_root   # default: none

# Static leases map
#static_lease 00:60:08:11:CE:4E 192.168.10.54
#static_lease 00:60:08:11:CE:3E 192.168.10.44

# The remainder of options are DHCP options and can be specified 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.
# Examples:
opt dns 8.8.8.8
option  subnet  255.255.255.0
opt router  192.168.188.1
#opt    wins    192.168.188.10
option  dns 114.114.114.114 # appended to above DNS servers for a total of 3
#option domain  local
#option lease   864000      # default: 10 days
# Arbitrary option in hex form:
#option 0x08    01020304    # option 8: "cookie server IP addr: 1.2.3.4"

# Currently supported options (for more info, see options.c):
#opt lease      NUM
#opt subnet     IP
#opt broadcast  IP
#opt router     IP_LIST
#opt ipttl      NUM
#opt mtu        NUM
#opt hostname   STRING      # client's hostname
#opt domain     STRING      # client's domain suffix
#opt search     STRING_LIST # search domains
#opt nisdomain  STRING
#opt timezone   NUM     # (localtime - UTC_time) in seconds. signed
#opt tftp       STRING      # tftp server name
#opt bootfile   STRING      # tftp file to download (e.g. kernel image)
#opt bootsize   NUM     # size of that file
#opt rootpath   STRING      # (NFS) path to mount as root fs
#opt wpad       STRING
#opt serverid   IP      # default: server's IP
#opt message    STRING      # error message (udhcpd sends it on success too)
# Options specifying server(s)
#opt dns        IP_LIST
#opt wins       IP_LIST
#opt nissrv     IP_LIST
#opt ntpsrv     IP_LIST
#opt lprsrv     IP_LIST
#opt swapsrv    IP
# Obsolete options, no longer supported
#opt logsrv     IP_LIST # 704/UDP log server (not syslog!)
#opt namesrv    IP_LIST # IEN 116 name server, obsolete (August 1979!!!)
#opt cookiesrv  IP_LIST # RFC 865 "quote of the day" server, rarely (never?) used
#opt timesrv    IP_LIST # RFC 868 time server, rarely (never?) used

你可能感兴趣的:(基于 hostapd udhcpd 的热点配置)