When Linux operating system When a network failure occurs , It should start from the hardware and software of the system 、 Local and overall inspection , The following will be from several aspects for Linux When the operating system produces the network breakdown the solution carries on the elaboration .
1、 Check the cable 、 network card </h2>
Go to the computer room to check whether both ends of the network cable are on , The normal server is always green , The switch's green light flashes to indicate that data is being transmitted .
By command ethtool ethX To check whether the link of a network card is physically connected . among ,speed Is the speed of the current network card , This is a Gigabit NIC ;Duplex Shows that the current network supports full duplex ;link detected Indicates the physical connection status of the current network card and network ,yes It's normal .
Usually, the network speed and full / Half duplex state is automatically negotiated between host and network protocol provider .</p>
2、 After making sure the cable is connected , Let's look at the physical network card </h2>
ifconfig You can see the network card loaded successfully , use ethtool -i ethX You can see the NIC driver ,lspci You can see all the connections to pci Bus device ,lsmod Show all loaded modules , The successful module will also be loaded in /proc/modules It shows that .
In general , After loading the NIC successfully , use ifconfig You can see . If you can't find the network card , Then you should check whether the physical network card is connected to pci On the bus , If lspci If it cannot be detected, the network card may be broken .
Another case is that the NIC module is not loaded , Go first lspci Find the corresponding manufacturer and model in ：Ethernet Controller, Reuse modprobe Try to load the correct module , such as modprobe3c509. If something goes wrong , The module does not exist . It's time to find the right module and recompile .
3、 After the physical layer of network card has no problem , Let's look at the network card configuration </h2>
use ifconfig You can look at IP、 Mask and other information , Permanently modify network card information in /etc/sysconfig/network-scripts/ifcfg-ethX（ There are some Linux The distribution doesn't have to be the file name , But the path is similar , It's in the upper layer network The file is modified hostname Of ） In file , This file is also put DNS The right place to be , Restart after modification network.
4、 Check whether the routing table is correct </h2>
use route-n Look at the kernel routing table , adopt route Command to view kernel routing , After checking whether the specific network card is connected to the route of the target network, you can try PING gateway , Check the connection with the gateway . If you can't ping Through gateway , Maybe the gateway limits ICMP Packet or switch settings .
A very common problem ： The two network cards provide intranet and extranet services respectively , If the default gateway is intranet card , So Internet services are inaccessible . At this time, you need to delete and add the default gateway , use route delete/ add default gw command .
5、 see DNS</h2>
stay /etc/resolve.conf The specified domain name server can be seen in the file , But you can't modify this file here , It will be automatically generated after modification networkManager file , So I'm going etc/sysconfig/network-scripts/ifcfg-ethX Revision in China .
6、 Check whether the route is smooth with the host </h2>
When a remote host cannot be connected , How to track the route .traceroute Command is a tool to track the gateway from the sending host to the target host .
traceroute The common parameter options of the command are as follows ：
-i Specify network interface , Useful for multiple network interfaces . such as -i eth1 or -i ppp1 etc. .</li>
-m Set the maximum lifetime used in the outgoing probe test package to max-ttl Forward , The default value is 30 Time .</li>
-n Show IP Address , Don't look up the hostname . When DNS This parameter is often used when it doesn't work ; It can also be ruled out during the examination DNS The problem of .</li>
Record by serial number from 1 Start , Every record is a jump , Each hop represents a gateway , We see three times per line , The unit is ms, In fact, that is -q Default parameters . After the probe packet sends three packets to each gateway , The return time of the gateway response . asterisk “*” The firewall is blocked ICMP The return information of .
7、 Check whether the service port of the remote host is open </h2>
use telnet and nmap To check , If you don't have these two tools, install them yourself yum. For example, we need to see Baidu's 80 Is the port open , state STATE yes open Open for indication , If it is filtered It means it is filtered by firewall .
For example, the second 1 Column is the socket communication protocol , The first 2 Column and the first 3 Column shows the receive and send queues , The first 4 Column is the local address that the host is listening to , Reflects the network that the socket listens to ; The first 6 Column shows the status of the current socket , The last column shows the process that opened the port .
That's all Liangxu tutorial website For all of you Linux Related knowledge .