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

Raspberry Pi で link local 接続が断続的に切断される

Last updated at Posted at 2025-04-07

Link local 接続。
固定アドレスが割り当てられていない環境でも、DHCPサーバ無しでリンクローカル用のIPアドレスが割り当てられてそのような機器同士で通信ができるようになる。

MS-Windows だと以下のようになる。

  • DHCP サーバーが外部にある環境だと DHCP クライアントになる
  • DHCP サーバーが無いとしばらくしてからリンクローカルアドレスが割り当てられる

ところが PC用のUbuntuだとこのような動作がデフォルトではならない。
image.png

リンクローカルを使いたい場合は「リンクローカルのみ」を選ばないといけない。

2023年頃の Raspberry Pi OS だと MS-Windows のように動作したけれども最近はそうではないっぽい。

Raspberry Pi OS での有線LAN。

  • Raspberry Pi OS Lite
  • Release date: October 22nd 2024
  • Raspberry Pi 3 model B

Raspberry Pi をターゲットにと有線LANでPeer to Peer 接続すると、一旦以下のようになる。

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::2eb4:2284:f900:6094  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:80:48:bb  txqueuelen 1000  (イーサネット)
        RX packets 66378  bytes 5746058 (5.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 125635  bytes 189790062 (180.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
.
.
.

ipv4 でのアドレスは無いものの、 ipv6 で fe80::2eb4:2284:f900:6094 アドレスが割り当てられている。しかしながらしばらくすると以下のように変化する。

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether b8:27:eb:80:48:bb  txqueuelen 1000  (イーサネット)
        RX packets 66381  bytes 5747084 (5.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 125638  bytes 189790612 (180.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
.
.
.

この時点で、 peer to peer 接続先の機器から Raspberry Pi にアクセスできなくなってしまう。
ログを確認すると以下のようなことが起こっていた。

$ sudo journalctl -f
.
.
.
 4月 06 23:14:11 itms NetworkManager[492]: <info>  [1743948851.0102] device (eth0): state change: ip-config -> failed (reason 'ip-config-unavailable', sys-iface-state: 'managed')
 4月 06 23:14:11 itms NetworkManager[492]: <warn>  [1743948851.0149] device (eth0): Activation: failed for connection '有線接続 1'
 4月 06 23:14:11 itms NetworkManager[492]: <info>  [1743948851.0171] device (eth0): state change: failed -> disconnected (reason 'none', sys-iface-state: 'managed')
 4月 06 23:14:11 itms avahi-daemon[420]: Withdrawing address record for fe80::2eb4:2284:f900:6094 on eth0.
 4月 06 23:14:11 itms avahi-daemon[420]: Leaving mDNS multicast group on interface eth0.IPv6 with address fe80::2eb4:2284:f900:6094.
 4月 06 23:14:11 itms avahi-daemon[420]: Interface eth0.IPv6 no longer relevant for mDNS.
 4月 06 23:14:11 itms NetworkManager[492]: <info>  [1743948851.0742] dhcp4 (eth0): canceled DHCP transaction
 4月 06 23:14:11 itms NetworkManager[492]: <info>  [1743948851.0743] dhcp4 (eth0): activation: beginning transaction (timeout in 45 seconds)
 4月 06 23:14:11 itms NetworkManager[492]: <info>  [1743948851.0744] dhcp4 (eth0): state changed no lease
.
.
.

このサイトで似た現象は起こっているが
「unstable ethernet connection (unexpected breaks) between two Raspberry Pi boards (unexpected link down/up events) · Issue #6327 · raspberrypi/linux」
https://github.com/raspberrypi/linux/issues/6327

今回は、間にHUBをつなげても解消しなかったので別の問題のようだ。

ログを見るに、

なんだか ipv4 のDHCPがgive up になったタイミングで ipv6 のアドレスが削除されているようだ。
state change: failed -> disconnected となっているのはどういうことかな・・・

$ nmcli
.
.
.
eth0: 切断済み
        "Microchip 7800"
        1 接続が利用可能
        ethernet (lan78xx), B8:27:EB:80:48:BB, hw, mtu 1500
.
.
.

切断済み というのは OSIのL1とかL2ではなく、L3層を示しているのかな?

link local と DHCP の有線接続ポートを分ける

Etnernet ポートのTCP/IP の設定は以下の通り。

$ nmcli connection show '有線接続 1' | grep method
ipv4.method:                            auto
ipv6.method:                            auto
proxy.method:                           none

これについて、 ipv4 を link locak 設定にすれば良いらしい。

cf.,
「linux - "Connecting...", "Connection failed. Activation of network connection failed" How to find out what does it mean exactly? (ping works) - Unix & Linux Stack Exchange」
https://unix.stackexchange.com/questions/685856/connecting-connection-failed-activation-of-network-connection-failed-ho
「Raspberry Pi 5 keeps dropping ethernet connection to PC [SOLVED] - Raspberry Pi Forums」
https://forums.raspberrypi.com/viewtopic.php?t=367676

これに基づき、今回は有線 Ethernet ポートを 2 つにして 1 つのポートを ipv4 の link local 専用とし、もう 1 つを DHCP 専用とすることにした。

USBポートに USB-Ethernetアダプタを刺してみると・・・

$ nmcli con
NAME        UUID                                  TYPE      DEVICE 
有線接続 1  b1c09dd7-79a2-3a18-b282-f111ca8e7c93  ethernet  eth0   
lo          d943d158-31fd-42d2-8268-4f9403942be3  loopback  lo     
openforce3  e3fbaa5f-4371-4aaa-8af7-33a425d4b857  wifi      wlan0  
有線接続 2  b42702af-a445-3062-9751-4f07de121629  ethernet  --     

有線接続2 が新たに生成されてこれが USB-Ethrnet アダプタのはずなのだけれど、うーん?

そのうえで '有線接続 1' の ipv4 を link locak 設定に。

こうしたら解決


$ sudo nmcli c m '有線接続 1' ipv4.method link-local

確認

$ nmcli connection show '有線接続 1' | grep method
ipv4.method:                            link-local
ipv6.method:                            auto
proxy.method:                           none

コレで大丈夫かな?

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.222  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fd75:3252:442c:10:f14:1e2b:c7e9:55f4  prefixlen 64  scopeid 0x0<global>
        inet6 fd75:3252:442c:10::c36  prefixlen 128  scopeid 0x0<global>
        inet6 2406:2d40:30ca:7210:489c:c8ba:8b13:b23d  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::ba54:6249:828e:35a0  prefixlen 64  scopeid 0x20<link>
        inet6 2406:2d40:30ca:7210::c36  prefixlen 128  scopeid 0x0<global>
        ether 4c:e6:76:55:2f:e7  txqueuelen 1000  (イーサネット)
        RX packets 1171  bytes 115432 (112.7 KiB)
        RX errors 0  dropped 3  overruns 0  frame 0
        TX packets 199  bytes 31190 (30.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::a97b:aea5:a429:be71  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:80:48:bb  txqueuelen 1000  (イーサネット)
        RX packets 8249  bytes 739973 (722.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 25333  bytes 38011738 (36.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

あれれ?

$ nmcli con
NAME        UUID                                  TYPE      DEVICE 
有線接続 1  b1c09dd7-79a2-3a18-b282-f111ca8e7c93  ethernet  eth0   
lo          d943d158-31fd-42d2-8268-4f9403942be3  loopback  lo     
openforce3  e3fbaa5f-4371-4aaa-8af7-33a425d4b857  wifi      wlan0  
有線接続 2  b42702af-a445-3062-9751-4f07de121629  ethernet  --     

eth1 の認識が変。
再起動したら・・・


$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 169.254.170.1  netmask 255.255.0.0  broadcast 169.254.255.255
        inet6 fe80::ba54:6249:828e:35a0  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:80:48:bb  txqueuelen 1000  (イーサネット)
        RX packets 5870  bytes 507892 (495.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 18331  bytes 27700875 (26.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.222  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::847b:12a3:5c22:8c8a  prefixlen 64  scopeid 0x20<link>
        inet6 2406:2d40:30ca:7210:b8e7:f9c9:a7f0:2af0  prefixlen 64  scopeid 0x0<global>
        inet6 2406:2d40:30ca:7210::dfd  prefixlen 128  scopeid 0x0<global>
        inet6 fd75:3252:442c:10::dfd  prefixlen 128  scopeid 0x0<global>
        inet6 fd75:3252:442c:10:679c:4547:c98f:49e6  prefixlen 64  scopeid 0x0<global>
        ether 4c:e6:76:55:2f:e7  txqueuelen 1000  (イーサネット)
        RX packets 51  bytes 13308 (12.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 57  bytes 9644 (9.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0 が ipv4 の link-local アドレスが割り振られ、eth1 が dhcp クライアントとなっていることがわかります。

$ nmcli con
NAME        UUID                                  TYPE      DEVICE 
有線接続 2  3a5ea60e-d19a-36fa-bf78-b88413146863  ethernet  eth1   
lo          4b9fb7e7-298a-43ae-92e9-cbb5c631d54f  loopback  lo     
openforce3  e3fbaa5f-4371-4aaa-8af7-33a425d4b857  wifi      wlan0  
有線接続 1  b1c09dd7-79a2-3a18-b282-f111ca8e7c93  ethernet  eth0   

再起動後は動作も正常なようです。

接続後数時間動作を検証してみましたが、 DHCP が鑑賞することもなくなりまた。

別方法

このような/etc/systemd/network/98-mypi.network (?) に設定を書くやり方があったが未検証

「networking - IPv4 link-local address with NetworkManager - Raspberry Pi Stack Exchange」
https://raspberrypi.stackexchange.com/questions/139913/ipv4-link-local-address-with-networkmanager

「networking - systemd.networkd: DHCP and link-local address - Unix & Linux Stack Exchange」
https://unix.stackexchange.com/questions/489520/systemd-networkd-dhcp-and-link-local-address

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