なにかの技術メモ置き場

なにかの技術メモ置き場

@インフラエンジニア

/etc/rc.d/rc.local@CentOS7の落とし穴

CentOS7でWake on LAN(以下wol)の設定に苦戦した話。

試行錯誤

CentOS6の頃は以下の2通りの方法があり、前者を使用していた。
・/etc/sysconfig/network-scripts/ifcfg-【IF名】内にオプションとして記載
・/etc/rc.d/rc.localに設定コマンドを記載

しかし今回はいずれも期待通りに動作しない。
Web上の情報も少なく、試行錯誤の末に気付いたのが以下の注意書き。

/etc/rc.d/rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In constrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

『システムのブート時にこのスクリプトが確実に実行されるようにするため、'chmod +x /etc/rc.d/rc.local'しておくように。』とのこと。
ええ?
確認してみると確かに実行権限がない。てっきりデフォルトで付与されているものかと・・・。

設定方法

ついでにwolの設定方法まとめ(OS上の設定のみ)。

wolの有効/無効を確認。

# ethtool 【IF名】
Settings for 【IF名】:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Advertised link modes:  Not reported
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: pg
        Wake-on: d	# d:無効
        Current message level: 0x0000003f (63)
                               drv probe link timer ifdown ifup
        Link detected: yes

システム再起動後も有効となるよう設定。

vi /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In constrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

/sbin/ethtool -s 【IF名】 wol g

設定ファイルがシステム起動時に実行されるよう設定。

# chmod +x /etc/rc.d/rc.local
#
# ls -l /etc/rc.d/rc.local
--rwxr-xr-x. 1 root root 290  8月  3 23:25 2014 /etc/rc.d/rc.local

システム再起動後、再度wol有効/無効を確認。

# ethtool 【IF名】
Settings for 【IF名】:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Advertised link modes:  Not reported
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: pg
        Wake-on: g	# g:有効
        Current message level: 0x0000003f (63)
                               drv probe link timer ifdown ifup
        Link detected: yes

以上。思い込みによる落とし穴にはまった件。