3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Raspberry Piにアクセスポイントを立てる

Last updated at Posted at 2022-01-03

今後使いそうなので覚え書きメモ

今回使用した物

  • Raspberry Pi本体
  • 最新ではなくlegacyの方のOS
    • 自分の使ってるモニターでは最新版ではデスクトップ環境が表示されなかったので...
  • キーボード
  • 適当なモニター

パッケージのインストール

$ sudo apt-get update
$ sudo apt-get install hostapd
$ sudo apt-get install dnsmasq

hostapdのインストールが上手くいかない場合

# エラー状況の確認
$ systemctl status hostapd.service

● hostapd.service
   Loaded: masked (Reason: Unit hostapd.service is masked.)
   Active: failed (Result: exit-code) since Mon 2022-01-03 11:15:00 GMT; 33s ago

Jan 03 11:15:00 raspberrypi systemd[1]: hostapd.service: Service RestartSec=100ms expired, s
Jan 03 11:15:00 raspberrypi systemd[1]: hostapd.service: Failed to schedule restart job: Uni
Jan 03 11:15:00 raspberrypi systemd[1]: hostapd.service: Failed with result 'exit-code'.

# Active: failedになっていた場合
$ systemctl reset-failed hostapd.service
# これでActive: inactiveになっているかを確認
$ systemctl status hostapd.service

● hostapd.service
   Loaded: masked (Reason: Unit hostapd.service is masked.)
   Active: inactive (dead) since Mon 2022-01-03 11:15:00 GMT; 1min 53s ago

Jan 03 11:15:00 raspberrypi systemd[1]: hostapd.service: Service RestartSec=100ms expired, s
Jan 03 11:15:00 raspberrypi systemd[1]: hostapd.service: Failed to schedule restart job: Uni
Jan 03 11:15:00 raspberrypi systemd[1]: hostapd.service: Failed with result 'exit-code'.

# 一応もう一回apt-get
$ sudo apt-get install hostapd

環境の確認

ifconfigwlan0を確認できればOK

参考
$ ifconfig

eth0: ~~~~~~~~~~~

lo: ~~~~~~~~~~~~~

wlan0: ~~~~~~~~~~

create_apをインストール

$ git clone https://github.com/oblique/create_ap
$ cd create_ap/
$ sudo make install

create_apを実行

SSH接続をしていた場合は一度切り、ラズパイにモニターとキーボードを接続し続行
実行コマンドなどの詳細は下記を参照

# これでアクセスポイントが立てられる筈だが...
$ sudo ./create_ap --no-virt -w 2 wlan0 eth0 SSID名 適当なパスワード

# 恐らく下記のエラーが出る(出なければ気にしなくてOK)
WARN: brmfmac driver doesn't work properly with virtual interfaces and
      it can cause kernel panic. For this reason we disallow virtual
      interfaces for your adapter.
      For more info: https://github.com/oblique/create_ap/issues/203
ERROR: Your adapter can not be a station (i.e. be connected) and an AP at the same time'

# 要は貴方のデバイスWi-Fi繋げたままアクセスポイントを立てられませんよとのこと
# なのでWi-Fiを切断し再度実行
# そうすると以下のようなエラーが出る場合がある
RTNETLINK answers: Operation not possible due to RF-kill
# これは無線LANが何故か無効化されてしまっているという事

# 以下で対処可能
$ sudo apt install rfkill
$ sudo nano /etc/rc.local

# `# By default this script does nothing.`以下に追記
/usr/sbin/rfkill unblock wifi

# これで再度実行すれば恐らく他デバイスでアクセスポイントが確認出来る
# 一応それに接続しSSH等出来れば成功

ipアドレスとかはどうなってるのだろう?

参考リンク

追記:hostapdを使ったアクセスポイント構築

WN-G300UAというWi-Fiアダプターを接続してアクセスポイントを構築しようとしたら、上記の手法では出来なかった。
なのでhostapd単体を使ったアクセスポイントを構築する。

hostapdをインストール

$ sudo apt-get install hostapd
# インストール後、一度hostapdを停止する
$ sudo systemctl stop hostapd

各種設定

まず/etc/dhcpcd.confに以下を記載

/etc/dhcpcd.conf
denyinterfaces wlan0
interface wlan0
# 192.168.xx.1/24 このxxの部分は取り敢えず現状のWi-Fiルータで使用しているものと被らない様にしておく
# ついでに末尾も.1
static ip_address=192.168.xx.1/24

次に/etc/network/interfacesを編集

/etc/network/interfaces
allow-hotplug wlan0
iface wlan0 inet static
# /etc/dhcpcd.confで設定したものと同じに
address 192.168.xx.1
netmask 255.255.255.0

/etc/hostapd/hostapd.confを編集

/etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=好きなSSID
hw_mode=g
channel=6
wmm_enabled=0
macaddr_acl=0
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=パスワード

/etc/default/hostapdを編集

/etc/default/hostapd
# 中にあるDAEMON_CONF=""のコメントアウトを外して以下を追記
DAEMON_CONF="/etc/hostapd/hostapd.conf"

自動で起動出来る様に設定する

/etc/rc.localを編集

/etc/rc.local
# 下の方にある fi exit 0 の間に追記
fi

/etc/init.d/hostapd start 

exit 0

dnsmasqをインストール

$ sudo apt-get install dnsmasq
# インストール後停止
$ sudo systemctl stop dnsmasq

各種設定

割り振られるIPアドレスの範囲を設定する。
/etc/dnsmasq.confを編集

/etc/dnsmasq.conf
interface=wlan0
# /etc/dhcpcd.confで設定したIPを192.168.xx.2, 192.168.xx.好きな範囲で設定
dhcp-range=192.168.xx.2,192.168.xx.好きな範囲,255.255.255.0,24h

システムの起動

恐らくhostapd関連でエラーが出るので事前に対処しておく

$ sudo systemctl unmask hostapd
$ sudo systemctl enable hostapd
$ sudo systemctl start hostapd

hostapddnsmasqを起動

$ sudo systemctl start hostapd
$ sudo systemctl start dnsmasq

再起動してアクセスポイントが確認出来れば完了

参考

完全にこちらを参考にしました

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?