<< 2026年02月
新着記事
最近のコメント
月別
カテゴリ
2026.02.07 22:34

RaspberryPiZero2WのAP化(2/8追記)


・雪が振りそうとかいうお天気で、外出を中止してちょっと時間ができたので、キーボードの上に敷く布の作成
・といっても、四角く切って端を折ってミシンがけするだけなので簡単。以前買っていた生地もでてきたので2つ作って1時間もかからなかった。
・というところで、以前買った3Dプリンタを外部につながらないLAN・・・ローカルエリアなネットワークだけで使おうということでルーターを考えていたのだけど、考えたらRaspberryPi Zero2Wもアクセスポイント化できるだろう。
・ということで、Geminiに聞きながらあれこれ設定をいじっていたらできた。スマホやPCからSSIDを指定して接続し、自分で決めたパスワードを入れるとちゃんと接続された。
・これで、
 Bambu Studio用のLinux仮想マシンを作る
 USB-WiFiドングルをPCに取り付け
 USB-WiFiだけをBambu Studio仮想マシンに接続する
とやれば、あとはスッキリいける・・・はずだし、BambuStudioが勝手に外に出ていくこともできない・・・はず。
ーーー
2/8追記:
ということで、設定方法のメモを残しておこう。RaspberryPiのIPアドレスは、192.168.50.1で、DHCPで192.168.50.100-200を割り当てることを想定
これでうまく動けばRaspberryPiのAPに接続して
ssh (user名)@192.168.50.1
とかやってユーザのパスワードを入れてsshで遊ぶこともできる
LANアダプタを追加してルータ化する手もあるけども、それはまた後日としよう。

・必要なもの
 sudo apt install hostapd
 sudo apt install dnsmasq

あとsystemd-networkdも要るけど、既に入ってる?(失念)
 sudo systemctl enable sshもついでにやっておく

・/etc/hostapd/hostapd.confを作成。中身は
interface=wlan0
ssid=(SSIDの文字列)
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=0

auth_algs=1
wpa=2
wpa_passphrase=(パスワード文字列)
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

ctrl_interface=/var/run/hostapd
ctrl_interface_group=0

・/etc/default/hostapdに追記
DAEMON_CONF="/etc/hostapd/hostapd.conf"

・/etc/systemd/network/10-wlan0.networkを作成(固定IPで作成)。中身は
[Match]
Name=wlan0

[Network]
Address=192.168.50.1/24
ConfigureWithoutCarrier=yes

systemd-networkdの有効化
sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd

(動作確認)
systemctl status systemd-networkd
active(runningならOK)

・/etc/dnsmasq.confの後ろに追記
interface=wlan0
dhcp-range=192.168.50.100,192.168.50.200,255.255.255.0,24h

(孤立LANなので下記は無意味だけど入れておいても良い)
domain-needed (ドメイン名の無い名前をDNSに問い合わせしない)
bogus-priv (ローカルのIP逆引き問い合わせをしない)

・hostapdとdnsmasqを起動
sudo systemctl unmask hostapd
sudo systemctl enable hostapd dnsmasq
sudo systemctl restart hostapd dnsmasq

・特定のデバイスに固定IPを割り振りたい時は
/etc/dnsmasq.confに下記のような具合に追記する(最後につけるのはデバイスの名称:省略可能だけど、つけるとping SmartPhoneみたいに名前が使える)

dhcp-host=aa:bb:cc:dd:ee:ff,192.168.50.10,SmartPhone
(DHCPの払い出し範囲を避けること)

書き換えたら
sudo systemctl restart dnsmasq
でdnsmasqの再起動も忘れずに

・動作状態確認コマンド集
AP(アクセスポイント)が動いているか(hostapd)
systemctl status hostapd
 =>Active: active (running)
 になっていればOK

APのインターフェースの状態
iw dev
 =>Interface wlan0
type AP
 ならOK

hostapdログ
journalctl -u hostapd -e
 =>wlan0: AP-ENABLED
 ならOK

DHCP(dnsmasq)が動いているか
systemctl status dnsmasq

DHCP払い出しログ
journalctl -u dnsmasq -e
 => DHCPDISCOVER(wlan0)
   DHCPOFFER(wlan0)
  DHCPREQUEST(wlan0)
   DHCPACK(wlan0)

RaspberryPi自身のIP
ip addr show wlan0
hostname ーI でも良い

接続している端末一覧
arp -a
ip neigh でも良い

接続中のクライアントの情報(WiFiレベル)
iw dev wlan0 station dump

まとめて確認
systemctl --no-pager status hostapd dnsmasq
ip addr show wlan0
iw dev wlan0 station dump