網路連線僅在手動啟動時可用

網路連線僅在手動啟動時可用

每次 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將使用強制命令後的第二個命令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

我想補充一點,如果我只將電纜從“討論中的問題”中更改,即使在重新啟動、關機後,沒有其他補充手動命令或任何其他操作,討論中的同一台Linux 機器也總是立即/直接接收網路連線網路連線」到「沒有問題」的完全不同的 DSL 路由器連線(另一個 ISP,但仍然是相同的乙太網路線)

有問題的連接依賴於“正在討論”的手動命令,只有在手動命令之後才有互聯網,來自另一個 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

相關內容