rokkonet

PC・Androidソフトウェア・アプリの開発・使い方に関するメモ

Ubuntu 20.04 Realtekチップ ネットワークトラブル・ネットワーク切断対応

2022 Jul. 17.

出典 Ubuntu18.04でスリープ後ネットワークが繋がらなくなった話 - Qiita


ネットワークチップの確認
$ lspci
    Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 11)

$ sudo lshw -C network | grep "driver="
       設定: autonegotiation=on broadcast=yes driver=r8169 driverversion=5.15.0-41-generic duplex=full firmware=rtl8168g-2_0.0.1 02/06/13 ip=192.168.1.1 latency=0 link=yes multicast=yes port=twisted pair speed=100Mbit/s

$ lsmod
    r8169 


概要

システムスリープ開始時にネットワークデバイスドライバを再読み込みする設定にする

対処

/lib/systemd/system-sleep/r8169-refresh.shをセットする

/lib/systemd/system-sleep/r8169-refresh.sh

#!/bin/bash

# 2022 Jul. 17.

# This is a copy from https://qiita.com/tk_01/items/c1bbd844f38575f84f7b

PROGNAME=${0##*/}
state=$1
action=$2

function log {
      logger -i -t "$PROGNAME" "$*"
}

log "Running $action $state"

if [[ $state == post ]]; then
    modprobe -r r8169 \
      && log "Removed r8169" \
      && modprobe -i r8169 \
      && log "Inserted r8169"
fi
exit 0