Raspberry Pi3 をアクセスポイントとして使う

我が家には無線LANルーターがあるのだが、iPhone SE との接続がなぜか安定しない。そこでRPi3をアクセスポイント化(AP化)して「接続がちょくちょく切れる問題」を解決したい。

 

想定構成

RPi3はあくまでAPとしてのみ使用し、DHCPによるアドレス配布は無線ルーターに任せる。

 

必要になるパッケージ

bridge-utils, hostapd

 

作業手順

  1. 必要なパッケージをインストールする
    # apt-get update
    # apt-get install bridge-utils hostapd
  2. NICの設定をする(ブリッジ接続のためのインターフェイスを追加する)
    ポイントとしては、bridge_ports でブリッジ設定することと、wlan0の設定をmanualにすること
    $ sudo emacs /etc/network/interfaces
    auto br0
    iface br0 inet static
    address 192.168.1.20 # 重複しない任意のアドレス
    netmask 255.255.255.0 # 無線LANルーターが見えるマスク
    gateway 192.168.1.1 # 無線LANルーターのアドレスを指定する

    bridge_ports wlan0 eth0

    auto wlan0
    allow-hotplug wlan0
    iface wlan0 inet manual
  3. RPi3を再起動して、ブリッジ接続が上手くできているか確認する
    $ brctl show
    bridge name に br0 が表示されていればOK
  4. hostapdの設定をする
    /usr/share/doc/hostapd/examples/hostapd.conf.gz の内容を参考に設定ファイルを作成するのだけど、コメントが多いので以下をコピペして使う。
    赤字のところは自分の環境に合わせて設定する。
    # 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=<your SSID name>

    # Bridge Interface Name
    bridge=br0

    # Use the 2.4GHz band
    hw_mode=g

    # Use channel 6
    channel=[1-14]

    # 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  # 1にしてもステルスにならない...

    # Use WPA2
    wpa=2

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

    # The network passphrase
    wpa_passphrase=<your SSID password>

    # Use AES, instead of TKIP
    rsn_pairwise=CCMP
    パスフレーズ8文字以上じゃないとダメっぽいです。
  5. RPi3を再起動する
  6. hostapd の試運転を行なう
    $ sudo hostapd /etc/hostapd/hostapd.conf
  7. 問題がなければ、hostapd.conf をデーモンのデフォルトに指定する
    $ sudo emacs /etc/default/hostapd
    DAEMON_CONF="/etc/hostapd/hostapd.conf"
  8. サービスを再起動する
    $ sudo service hostapd restart

 

参考Webページ