Linux服务器网络故障处理
主要分为硬件层面和系统层面、本机和局域网网络环境
1、检查网络硬件问题
网线、网卡、集线器、路由器、交换机等是否出现问题,及时更换。
2、检查网卡是否正常工作
1)、网卡是否正常加载:ifconfig、lsmod
ifconfig可以正常显示网络接口配置信息(eth0、eth1、ens33等),则表示网卡驱动,网络设备,网卡加载正常
[root@node3 ~]# ifconfig
ens35: flags=4163
inet 192.168.88.135 netmask 255.255.255.0 broadcast 192.168.88.255
inet6 fe80::20c:29ff:fe0b:8ad2 prefixlen 64 scopeid 0x20
ether 00:0c:29:0b:8a:d2 txqueuelen 1000 (Ethernet)
RX packets 85925 bytes 62579212 (59.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 141324 bytes 153355472 (146.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2)、网卡ip配置是否正确
IP是否配置,配置是否正确,与局域网内其他服务器配置是否存在冲突
检查网卡的配置文件:/etc/sysconfig/network-scripts/下的文件
[root@node3 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens35
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.88.135
PREFIX=24
GATEWAY=192.168.88.2
8DOMAIN=localdomain
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens35
HWADDR=00:0C:29:0B:8A:D2
UUID=d480ca17-4d25-40e2-8ad6-e94785e4a0aa
DEVICE=ens35
ONBOOT=yes
3)、系统路由表信息是否正确
[root@node3 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.88.2 0.0.0.0 UG 100 0 0 ens35
192.168.88.0 0.0.0.0 255.255.255.0 U 100 0 0 ens35
Destination:目标网络或主机。
Gateway:网关地址。
Genmask:目标网络的网络掩码。"255.255.255.0"表示一个主机。"0.0.0.0"表示网关。
Flags:标记。
U、路由被启用。
H、目标是一个主机
G、使用网关。
删除默认路由方法:route delete default
[root@node3 ~]# route delete default
[root@node3 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.88.0 0.0.0.0 255.255.255.0 U 100 0 0 ens35
添加默认路由方法:route add default gw
[root@node3 ~]# route add default gw 192.168.88.2
[root@node3 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.88.2 0.0.0.0 UG 0 0 0 ens35
192.168.88.0 0.0.0.0 255.255.255.0 U 100 0 0 ens35
3、检查DNS文件解析是否正常:/etc/host.conf和/etc/nsswitch.conf文件
/etc/host.conf :指定系统如何解析主机名
/etc/nsswitch.conf:管理多个配置文件查询的顺序,用于决定查询时是先查找hosts文件还是先通过/etc/resolv.conf指定的DNS服务器进行解析。
[root@node3 ~]# cat /etc/host.conf
multi on #允许主机拥有多个ip地址
#order hosts,bind
#解析器查询顺序是文件/etc/hosts,然后是/etc/resolve.conf中指定的DNS服务器进行解析
#nospoof on #禁止ip地址欺骗
[root@node3 ~]# grep -v ^[[:space:]]*$ /etc/nsswitch.conf| grep -v ^#
passwd: files sss
shadow: files sss
group: files sss
hosts: files dns myhostname
#files:使用/etc/hosts文件查询,dns:使用/etc/resolv.conf文件指定的DNS服务器进行解析查询, myhostname:查询当前系统的主机名
bootparams: nisplus [NOTFOUND=return] files
ethers: files
netmasks: files
networks: files
protocols: files
rpc: files
services: files sss
netgroup: nisplus sss
publickey: nisplus
automount: files nisplus sss
aliases: files nisplus
[root@node3 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain field.com
nameserver 192.168.88.2
4、检查应用服务状态
应用故障时,首先应该检查服务是否处于开启状态,配置文件是否正确等
1)、首先检查端口是否打开telnet、netstat、ss等命令
如检查mysql、Nginx服务是否开启:
[root@cen7 ~]# netstat -tnl|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
[root@cen7 ~]# netstat -tnl|grep 80
tcp6 0 0 :::80 :::* LISTEN
2)、检查配置文件:如Nginx配置文件
[root@cen7 ~]# more /etc/nginx/nginx.conf
...
[root@cen7 ~]# nginx -t 检测语法
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
5、检查是否开放访问权限:iptables、SElinux、Centos7的Firewall
1)、检测iptables是否做了限制:“iptables -L”命令查看iptables策略
[root@cen7 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
开放web服务iptables配置示例:
[root@cen7 ~]# iptables -A INPUT -i ens32 -p tcp --dport 80 -j ACCEPT
[root@cen7 ~]# iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
[root@cen7 ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp spt:80 state ESTABLISHED
iptables-save 命令保存规则
iptables-restore 命令恢复规则
[root@cen7 ~]# iptables-save > /etc/sysconfig/iptables
[root@cen7 ~]# iptables-restore > /etc/sysconfig/iptables
2)、检查SElinux是否打开
[root@cen7 ~]# grep "SELINUX" /etc/selinux/config
# SELINUX= can take one of these three values:
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
SELINUXTYPE=targeted
[root@cen7 ~]# getenforce
Disabled
3)、centos7检查Firewall
[root@cen7 ~]# firewall-cmd --state
Running
[root@cen7 ~]# systemctl stop firewalld
[root@cen7 ~]# firewall-cmd --state
not running
[root@cen7 ~]# chkconfig firewalld off
注意:正在将请求转发到“systemctl disable firewalld.service”。
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
6、检查局域网主机之间联机状态:ping
以上5步主要确认Linux系统自身问题,如果不能解决问题,核查Linux主机之外的网络环境是否存在问题。
思路:ping本机自身,网关,局域网中主机等,如果出现较大时延,基本可以判断服务器网络连接存在问题,最可能是网线老化,更换后再做尝试。
[root@cen7 ~]# ping 192.168.88.132 -->本机网络
PING 192.168.88.132 (192.168.88.132) 56(84) bytes of data.
64 bytes from 192.168.88.132: icmp_seq=1 ttl=64 time=0.027 ms
64 bytes from 192.168.88.132: icmp_seq=2 ttl=64 time=0.036 ms
^C
--- 192.168.88.132 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.027/0.031/0.036/0.007 ms
[root@cen7 ~]# ping 192.168.88.133 -->局域网中主机
PING 192.168.88.133 (192.168.88.133) 56(84) bytes of data.
64 bytes from 192.168.88.133: icmp_seq=1 ttl=64 time=0.806 ms
64 bytes from 192.168.88.133: icmp_seq=2 ttl=64 time=0.276 ms
^C
--- 192.168.88.133 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.276/0.541/0.806/0.265 ms
[root@cen7 ~]# ping 192.168.88.2 -->网关
PING 192.168.88.2 (192.168.88.2) 56(84) bytes of data.
64 bytes from 192.168.88.2: icmp_seq=1 ttl=128 time=0.819 ms
64 bytes from 192.168.88.2: icmp_seq=2 ttl=128 time=0.193 ms
^C
--- 192.168.88.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.193/0.506/0.819/0.313 ms