本帖最后由 米尔国产方案 于 2024-5-8 17:48 编辑
开启wifi的AP模式,电脑可以随时连接到开发板,并且通过网关地址(192.168.2.1)访问设备。
#当使用AP模式时,需要为激活wlan0并配置一个静态IP地址,这里配置一个默认的IP地址:192.168.2.1
ifconfig wlan0 192.168.2.1 up
#清除旧模式的配置,确保新模式正常执行,因为STA和AP模式配置不能同时存在。
killall udhcpc
killall udhcpd
killall wpa_supplicant
killall hostapd
#使用wlan0运行hostapd服务
hostapd -B /etc/hostapd.conf
另外,还需要编辑两个配置文件,设置AP的参数
/etc/hostapd.conf,该文件设置了wifi名和密码 Ø ssid:wifi名称 Ø wpa_passphrase:wifi密码
root@myd-lt527:/# cat /etc/hostapd.conf interface=wlan0 driver=nl80211 ssid=myd_lt527_test_wifi channel=6 hw_mode=g ignore_broadcast_ssid=0 auth_algs=1 wpa=2 wpa_passphrase=12345678 wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
/etc/udhcpd.conf文件设置设备动态分配IP地址 当AP模式配置完成,其它设备连接到这个热点时,就会通过wlan0获取到上面地址池中的IP地址,地址范围为192.168.2.10~192.168.2.254,子网掩码为255.255.255.0,默认网关192.168.2.1,DNS为8.8.8.8。
root@myd-lt527:/# cat /etc/udhcpd.conf # Change the following lines if you want dnsmasq to serve SRV # records. # You may add multiple srv-host lines. # The fields are <name>,<target>,<port>,<priority>,<weight> # A SRV record sending LDAP for the example.com domain to # ldapserver.example.com port 289 #srv-host=_ldap._tcp.example.com,ldapserver.example.com,389 # Two SRV records for LDAP, each with different priorities #srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,1 #srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,2 # A SRV record indicating that there is no LDAP server for the domain # example.com #srv-host=_ldap._tcp.example.com # The following line shows how to make dnsmasq serve an arbitrary PTR # record. This is useful for DNS-SD. # The fields are <name>,<target> #ptr-record=_http._tcp.dns-sd-services,"New Employee Page._http._tcp.dns-sd-services" # Change the following lines to enable dnsmasq to serve TXT records. # These are used for things like SPF and zeroconf. # The fields are <name>,<text>,<text>... #Example SPF. #txt-record=example.com,"v=spf1 a -all" #Example zeroconf #txt-record=_http._tcp.example.com,name=value,paper=A4 # Provide an alias for a "local" DNS name. Note that this _only_ works # for targets which are names from DHCP or /etc/hosts. Give host # "bert" another name, bertrand # The fields are <cname>,<target> #cname=bertand,bert resolv-file=/etc/resolv.dnsmasq.conf strict-order cache-size=102400 interface=wlan0 min-cache-ttl=3600 dhcp-range=192.168.2.2,192.168.2.255 all-servers dhcp-sequential-ip
root@myd-lt527:/# cat /etc/udhcpd.conf # Sample udhcpd configuration file (/etc/udhcpd.conf) # The start and end of the IP lease block start 192.168.2.10 #default: 192.168.2.20 end 192.168.2.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 # <--- usefull 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 202.96.134.133 option subnet 255.255.255.0 opt router 192.168.2.1 opt wins 192.168.2.10 option dns 202.96.128.86 # appened to above DNS servers for a total of 3 option domain local option lease 864000 # 10 days of seconds
|