LinuxでのワイヤレスカードのAPモード

5525 ワード

Windowsの下で、私たちはチーター、360とテンセントの執事の中のいくつかのソフトウェアアシスタントを使って、私たちのワイヤレスカードをホットスポットにすることができて、同じようにLinuxの中で.ワイヤレスカードのホットスポットを開いて、他のデバイスが接続できるようにすることもできます.ここでは、天嵌のIMX 6 ULプラットフォームに基づいて、8723 bu WIFIモジュールを使用してAPホットスポットを送信する
前提条件:1.ファイルシステムにはhostapdツールがあり、自分で移植する必要がない場合は2.ファイルシステムにはudhcpdツールがあり、自分で移植する必要がない場合は1)hostapdプロファイルを開き、構成内容を変更します.
vi /etc/hostapd.conf:
ctrl_interface=/var/run/hostapd
#change wlan0 to your wireless device
interface="wlan0"//         ,    wlan0
driver=nl80211
ssid="test"//    ,    
channel=1
# ....../............ macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase="12345678" //     ,   
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

2)ネットワークipを割り当てるプロファイル(ここでは貼り付け部分):vi/etc/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.0.20  //     ip      
end  192.168.0.254  //     ip      
# The interface that udhcpd will useinterface 
wlan0 //           

3)この2つのファイルを構成した後、ホットスポットの作成を開始します.
hostapd -B /etc/hostapd.conf -f /var/log/hstap.log

4)wlan 0のipの設定
ifconfig wlan0 192.168.0.2

5)自動割当ipバックグラウンドを起動し、接続上の機器にipを割り当てる
udhcpd -f /etc/udhcpd.conf &

6)次の送信ホットスポットコマンドスクリプトsend_を実行するap.sh
#!/bin/sh
ifconfig wlan0 down
ps -ef | grep hostapd | grep -v grep | awk '{print $1}' | xargs kill -9
ps -ef | grep wpa_supplicant | grep -v grep | awk '{print $1}' | xargs kill -9
ps -ef | grep udhcpd | grep -v grep | awk '{print $1}' | xargs kill -9
hostapd -B /etc/hostapd.conf -f /var/log/hostap.log
ifconfig wlan0 192.168.0.2
udhcpd -f /etc/udhcpd.conf &

その後、携帯電話や他のwifiデバイスで8723から送信されたapホットスポット「test」に接続でき、パスワード12345678
7)APサービスは、dhcpに接続して動的IPを得ることができますが、どのようにしてデバイスがこの無線ネットワークカードを通じてインターネットを利用できるかを保証する必要があります.これは、無線ネットワークカードwlan 0のデバイスを有線ネットワークカードeth 0に転送する構成が必要です.ルーティング転送ルールを構成し、データ伝送のリンクを開く必要があります.以下のルーティング転送スクリプトiptablesを実行する.sh
#! /bin/sh
#  linux    ip   
echo "1" > /proc/sys/net/ipv4/ip_forward
  
#     
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X

#  filter table    
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

#  NAT  
iptables -t nat -A POSTROUTING -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

ルーティング転送中にiptablesでエラーが発生した場合は、関連するカーネル構成が必要です.
Networking —->
  Networking options —->
  [*] Network packet filtering (replaces ipchains)  —>
    Core Netfilter Configuration  —>
       Netfilter Xtables support (required for ip_tables)
    IP: Netfilter Configuration —>
       Connection tracking (required for masq/NAT)
       IP tables support (required for filtering/masq/NAT)
         IP range match support
         Packet filtering
           REJECT target support
         Full NAT

ルーティング転送中にnatエラーが発生した場合、関連するカーネル構成が必要です.
Type  : tristate                                                                                                                                                                             │  
  │ Prompt: iptables NAT support                                                                                                                                                                 │  
  │   Location:                                                                                                                                                                                  │  
  │     -> Networking support (NET [=y])                                                                                                                                                         │  
  │       -> Networking options                                                                                                                                                                  │  
  │         -> Network packet filtering framework (Netfilter) (NETFILTER [=y])                                                                                                                   │  
  │           -> IP: Netfilter Configuration                                                                                                                                                     │  
  │ (1)         -> IP tables support (required for filtering/masq/NAT) (IP_NF_IPTABLES [=y])       

CONFIG_IP_NF_NAT
  │   Location:                                                                                                                                                                                  │  
  │     -> Networking support (NET [=y])                                                                                                                                                         │  
  │       -> Networking options                                                                                                                                                                  │  
  │         -> Network packet filtering framework (Netfilter) (NETFILTER [=y])                                                                                                                   │  
  │ (1)       -> IP: Netfilter Configuration