RaspberryPiにWifiAPとEthernetを設定 nmcli有り

### nmcliコマンドを使う
リンク https://qiita.com/carpenders/items/c79ba9f6672d431fa8c7
### 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
```
### wlan0用アクセスポイントを追加
nmcliコマンドで設定、設定値説明「man nm-settings」
```
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
```
SSH接続しているインターフェースを変更すると接続が切れる、再接続して結果を確認
```
$ ip address show dev wlan0
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast 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::348d:a104:5c28:9171/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
$ sudo cat /etc/NetworkManager/system-connections/wifi-wlan0.nmconnection
[connection]
id=wifi-wlan0
uuid=979aa4c8-d25c-4733-b7da-d947b1c9dbc6
type=wifi
interface-name=wlan0
timestamp=1711271622

[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]
```
### Ethernetを静的アドレスで設定する場合
```
sudo nmcli connection add con-name eth0-s type ethernet
sudo nmcli connection modify eth0-s ifname eth0
sudo nmcli connection modify eth0-s connection.autoconnect yes
sudo nmcli connection modify eth0-s ipv4.addresses 192.168.213.81/24
sudo nmcli connection modify eth0-s ipv4.method manual
sudo nmcli connection up eth0-s
```
eth0-sでインターネット接続したい場合はupの前に以下を追加
```
sudo nmcli connection modify eth0-s ipv4.dns 192.168.213.1
sudo nmcli connection modify eth0-s ipv4.gateway 192.168.213.1
```
すると以下が設定される
```
$ cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.213.1
nameserver 2402:6b00:de24:3700:1266:82ff:fec0:3404
```
SSH接続しているインターフェースを変更すると接続が切れる、再接続して結果を確認
```
$ ip address show eth0
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 268sec preferred_lft 268sec
    inet6 fe80::a319:8e72:547:7b81/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
$ sudo cat /etc/NetworkManager/system-connections/eth0-s.nmconnection
[connection]
id=eth0-s
uuid=d24efc82-c622-4a25-afe1-9b11832ad2ed
type=ethernet
interface-name=eth0

[ethernet]

[ipv4]
address1=192.168.213.81/24
method=manual

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

[proxy]
```
### Ethernetを動的アドレスで設定する場合
```
sudo nmcli connection add con-name eth0-d type ethernet
sudo nmcli connection modify eth0-d ifname eth0
sudo nmcli connection modify eth0-d connection.autoconnect yes
sudo nmcli connection modify eth0-d ipv4.method auto
sudo nmcli connection up eth0-d
```
### その他
ブリッジ化
https://kassyjp.ninja-web.net/ras/jessie/bridge.htm