1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NetworkManager を使って Raspberry Pi をアクセスポイントにする

Last updated at Posted at 2025-12-13

はじめに

最近 IoT を齧り始めたのですが、
Raspberry Pi をアクセスポイントにして簡単な無線 LAN を作りたくなりました。

調べてみると hostapddnsmasq を使った実装が多かったのですが、NetworkManager が入っている場合は、NetworkManager の設定をするだけで構築するのことができました。

この記事では、NetworkManager を使って、Raspberry Pi をアクセスポイントにする方法をまとめます。

環境

  • ハードウェア: Raspberry Pi 5
  • OS:
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

前提

上記の環境の場合、デフォルトで入っていると思いますが、NetworkManager がインストールされていてる必要があります。

$ sudo systemctl status NetworkManager
● NetworkManager.service - Network Manager
     Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; preset: enabled)
     Active: active (running) since Tue 2025-09-30 03:40:11 JST; 2 months 13 days ago
       Docs: man:NetworkManager(8)
   Main PID: 697 (NetworkManager)
      Tasks: 3 (limit: 4756)
        CPU: 334ms
     CGroup: /system.slice/NetworkManager.service
             └─697 /usr/sbin/NetworkManager --no-daemon

また、ワイヤレス通信用のネットワークインターフェースも必要になります。
これは上記と同じ環境だと、おそらく wlan0 という名前で最初から存在しているはずです。

$ nmcli dev show wlan0
GENERAL.DEVICE:                         wlan0
GENERAL.TYPE:                           wifi
GENERAL.HWADDR:                         XX:XX:XX:XX:XX:XX
GENERAL.MTU:                            1500
GENERAL.STATE:                          30 (disconnected)
GENERAL.CONNECTION:                     --
GENERAL.CON-PATH:                       --
IP4.GATEWAY:                            --
IP6.GATEWAY:                            --

設定

ワイヤレス通信ができるようにする

おそらく初期状態だと、ワイヤレス通信ができないようになっているはずです。

$ nmcli radio wifi
disabled

Enable wireless networking

On a fresh install, you must specify the country where you use your device. This allows your device to choose the correct frequency bands for 5GHz networking. Once you have specified a wireless LAN country, you can use your Raspberry Pi’s built-in wireless networking module.

と書かれている通り、WLAN country を選択しないとワイヤレス通信ができないので、その設定をします。

$ iw reg get
global
country 00: DFS-UNSET

$ sudo raspi-config nonint do_wifi_country JP

$ iw reg get
global
country JP: DFS-JP

$ nmcli radio wifi
enabled

コネクションの作成

対象のネットワークインターフェース(今回だとwlan0)をアクセスポイントとして動作させるための、コネクションを作成します。

$ nmcli connection add \
  type wifi \
  ifname wlan0 \
  con-name con-my-ap \
  ssid my-ap

この例だと、

  • 接続タイプ: Wi-Fi
  • 対象のネットワークインターフェース: wlan0
  • 接続名: con-my-ap
  • ssid: my-ap

として作成しています。
そのほかにもオプションは結構あるので、man nmcil などで確認していただけます。

作成されたコネクションの詳細は以下のコマンドで確認することができます。

$ nmcli connection show con-my-ap

コネクションをアクセスポイントモードに変更する

$ sudo nmcli connection modify con-my-ap wifi.mode ap

wifi802-11-wireless のエイリアスになっているので、以下の指定方法でも同じ結果を得ることができます。

$ nmcli connection modify con-my-ap 802-11-wireless.mode ap 

この辺の設定に関しては、

で確認することができます。

IP アドレスの割り当て

アクセスポイントモードに変更すると、IPアドレスの設定が必要になるので設定します。

$ sudo nmcli connection modify con-my-ap ipv4.method shared

For IPv4 method "shared", the IP subnet can be configured by adding one manual IPv4 address or otherwise 10.42.x.0/24 is chosen. Note that the shared method must be configured on the interface which shares the internet to a subnet, not on the uplink which is shared.

shared を指定して、特に IP address を指定しなかった場合は、10.42.x.0/24 が割り当てられるようになります。
この時点で、アクセスポイントとして動かすための必要最低限の設定が揃ったので、接続が可能になります。

capture.jpg

パスワードと認証方式を設定する

さすがに、認証なしのアクセスポイントのまま運用するのはよろしくないので、パスワードと認証方式を設定します。
https://networkmanager.dev/docs/api/latest/settings-802-11-wireless-security.html

$ sudo nmcli connection modify con-my-ap \
  wifi-sec.key-mgmt wpa-psk \
  wifi-sec.psk password

wifi-sec802-11-wireless-security のエイリアスになっているので、以下の指定方法でも同じ結果を得ることができます。

$ sudo nmcli connection modify con-my-ap \
  802-11-wireless-security.key-mgmt wpa-psk \
  802-11-wireless-security.psk password

設定が完了したら、connection を上げなおします。

$ sudo nmcli connection down con-my-ap
$ sudo nmcli conneciton up con-my-ap

再度繋いでみると、パスワードが必要になっていることがわかります。

capture.jpg

一気にやりたい時

逐次的にやったほうがわかりやすいと思ったので、上記のように記載していますが、
nmcli device wifi hotspot を使うと、全て指定して作成することができます。

$ man nmcli
# ...

DEVICE MANAGEMENT COMMANDS
       nmcli device {status | show | set | up | connect | reapply | modify | down | disconnect | delete | monitor | wifi | lldp |
                    checkpoint} [ARGUMENTS...]

       Show and manage network interfaces.

# ...

       wifi hotspot [ifname ifname] [con-name name] [ssid SSID] [band {a | bg}] [channel channel] [password password]
           Create a Wi-Fi hotspot. The command creates a hotspot connection profile according to Wi-Fi device capabilities and
           activates it on the device. The hotspot is secured with WPA if device/driver supports that, otherwise WEP is used. Use
           connection down or device down to stop the hotspot.

           Parameters of the hotspot can be influenced by the optional parameters:

           ifname
               what Wi-Fi device is used.

           con-name
               name of the created hotspot connection profile.

           ssid
               SSID of the hotspot.

           band
               Wi-Fi band to use.

           channel
               Wi-Fi channel to use.

           password
               password to use for the created hotspot. If not provided, nmcli will generate a password. The password is either WPA
               pre-shared key or WEP key.

               Note that --show-secrets global option can be used to print the hotspot password. It is useful especially when the
               password was generated.
$ sudo nmcli device wifi hotspot \
  ifname wlan0 \
  con-name con-my-ap \
  ssid my-ap \
  password password

こっちのコマンドを使ってやると、pairwise などの設定も自動的にされるようです。

3c3
< uuid=b2e55545-3d96-4638-a6c3-09a057354374
---
> uuid=4d60a53e-6ada-4331-bedb-7865a0a377ec
4a5
> autoconnect=false
6d6
< timestamp=1765617368
12a13
> group=ccmp;
13a15,16
> pairwise=ccmp;
> proto=rsn;
21c24
< method=auto
---
> method=ignore

設定ファイル

今回は、nmcli を使って設定をしましたが、これらは設定ファイルで管理できます。
/etc/NetworkManager/system-connections/{con-name}.nmconnectionに設定ファイルが作成されているはずです。

参考

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?