天天看点

如何解决与驱动相关的Linux网络问题

linux机器上与网络有关的问题很难解决,因为这已经超出Linux所信任的环境

之外了。但是作为Linux管理员,你可以通过使用正确的技术帮助网络管理员解决难题。在本文中,TechTarget中国的特约专家Sander

van Vugt将介绍如何解决与驱动相关的网络问题。

  要确定你遇到的问题与网络相关很简单:如果你的计算机不能与其他计算机通信,网络就有问题。但是很难找到问题根源。你需要从分析网络通信里包含的各种

元素入手。

  如果你的主机需要与网络中的其他主机通信,必须具备以下条件:

1.安装了网卡并能用于操作系统,例如载入了正确驱动。

2.网卡分配有IP地址。

3.计算机能与同个网络中的其他主机通信。

4.计算机能与其他网络中的其他主机通信。

5.计算机能使用其主机名与其他主机通信。

  解决网络驱动问题

  要与网络上的其他计算机通信,你的计算机需要一个网络接口。计算机要获取网络接口的方式设计得很好。在系统启动期间,内核探测不同的可用接口,一般位

于PCI bus上,找到一个网卡。接下来确定需要哪个驱动记录网卡,驱动是否可用,它将记录网卡。随后,udev

daemon(udevd)在计算机的初始启动阶段启动,并创建网络设备。在只有一个网络接口的计算机里,这一般是eth0设备,不过随后其他设备也能使

用。一旦载入接口,下一步骤为网卡获取IP地址就可以跳过。

  正如我们所讨论的,为网卡正确载入驱动包含以下一些条款:

1.内核探测PCI bus。

2.基于信息查找载入到PCI bus的驱动。

3.Udev创建网络接口。

  要修复网络问题,通过确定网卡是否真的在PCI-bus上开始。可以使用lspci命令进行确认。下面是lspci的例子:

JBO:~ # lspci

00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host

bridge (rev 01)

00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP

00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)

00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev

01)

00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)

00:07.7 System peripheral: VMware Inc Virtual Machine Communication

Interface (rev 10)

00:0f.0 VGA compatible controller: VMware Inc Abstract SVGA II Adapter

00:10.0 SCSI storage controller: LSI Logic /

Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)

02:00.0 USB Controller: Intel Corporation 82371AB/EB/MB PIIX4 USB

02:01.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970

[PCnet32 LANCE] (rev 10)

02:02.0 Multimedia audio controller: Ensoniq ES1371 [AudioPCI-97] (rev

02)

02:03.0 USB Controller: VMware Inc Abstract USB2 EHCI Controller

JBO:~ #

  在这里,以太网网卡上找到了PCI地址02:01.0。这个网卡是AMD 79c970(括号之间),并且需要PCnet32

kernel内核模块定位这个网卡。

  下一步是检查反映在/sys架构里的硬件配置。每个PCI设备都在这里存储了自己的配置,本例中还包括网卡配置,它存储在目录/sys/bus

/pci/devices/0000:02:01.0里,这反映了设备在PCI bus上地址。下面是该目录内容的例子:

JBO:/sys/bus/pci/devices/0000:02:01.0 # ls -l

total 0

-rw-r--r-- 1 root root 4096 Oct 18 07:08 broken_parity_status

-r--r--r-- 1 root root 4096 Oct 17 07:50 class

-rw-r--r-- 1 root root 256 Oct 17 07:50 config

-r--r--r-- 1 root root 4096 Oct 17 07:50 device

lrwxrwxrwx 1 root root 0 Oct 17 07:51 driver ->

../../../../bus/pci/drivers/pcnet32

-rw------- 1 root root 4096 Oct 18 07:08 enable

lrwxrwxrwx 1 root root 0 Oct 18 07:08 firmware_node ->

../../../LNXSYSTM:00/device:00/PNP0A03:00/device:06/device:08

-r--r--r-- 1 root root 4096 Oct 17 07:50 irq

-r--r--r-- 1 root root 4096 Oct 18 07:08 local_cpulist

-r--r--r-- 1 root root 4096 Oct 18 07:08 local_cpus

-r--r--r-- 1 root root 4096 Oct 17 07:53 modalias

-rw-r--r-- 1 root root 4096 Oct 18 07:08 msi_bus

drwxr-xr-x 3 root root 0 Oct 17 07:50 net

-r--r--r-- 1 root root 4096 Oct 18 07:08 numa_node

drwxr-xr-x 2 root root 0 Oct 18 07:08 power

-r--r--r-- 1 root root 4096 Oct 17 07:50 resource

-rw------- 1 root root 128 Oct 18 07:08 resource0

-r-------- 1 root root 65536 Oct 18 07:08 rom

lrwxrwxrwx 1 root root 0 Oct 17 07:50 subsystem ->

../../../../bus/pci

-r--r--r-- 1 root root 4096 Oct 17 07:51 subsystem_device

-r--r--r-- 1 root root 4096 Oct 17 07:51 subsystem_vendor

-rw-r--r-- 1 root root 4096 Oct 17 07:51 uevent

-r--r--r-- 1 root root 4096 Oct 17 07:50 vendor

JBO:/sys/bus/pci/devices/0000:02:01.0 #

  检修中最有趣的条款是到驱动目录的链接文件。本例中指向pcnet32驱动,并使用lspci提供的信息,我们知道这是正确的驱动。

  多数情况下,Linux安装的驱动运行得很好。有些情况下则不好。当使用Broadcom网卡配置Dell服务器,我发现一些问题,用于巨型帧包的

ping命令可能引起内核异常。这样的话,首先怀疑用于网卡的相同内核驱动。一种好的检修方式是从你所使用的驱动版本开始。通过在驱动本身使用

modinfo命令查找。下面是在 pcnet32驱动上使用modinfo的例子:

JBO:/ # modinfo pcnet32

filename: /lib/modules/2.6.27.19-5-pae/kernel/drivers/net/pcnet32.ko

license: GPL

description: Driver for PCnet32 and PCnetPCI based ethercards

author: Thomas Bogendoerfer

srcversion: 261B01C36AC94382ED8D984

alias: pci:v00001023d00002000sv*sd*bc02sc00i*

alias: pci:v00001022d00002000sv*sd*bc*sc*i*

alias: pci:v00001022d00002001sv*sd*bc*sc*i*

depends: mii

supported: yes

vermagic: 2.6.27.19-5-pae SMP mod_unload modversions 586

parm: debug:pcnet32 debug level (int)

parm: max_interrupt_work:pcnet32 maximum events handled per interrupt

(int)

parm: rx_copybreak:pcnet32 copy breakpoint for copy-only-tiny-frames

parm: tx_start_pt:pcnet32 transmit start point (0-3) (int)

parm: pcnet32vlb:pcnet32 Vesa local bus (VLB) support (0/1) (int)

parm: options:pcnet32 initial option setting(s) (0-15) (array of int)

parm: full_duplex:pcnet32 full duplex setting(s) (1) (array of int)

parm: homepna:pcnet32 mode for 79C978 cards

(1 for HomePNA, 0 for Ethernet, default Ethernet (array of int)

  modinfo命令将为每个模块提供不同的有用信息。如果包括版本号,查看可用的升级版,下载并安装。

  当与一些硬件使用时,你也应该检查使用的是何种模块。如果模块是开源的,通常可用通过Linux社区彻底检查开源模块。如果是这样,你的内核显示受到

“污染”。受感染的内核是载入了一些模块的内核,不由Linux内核社区控制。要查找这是否出现在你的系统上,可以检查/proc/sys/kernel

/tainted文件里的内容。如果这个文件内容为0,没有载入私有模块。如果有1个,那么载入了专有模块,并且如果你将私有模块替换成开源模块,就可能

修复问题。