Linux网络故障
1 网络故障的一般处理流程:
(1)网络硬件问题
(2)检查网卡是否正常工作,检查网卡驱动是否正常加载、IP设置是否正确、系统路由设置是否正确
(3)检查局域网间主机是否连通正常,可以通过ping自身IP、ping网关、ping局域网内其他主机IP来检查
(4)检查DNS是否设置正确。通过检查/etc/resolv.conf和/etc/hosts文件进行确认。
(5)服务套接字是否正常打开。通过telnet和ss命令进行确认
(6)检查是否有访问权限。可以通过本机防火墙iptables、Linux内核强制访问控制策略来检查
1.1 检查网卡是否正常工作
1.1.1 检查网卡是否加载正常
通过lspci命令和lsmod、modinfo等命令查看网卡设备信息
[root@master ~]# yum install -y pciutils
查看网卡基本信息(厂商和信号)
[root@hehe ~]# lspci |grep -i ethernet 00:05.0 Ethernet controller: Red Hat, Inc. Virtio network device [root@hehe ~]# lspci 00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] 00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II] 00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01) 00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) 00:02.0 VGA compatible controller: Cirrus Logic GD 5446 00:03.0 Communication controller: Red Hat, Inc. Virtio console 00:04.0 SCSI storage controller: Red Hat, Inc. Virtio block device 00:05.0 Ethernet controller: Red Hat, Inc. Virtio network device 00:06.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon [root@hehe ~]# lspci |grep -i ethernet 00:05.0 Ethernet controller: Red Hat, Inc. Virtio network device
查看网卡详细信息
[root@hehe ~]# lspci -vvv 00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) Subsystem: Red Hat, Inc. Qemu virtual machine Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] Subsystem: Red Hat, Inc. Qemu virtual machine Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- 00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II] (prog-if 80 [ISA Compatibility mode-only controller, supports bus mastering]) Subsystem: Red Hat, Inc. Qemu virtual machine Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Latency: 0 Region 0: [virtual] Memory at 000001f0 (32-bit, non-prefetchable) [size=8] Region 1: [virtual] Memory at 000003f0 (type 3, non-prefetchable) Region 2: [virtual] Memory at 00000170 (32-bit, non-prefetchable) [size=8] Region 3: [virtual] Memory at 00000370 (type 3, non-prefetchable) Region 4: I/O ports at c060 [size=16] Kernel driver in use: ata_piix Kernel modules: ata_piix, ata_generic 00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01) (prog-if 00 [UHCI]) Subsystem: Red Hat, Inc. QEMU Virtual Machine Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Latency: 0 Interrupt: pin D routed to IRQ 11 Region 4: I/O ports at c000 [size=32] Kernel driver in use: uhci_hcd 00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) Subsystem: Red Hat, Inc. Qemu virtual machine Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Interrupt: pin A routed to IRQ 9 Kernel driver in use: piix4_smbus Kernel modules: i2c_piix4 00:02.0 VGA compatible controller: Cirrus Logic GD 5446 (prog-if 00 [VGA controller]) Subsystem: Red Hat, Inc. QEMU Virtual Machine Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Region 0: Memory at fc000000 (32-bit, prefetchable) [size=32M] Region 1: Memory at febf0000 (32-bit, non-prefetchable) [size=4K] Expansion ROM at 000c0000 [disabled] [size=128K] Kernel driver in use: cirrus Kernel modules: cirrus 00:03.0 Communication controller: Red Hat, Inc. Virtio console Subsystem: Red Hat, Inc. Device 0003 Physical Slot: 3 Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx+ Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Latency: 0 Interrupt: pin A routed to IRQ 10 Region 0: I/O ports at c020 [size=32] Region 1: Memory at febf1000 (32-bit, non-prefetchable) [size=4K] Capabilities: [40] MSI-X: Enable+ Count=2 Masked- Vector table: BAR=1 offset=00000000 PBA: BAR=1 offset=00000800 Kernel driver in use: virtio-pci 00:04.0 SCSI storage controller: Red Hat, Inc. Virtio block device Subsystem: Red Hat, Inc. Device 0002 Physical Slot: 4 Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx+ Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Latency: 0 Region 0: Memory at fe000000 (64-bit, prefetchable) [size=4K] Region 2: Memory at fe001000 (64-bit, prefetchable) [size=4K] Capabilities: [40] MSI-X: Enable+ Count=2 Masked- Vector table: BAR=2 offset=00000000 PBA: BAR=2 offset=00000c00 Kernel driver in use: virtio-pci 00:05.0 Ethernet controller: Red Hat, Inc. Virtio network device Subsystem: Red Hat, Inc. Device 0001 Physical Slot: 5 Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx+ Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Latency: 0 Region 0: Memory at fe002000 (64-bit, prefetchable) [size=4K] Region 2: Memory at fe003000 (64-bit, prefetchable) [size=4K] Capabilities: [40] MSI-X: Enable+ Count=4 Masked- Vector table: BAR=2 offset=00000000 PBA: BAR=2 offset=00000c00 Kernel driver in use: virtio-pci 00:06.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon Subsystem: Red Hat, Inc. Device 0005 Physical Slot: 6 Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Latency: 0 Interrupt: pin A routed to IRQ 10 Region 0: I/O ports at c040 [size=32] Kernel driver in use: virtio-pci
查看网卡设备是否识别
[root@master ~]# lspci -vv|grep -i eth 02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
查看网卡驱动和模块
[root@master ~]# lspci -vv -s 02:01.0 02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01) Subsystem: VMware PRO/1000 MT Single Port Adapter Physical Slot: 33 Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV+ VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx- Status: Cap+ 66MHz+ UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- Latency: 0 (63750ns min), Cache Line Size: 64 bytes Interrupt: pin A routed to IRQ 19 Region 0: Memory at fd5c0000 (64-bit, non-prefetchable) [size=128K] Region 2: Memory at fdff0000 (64-bit, non-prefetchable) [size=64K] Region 4: I/O ports at 2000 [size=64] [virtual] Expansion ROM at fd500000 [disabled] [size=64K] Capabilities: [dc] Power Management version 2 Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+) Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=1 PME- Capabilities: [e4] PCI-X non-bridge device Command: DPERE- ERO+ RBC=512 OST=1 Status: Dev=ff:1f.0 64bit+ 133MHz+ SCD- USC- DC=simple DMMRBC=2048 DMOST=1 DMCRS=16 RSCEM- 266MHz- 533MHz- Kernel driver in use: e1000 Kernel modules: e1000
查看网卡模块信息(一般保存在/lib/modules/`uname -r`/kernel/drivers/net/ethernet目录下)
[root@master ~]# lsmod |grep e1000 e1000 137574 0
[root@master ~]# modinfo e1000 filename: /lib/modules/3.10.0-862.el7.x86_64/kernel/drivers/net/ethernet/intel/e1000/e1000.ko.xz version: 7.3.21-k8-NAPI license: GPL description: Intel(R) PRO/1000 Network Driver author: Intel Corporation, <linux.nics@intel.com> retpoline: Y rhelversion: 7.5 srcversion: 04454A212DD89712602561D alias: pci:v00008086d00002E6Esv*sd*bc*sc*i* alias: pci:v00008086d000010B5sv*sd*bc*sc*i* alias: pci:v00008086d00001099sv*sd*bc*sc*i* alias: pci:v00008086d0000108Asv*sd*bc*sc*i* alias: pci:v00008086d0000107Csv*sd*bc*sc*i* alias: pci:v00008086d0000107Bsv*sd*bc*sc*i* alias: pci:v00008086d0000107Asv*sd*bc*sc*i* alias: pci:v00008086d00001079sv*sd*bc*sc*i* alias: pci:v00008086d00001078sv*sd*bc*sc*i* alias: pci:v00008086d00001077sv*sd*bc*sc*i* alias: pci:v00008086d00001076sv*sd*bc*sc*i* alias: pci:v00008086d00001075sv*sd*bc*sc*i* alias: pci:v00008086d00001028sv*sd*bc*sc*i* alias: pci:v00008086d00001027sv*sd*bc*sc*i* alias: pci:v00008086d00001026sv*sd*bc*sc*i* alias: pci:v00008086d0000101Esv*sd*bc*sc*i* alias: pci:v00008086d0000101Dsv*sd*bc*sc*i* alias: pci:v00008086d0000101Asv*sd*bc*sc*i* alias: pci:v00008086d00001019sv*sd*bc*sc*i* alias: pci:v00008086d00001018sv*sd*bc*sc*i* alias: pci:v00008086d00001017sv*sd*bc*sc*i* alias: pci:v00008086d00001016sv*sd*bc*sc*i* alias: pci:v00008086d00001015sv*sd*bc*sc*i* alias: pci:v00008086d00001014sv*sd*bc*sc*i* alias: pci:v00008086d00001013sv*sd*bc*sc*i* alias: pci:v00008086d00001012sv*sd*bc*sc*i* alias: pci:v00008086d00001011sv*sd*bc*sc*i* alias: pci:v00008086d00001010sv*sd*bc*sc*i* alias: pci:v00008086d0000100Fsv*sd*bc*sc*i* alias: pci:v00008086d0000100Esv*sd*bc*sc*i* alias: pci:v00008086d0000100Dsv*sd*bc*sc*i* alias: pci:v00008086d0000100Csv*sd*bc*sc*i* alias: pci:v00008086d00001009sv*sd*bc*sc*i* alias: pci:v00008086d00001008sv*sd*bc*sc*i* alias: pci:v00008086d00001004sv*sd*bc*sc*i* alias: pci:v00008086d00001001sv*sd*bc*sc*i* alias: pci:v00008086d00001000sv*sd*bc*sc*i* depends: intree: Y vermagic: 3.10.0-862.el7.x86_64 SMP mod_unload modversions signer: CentOS Linux kernel signing key sig_key: 3A:F3:CE:8A:74:69:6E:F1:BD:0F:37:E5:52:62:7B:71:09:E3:2B:96 sig_hashalgo: sha256 parm: TxDescriptors:Number of transmit descriptors (array of int) parm: RxDescriptors:Number of receive descriptors (array of int) parm: Speed:Speed setting (array of int) parm: Duplex:Duplex setting (array of int) parm: AutoNeg:Advertised auto-negotiation setting (array of int) parm: FlowControl:Flow Control setting (array of int) parm: XsumRX:Disable or enable Receive Checksum offload (array of int) parm: TxIntDelay:Transmit Interrupt Delay (array of int) parm: TxAbsIntDelay:Transmit Absolute Interrupt Delay (array of int) parm: RxIntDelay:Receive Interrupt Delay (array of int) parm: RxAbsIntDelay:Receive Absolute Interrupt Delay (array of int) parm: InterruptThrottleRate:Interrupt Throttling Rate (array of int) parm: SmartPowerDownEnable:Enable PHY smart power down (array of int) parm: copybreak:Maximum size of packet that is copied to a new buffer on receive (uint) parm: debug:Debug level (0=none,...,16=all) (int)
1.1.2 检查网卡配置文件
检查IP配置是否正确。
1.1.3 检查系统路由表是否正确
一般都是由于网卡配置后,路由表有问题导致无法访问。例如:
[root@master ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 default 192.168.100.1 0.0.0.0 UG 0 0 0 eth1
由路由表可以看出,eth1网卡是内网网卡,而网卡的默认路由绑定在了内网网卡上,导致无法对外提供访问。
可以删除此条路由,将默认路由添加到eth0上即可
[root@master ~]# route delete default [root@master ~]# route add default gw 10.0.0.226
1.2 检查DNS配置是否正确
linux系统主要通过两个文件来指定系统寻找相关的解析库:/etc/host.conf 和 /etc/nsswitch.conf。/etc/host.conf 指定了系统如何解析主机名,通过域名解析库来获得主机名对应的IP。
[root@master ~]# cat /etc/host.conf
#multi on
order hosts,bind
此文件默认配置为:
multi on
上面的配置表示:order决定了主机名查询顺序,这里是先找/etc/hosts文件对应的解析,如果没有找到对应的解析,再根据 /etc/resolv.conf 指定的域名服务器进行解析。
nsswitch是有SUN公司研发。nsswitch已经取代了hosts.conf。
关于nsswitch可以参考我的另一篇博客:https://www.cnblogs.com/zh-dream/p/12735152.html
1.3 检查服务是否正常启动
一般情况下通过telnet命令检查
posted on 2020-05-10 23:22 hopeless-dream 阅读(671) 评论(0) 编辑 收藏 举报