树莓派使用ethtool永久配置网口信息与工作模式

1、安装ethtool软件

使用指令
sudo apt-get install ethtool

成功显示:

pi@jcr:~ $ sudo apt-get install ethtool
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
ethtool is already the newest version (1:5.9-1).
0 upgraded, 0 newly installed, 0 to remove and 46 not upgraded.

2、查看当前网口状态

如查看eth0:使用指令
ethtool eth0

成功显示:

pi@raspberrypi:~ $ ethtool eth0
Settings for eth0:
        Supported ports: [ TP    MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Supported pause frame use: Symmetric Receive-only
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Advertised pause frame use: Symmetric Receive-only
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Link partner advertised link modes:  10baseT/Half 10baseT/Full
                                             100baseT/Half 100baseT/Full
                                             1000baseT/Full
        Link partner advertised pause frame use: Symmetric Receive-only
        Link partner advertised auto-negotiation: Yes
        Link partner advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Auto-negotiation: on
        master-slave cfg: preferred slave
        master-slave status: slave
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: external
        MDI-X: Unknown
netlink error: Operation not permitted
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes

3、打开网络配置文件:

使用指令

sudo nano /etc/network/interfaces

4、编辑接口配置:找到你的以太网接口配置(通常是eth0),并添加pre-up命令来设定速度、双工模式和关闭自动协商。例如,要设置100Mbps的速度和半双工模式,可以添加如下行:

添加命令

auto eth0
iface eth0 inet dhcp
    pre-up sleep 2 & ethtool -s eth0 speed 100 duplex half autoneg off

如果你的树莓派使用静态IP,确保保留或正确配置相应的静态IP设置。

5、保存并退出,然后重启网络服务使更改生效:

使用指令

sudo systemctl restart networking

6、完成后重启树莓派查看

使用指令

sudo reboot
#重启完成后使用指令
ethtool eth0

成功显示

pi@raspberrypi:~ $ ethtool eth0
Settings for eth0:
        Supported ports: [ TP    MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Supported pause frame use: Symmetric Receive-only
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Advertised pause frame use: Symmetric Receive-only
        Advertised auto-negotiation: No
        Advertised FEC modes: Not reported
        Speed: 100Mb/s
        Duplex: Half
        Auto-negotiation: off
        master-slave cfg: preferred slave
        master-slave status: slave
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: external
        MDI-X: Unknown
netlink error: Operation not permitted
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes

posted @ 2024-06-12 10:01  菜鸟计算机  阅读(352)  评论(0)    收藏  举报