Raspberry Pi3 無線LAN AP化

Raspberry Pi3 内蔵の無線LANアダプタをアクセスポイントとして動作させます。
普通にセットアップした状態では子機として動作しているので、設定を変更し、アクセスポイント化するための hostapd と、接続相手にIPを割り振るためのDHCPサーバーを動かします。

wlan0の準備


まず、既存で設定されている無線LANアダプタの設定を修正します。
子機動作を削除し、wlan0を固定IPアドレスのアダプタとして初期化します。

/etc/network/interfaces を下記のように修正します。
sudo vi /etc/network/interfaces 等として編集してください。

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
#iface wlan0 inet manual
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface wlan0 inet static
address 192.168.7.1
netmask 255.255.255.0


#allow-hotplug wlan1
#iface wlan1 inet manual
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

赤字の部分が主な設定内容です。

ここで、本来は固定IPアドレス化するのに、/etc/dhcpcd.conf ファイルを編集するのが正式な方法らしいのですが、この方法だと後述するdhcpサーバーの起動で失敗してしまいます。
仕方ないので、今回はインターフェイス初期化時にIPを割り振ります。

hostapdインストール


hostapdは無線LANをアクセスポイントモードで動かし、認証と接続を行うためのデーモンです。
コンソールコマンドラインより、

$ sudo apt-get install hostapd

以上でインストールは完了です。

設定ファイルを作ります。/etc/hostapd/hostapd.conf を下記ように作成してください。

 # This is the name of the WiFi interface we configured above
interface=wlan0

# Use the nl80211 driver with the brcmfmac driver
driver=nl80211

# This is the name of the network
ssid=starway-00000000

# Use the 2.4GHz band
hw_mode=g

# Use channel 6
channel=6

# Enable 802.11n
ieee80211n=1

# Enable WMM
wmm_enabled=1

# Enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]

# Accept all MAC addresses
macaddr_acl=0

# Use WPA authentication
auth_algs=1

# Require clients to know the network name
ignore_broadcast_ssid=0

# Use WPA2
wpa=2

# Use a pre-shared key
wpa_key_mgmt=WPA-PSK

# The network passphrase
wpa_passphrase=hogehoge

# Use AES, instead of TKIP
rsn_pairwise=CCMP

 ssidやchannelは個別に設定してください。

 /etc/default/hostapd を編集します。
DAEMON_CONFを下記のように変更してください。

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

dnsmasqインストール&設定


アクセスポイント化したwlan0へ接続した子機にIPアドレスを割り当てるためのにDHCPサーバーを動かします。今回はdnsmasqを使用しました。
まずはインストール。

$ sudo apt-get install dnsmasq

念のため、オリジナルの設定ファイルをバックアップしておきます。

$ sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

下記の内容で設定ファイル /etc/dnsmasq.conf を作成します。

# Use interface wlan0
interface=wlan0

# Explicitly specify the address to listen on
listen-address=192.168.7.1

# Bind to the interface to make sure we aren't sending things elsewhere.
bind-interfaces

# Forward DNS requests to Google DNS
server=8.8.8.8
server=8.8.4.4

# Don't forward short names
domain-needed

# Never forward addresses in the non-routed address spaces.
bogus-priv

# Assign IP addresses between 192.168.7.100 and 192.168.7.199
# with a 24 hour lease time
dhcp-range=192.168.7.100,192.168.7.199,24h

ネットワークアドレスは 192.168.7.0 / 24 の範囲を使用しています。
DHCPで割り当てられるIPアドレスの範囲は、192.168.7.100 ~ 192.168.7.199 です。

interface と listen-address はDHCP要求を受け付けるデバイスを指定します。今回は無線LANアダプタの wlan0 とそれに割り当てたIPアドレス 192.168.7.1を指定します。
DNSサーバーの設定はgoogle のパブリックDNSサーバーを指定しています。

以上、設定が完了したら、一度リブートします。

$ sudo reboot



関連項目:
wlan0-eth0フォワーディング


オリジナル 基板頒布

オープンソースの架台制御ソフト、OnStepのハードウェア実装基板などの話題です。


頒布状況 2024/4/2
○ OnStep基板 Rev2.1
○ OnStep基板 Rev3.0
○ GBC-SHC 基板 Rev1.0
頒布ご希望の方はこちら、基板頒布のお知らせ をご覧ください。

このブログを検索

Blog Archive

QooQ