4GPiのネットワーク環境を設定

githubの4GPiの説明ページ
https://github.com/mechatrax/4gpi/wiki
Raspberry Piを使って屋外利用可能なIoTゲートウェイを作る（Pi-protect）
https://qiita.com/ieking/items/a77f196db61035708993
ラズパイ+4GPiでLTEルータを作る（Wi-Fi・有線LAN 両対応）
https://qiita.com/ieking/items/5c976d09c3ca55a649e5
### メカトラックスのOSイメージから構築
このOSイメージを使用
https://github.com/mechatrax/4gpi/blob/main/os/4gpi-bookworm-lite-arm64-20240319.md
1. OSイメージをmicroSDに書き込み、Windows用アプリは「rufus-4.4.exe」を使用
1. ユーザー「raspi」パスワード「raspi」
1. 「sudo raspi-config」でSSHをインストール、WindowsからTeraTermでログイン
```
$ cat /proc/device-tree/model
Raspberry Pi 3 Model B Plus Rev 1.3
$ uname -a
Linux raspberrypi 6.6.20+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.20-1+rpt1 (2024-03-07) aarch64 GNU/Linux
$ 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/"
$ sudo raspi-config
5 Localisation Options Configure language and regional settings
L4 WLAN Country Set legal wireless channels for your country
JP Japan
```
### wlan0用アクセスポイントを追加
```
sudo nmcli connection add con-name wifi-wlan0 type wifi ssid RPiAP
sudo nmcli connection modify wifi-wlan0 ifname wlan0
sudo nmcli connection modify wifi-wlan0 autoconnect yes
sudo nmcli connection modify wifi-wlan0 802-11-wireless.mode ap
sudo nmcli connection modify wifi-wlan0 802-11-wireless.band bg
sudo nmcli connection modify wifi-wlan0 wifi-sec.key-mgmt wpa-psk
sudo nmcli connection modify wifi-wlan0 wifi-sec.pairwise ccmp
sudo nmcli connection modify wifi-wlan0 wifi-sec.proto rsn
sudo nmcli connection modify wifi-wlan0 wifi-sec.psk "1234567890123456"
sudo nmcli connection modify wifi-wlan0 ipv4.addresses 192.168.249.1/24
sudo nmcli connection modify wifi-wlan0 ipv4.method manual
sudo nmcli connection up wifi-wlan0
```
状態を参照
```
$ nmcli connection
NAME                UUID                                  TYPE      DEVICE
Wired connection 1  e28a7cca-8daf-3c89-9286-fe736ca0432b  ethernet  eth0
lo                  d6247aa4-d5f1-4497-988e-bee2d65cafec  loopback  lo
wifi-wlan0          056ee7a8-3a00-4bfc-902a-7534472d479c  wifi      wlan0
$ ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000
    link/ether b8:27:eb:c8:15:09 brd ff:ff:ff:ff:ff:ff
    inet 192.168.213.116/24 brd 192.168.213.255 scope global dynamic noprefixroute eth0
       valid_lft 86067sec preferred_lft 86067sec
    inet6 2402:6b00:de24:3700:8586:d9ef:44fa:7996/64 scope global dynamic noprefixroute
       valid_lft 275sec preferred_lft 275sec
    inet6 fe80::7167:91f5:5d73:7226/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000
    link/ether b8:27:eb:9d:40:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.249.1/24 brd 192.168.249.255 scope global noprefixroute wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::17a5:a30a:c17d:6fad/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
$ sudo cat /etc/NetworkManager/system-connections/wifi-wlan0.nmconnection
[connection]
id=wifi-wlan0
uuid=056ee7a8-3a00-4bfc-902a-7534472d479c
type=wifi
interface-name=wlan0

[wifi]
band=bg
mode=ap
ssid=RPiAP

[wifi-security]
key-mgmt=wpa-psk
pairwise=ccmp;
proto=rsn;
psk=1234567890123456

[ipv4]
address1=192.168.249.1/24
method=manual

[ipv6]
addr-gen-mode=default
method=auto

[proxy]
```
### wlan0用DHCPServerを追加
```
sudo apt -y install dnsmasq
```
wlan0のDHCP割り振りアドレス範囲を設定
```
$ sudo vi /etc/dnsmasq.conf
長いので省略
以下を末尾に追加
interface=wlan0
dhcp-range=192.168.249.50,192.168.249.150,255.255.255.0,12h
$ sudo systemctl restart dnsmasq
```
### 4GPi用インターフェースwwan0を追加
NipponSIMを使用
APN「m-air.jp」
```
$ sudo nmcli connection add type gsm ifname "*" con-name gsm-4gpi-nippon apn m-air.jp user "*" password "*"
Connection 'gsm-4gpi-nippon' (ea91c2d6-d071-403e-804f-a73342f80b3f) successfully added.
$ sudo nmcli connection up gsm-4gpi-nippon
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
```
状態を参照
```
$ nmcli connection
NAME             UUID                                  TYPE      DEVICE
eth0-s           d24efc82-c622-4a25-afe1-9b11832ad2ed  ethernet  eth0
lo               0415265d-7d55-4726-86a4-e34661e740a7  loopback  lo
wifi-wlan0       056ee7a8-3a00-4bfc-902a-7534472d479c  wifi      wlan0
gsm-4gpi-nippon  ea91c2d6-d071-403e-804f-a73342f80b3f  gsm       cdc-wdm0
$ ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000
    link/ether b8:27:eb:c8:15:09 brd ff:ff:ff:ff:ff:ff
    inet 192.168.213.81/24 brd 192.168.213.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 2402:6b00:de24:3700:2b5d:1bc9:46ea:3701/64 scope global dynamic noprefixroute
       valid_lft 273sec preferred_lft 273sec
    inet6 fe80::a319:8e72:547:7b81/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000
    link/ether b8:27:eb:9d:40:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.249.1/24 brd 192.168.249.255 scope global noprefixroute wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::17a5:a30a:c17d:6fad/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
4: wwan0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq state UNKNOWN group default qlen 1000
    link/none
    inet 10.40.8.64/25 brd 10.40.8.127 scope global noprefixroute wwan0
       valid_lft forever preferred_lft forever
$ sudo cat /etc/NetworkManager/system-connections/gsm-4gpi-nippon.nmconnection
[connection]
id=gsm-4gpi-nippon
uuid=ea91c2d6-d071-403e-804f-a73342f80b3f
type=gsm

[gsm]
apn=m-air.jp
password=*
username=*

[ipv4]
method=auto

[ipv6]
addr-gen-mode=default
method=auto

[proxy]
raspi@raspberrypi:~ $
```
### ルーティングを参照
```
$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.40.26.229    0.0.0.0         UG    700    0        0 wwan0
10.40.26.228    0.0.0.0         255.255.255.252 U     700    0        0 wwan0
192.168.213.0   0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.249.0   0.0.0.0         255.255.255.0   U     600    0        0 wlan0
$ ping www.yahoo.co.jp
PING edge12.g.yimg.jp (182.22.25.252) 56(84) bytes of data.
64 bytes from 182.22.25.252 (182.22.25.252): icmp_seq=1 ttl=57 time=62.3 ms
64 bytes from 182.22.25.252 (182.22.25.252): icmp_seq=2 ttl=57 time=53.8 ms
64 bytes from 182.22.25.252 (182.22.25.252): icmp_seq=3 ttl=57 time=52.8 ms
64 bytes from 182.22.25.252 (182.22.25.252): icmp_seq=4 ttl=57 time=61.8 ms
^C
--- edge12.g.yimg.jp ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 52.806/57.674/62.301/4.405 ms
```
### Ethernetを静的アドレスで設定する場合
リンク https://qiita.com/carpenders/items/179ac990467b0ca6eb89#ethernet%E3%82%92%E9%9D%99%E7%9A%84%E3%82%A2%E3%83%89%E3%83%AC%E3%82%B9%E3%81%A7%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B%E5%A0%B4%E5%90%88