每次 Linux 启动时,我都必须手动使用以下两个命令才能建立有效的互联网连接。
ethtool -s eth0 autoneg off speed 100 duplex full
dhclient eth0
我正在寻找一种方法,以便当 Lubuntu 启动时互联网连接会自动启动。
/etc/network/interfaces
:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
#auto eth0
iface eth0 inet dhcp
ethtool -s eth0 autoneg off speed 100 duplex full
allow-hotplug eth0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
/etc/rc.local
:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo 500 > /sys/class/backlight/intel_backlight/brightness
xrandr -s 960x540
rfkill block bluetooth
rfkill block wifi
ethtool -s eth0 autoneg off speed 100 duplex full
ip link set eth0 up
ifup eth0
dhcpcd eth0
exit 0
systemctl status rc-local:
globalisation@WindowsXP:~$ systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset:
Drop-In: /lib/systemd/system/rc-local.service.d
└─debian.conf
Active: failed (Result: exit-code) since Sun 2017-06-04 00:31:28 CEST; 15min
Process: 636 ExecStart=/etc/rc.local start (code=exited, status=1/FAILURE)
Jun 04 00:31:27 WindowsXP systemd[1]: Starting /etc/rc.local Compatibility...
Jun 04 00:31:28 WindowsXP rc.local[636]: Can't open display
Jun 04 00:31:28 WindowsXP systemd[1]: rc-local.service: Control process exited,
Jun 04 00:31:28 WindowsXP systemd[1]: Failed to start /etc/rc.local Compatibilit
Jun 04 00:31:28 WindowsXP systemd[1]: rc-local.service: Unit entered failed stat
Jun 04 00:31:28 WindowsXP systemd[1]: rc-local.service: Failed with result 'exit
globalisation@WindowsXP:~$
Lubuntu 启动时出现以下错误:
Failed to start LSB: IPV4 DHCP client with IPV4ALL support.
See 'systemctl status dhcpcd.service' for details
16.780656 usb 1-1.4.3: device descriptor read/64, error -110
/etc/sysctl.conf
:
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additional system variables.
# See sysctl.conf (5) for information.
#
#kernel.domainname = example.com
# Uncomment the following to stop low-level messages on console
#kernel.printk = 3 4 1 3
##############################################################3
# Functions previously found in netbase
#
# Uncomment the next two lines to enable Spoof protection (reverse-path filter)
# Turn on Source Address Verification in all interfaces to
# prevent some spoofing attacks
#net.ipv4.conf.default.rp_filter=1
#net.ipv4.conf.all.rp_filter=1
# Uncomment the next line to enable TCP/IP SYN cookies
# See http://lwn.net/Articles/277146/
# Note: This may impact IPv6 TCP sessions too
#net.ipv4.tcp_syncookies=1
# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1
# Uncomment the next line to enable packet forwarding for IPv6
# Enabling this option disables Stateless Address Autoconfiguration
# based on Router Advertisements for this host
#net.ipv6.conf.all.forwarding=1
###################################################################
# Additional settings - these settings can improve the network
# security of the host and prevent against some network attacks
# including spoofing attacks and man in the middle attacks through
# redirection. Some network environments, however, require that these
# settings are disabled so review and enable them as needed.
#
# Do not accept ICMP redirects (prevent MITM attacks)
#net.ipv4.conf.all.accept_redirects = 0
#net.ipv6.conf.all.accept_redirects = 0
# _or_
# Accept ICMP redirects only for gateways listed in our default
# gateway list (enabled by default)
# net.ipv4.conf.all.secure_redirects = 1
#
# Do not send ICMP redirects (we are not a router)
#net.ipv4.conf.all.send_redirects = 0
#
# Do not accept IP source route packets (we are not a router)
#net.ipv4.conf.all.accept_source_route = 0
#net.ipv6.conf.all.accept_source_route = 0
#
# Log Martian Packets
#net.ipv4.conf.all.log_martians = 1
#
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
似乎dhclient eth0
在使用 MANDATORY ONE ethtool -s eth0 autoneg off speed 100 duplex full
(仍然所有命令只能手动生效)之后的第二个命令可以替换为 ifup eth0
以使互联网正常工作。
也许下一个日志的重要部分是Link detected: no
启动后如果立即执行第一个命令则ethtool eth0
输出为:
:~$ sudo ethtool eth0
[sudo] password for globalisation:
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: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: Symmetric Receive-only
Advertised auto-negotiation: Yes
Speed: 10Mb/s
Duplex: Half
Port: MII
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: pumbg
Wake-on: g
Current message level: 0x00000033 (51)
drv probe ifdown ifup
Link detected: no
我想补充一点,如果我仅将电缆从“讨论中的有问题的互联网连接”更改为“没有问题的”完全不同的 DSL 路由器连接(另一个 ISP,但仍然是相同的以太网电缆),即使在重启、关机后,也无需其他补充手动命令或任何其他操作,讨论中的同一台 Linux 机器也总是可以立即/直接地接收互联网连接
有问题的连接依赖于“讨论中”的手动命令,只有在手动命令之后才能访问互联网,它来自另一个 ISP,并且是同轴电缆/电视电缆调制解调器。
会不会是板载网卡的问题?
这台与“讨论中”的系统完全相同的机器,相同的以太网电缆,即使在重启/关机或任何我愿意做的事情后,也可以直接/立即接入/保持互联网,无需任何手动命令,只需将以太网电缆从这个“讨论中”的有问题的路由器移动到连接到另一个 ISP 上的另一个互联网连接的另一个路由器即可。
路由器上的相同端口使用相同的电缆,即使是来自讨论中的有问题的路由器,Windows 7 和 Windows 10 也可以立即/直接连接到互联网,无需任何点击或补充点击,只需将电缆从 Linux 机器更改为 Windows 机器即可。
如果您有任何想法,知道这种情况是如何发生的,我刚刚记得,在讨论中,同一台机器+相同的操作系统(Linux 没有改变的配置)+相同的以太网电缆始终从所有 3 种不同型号的路由器自动“接收并保持”互联网(无需额外的手动命令)。
除第四个有问题的连接和路由器外,所有 3 个连接和路由器均来自同一 ISP。
最好的祝愿。
答案1
这似乎是最终的结果,为了在重启/关机/睡眠后自动访问互联网,不再需要手动命令:
/etc/网络/接口
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
iface eth0 inet dhcp
pre-up ethtool -s eth0 autoneg off speed 100 duplex full
allow-hotplug eth0
/etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo 70 > /sys/class/backlight/intel_backlight/brightness
rfkill block bluetooth
rfkill block wifi
ethtool -s eth0 autoneg off speed 100 duplex full
ip link set eth0 up
exit 0