网络基本排查

网络基础

系统网卡配置说明

[root@oldboy ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0                    <- 第一块网卡逻辑设备名;第二块为eth1,
有些系统也会以em等字符标识(centos7系统)
TYPE=Ethernet                <- 上网类型,目前基本都是以太网
UUID=sasd-sdasd-wqe-12        <- 通用唯一识别码(Universally Unique Identifier);
                                如果是vmware克隆的虚拟机无法启动网卡可以去除此项。
ONBOOT=yes                    <- 这个地方要设置为yes,才能保证下次开机启动激活网卡设备
NM_CONTROLLED=no            <- 是否通过NetworkManager管理网卡设备(centos6关闭)
BOOTPROTO=none                 <- 启动协议,获取IP地址配置方式,有none|bootp|dhcp三个选项
IPADDR=10.0.0.51            <- 表示本台局域网中服务器的固定IP地址
NETMASK=255.255.255.0        <- 子网掩码,用来规划网络为和主机位的,一般为255.255.255.0
DNS2=223.6.6.6                <- 第二个DNS,这里默认会覆盖以及优选于/etc/resolv.conf的配置文件
GATEWAY=10.0.0.254            <- 局域网上网网关地址
DNS1=223.5.5.5                <- 主DNS,这里默认会覆盖以及优先于/etc/resolv.conf的配置生效
USERCTL=no
PEERDNS=yes                    <- 是否确认网卡配置文件中的DNS配置优先于/etc/resolv.conf配置文件
IPV6INIT=no                    <- 是否支持IPV6
HWADDR=00:0c:29:10:2e:28    <- 以太网硬件地址即MAC地址,如果是vmware克隆的虚拟机,无法启动网卡可以毫不犹豫的删除此项。

网卡配置生效方法:

推荐:ifdown,ifup进行指定发卡的重启操作
ifdown eth0 && ifup eth0  <- 重启eth0网卡
ifup eth0                    <- 启动eth0网卡
/etc/init.d/network restart <-针对所有网卡进行重启操作(工作场景慎用此命令)

linux系统之添加多块网卡

方法一:使用ifconfig方法添加,关闭网卡:ifconfig eth0:1 down
[root@web02 ~]# ifconfig eth0:1 10.1.0.8/24 up
[root@web02 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:1F:6D:B7  
          inet addr:10.0.0.3  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe1f:6db7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:133858 errors:0 dropped:0 overruns:0 frame:0
          TX packets:209180 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:11612854 (11.0 MiB)  TX bytes:230192172 (219.5 MiB)

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:1F:6D:B7  
          inet addr:10.1.0.8  Bcast:10.1.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
方法二:使用ip add来进行添加
[root@web02 ~]# ip addr add 10.2.0.8/24 dev eth0:1
[root@web02 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:1f:6d:b7 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.3/24 brd 10.0.0.255 scope global eth0
    inet 10.1.0.8/24 brd 10.1.0.255 scope global eth0:1
    inet 10.2.0.8/24 scope global eth0
    inet6 fe80::20c:29ff:fe1f:6db7/64 scope link 
       valid_lft forever preferred_lft forever
添加广播地址与ip地址
[root@web02 ~]# ip addr add 10.3.0.8/24 broadcast 10.0.0.255 dev eth0
[root@web02 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:1f:6d:b7 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.3/24 brd 10.0.0.255 scope global eth0
    inet 10.1.0.8/24 brd 10.1.0.255 scope global eth0:1
    inet 10.2.0.8/24 scope global eth0
    inet 10.3.0.8/24 brd 10.0.0.255 scope global eth0
    inet6 fe80::20c:29ff:fe1f:6db7/64 scope link 
       valid_lft forever preferred_lft forever
删除ip地址
[root@web02 ~]# ip add del 10.3.0.8/24 dev eth0
[root@web02 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:1f:6d:b7 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.3/24 brd 10.0.0.255 scope global eth0
    inet 10.1.0.8/24 brd 10.1.0.255 scope global eth0:1
    inet 10.2.0.8/24 scope global eth0
    inet6 fe80::20c:29ff:fe1f:6db7/64 scope link 
       valid_lft forever preferred_lft forever
[root@web02 ~]# 

系统默认网关配置

查看系统路由表信息
route -n:显示路由表信息
ifconfig:显示网络状态信息
ip:显示网络奖态信息(centos7中)
hostname -I:显示网络中所有的IP地址
[root@web02 ~]# hostname -I
10.0.0.3 10.1.0.8 10.2.0.8 
netstat:显示主机的端口与服务网络连接状态,ESTABLISHED表示建立连接的状态,数量即表示网络连接数
lsof:显示主机的端口与服务网络连接状态。
添加默认网关
[root@web02 ~]# route add default gw 10.0.0.254
[root@web02 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.2.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
10.1.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
0.0.0.0         10.0.0.254      0.0.0.0         UG    0      0        0 eth0
0.0.0.0         10.0.0.251      0.0.0.0         UG    0      0        0 eth0
[root@web02 ~]# 
添加静态网段路由
[root@web02 ~]# route add  -net 172.16.1.0 netmask 255.255.255.0 gw 10.0.0.254 
[root@web02 ~]# route -n  
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.2.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
172.16.1.0      10.0.0.254      255.255.255.0   UG    0      0        0 eth0
10.1.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
0.0.0.0         10.0.0.254      0.0.0.0         UG    0      0        0 eth0
0.0.0.0         10.0.0.251      0.0.0.0         UG    0      0        0 eth0
[root@web02 ~]# 
添加静态主机路由
[root@web02 ~]# route add -host 192.168.10.25 dev eth0:1   
[root@web02 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.10.25   0.0.0.0         255.255.255.255 UH    0      0        0 eth0
10.2.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
172.16.1.0      10.0.0.254      255.255.255.0   UG    0      0        0 eth0
10.1.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
0.0.0.0         10.0.0.254      0.0.0.0         UG    0      0        0 eth0
0.0.0.0         10.0.0.251      0.0.0.0         UG    0      0        0 eth0
[root@web02 ~]# 

网络连接异常常用排查命令

ping命令
    -c<count>        设置完成要求回应的次数;默认会一直长ping
    -f                表示极限ping,ping过程中不显示任何信息,效率更高
    -i<interval>    指定收发信息的间隔时间
    -q                不显示指定执行过程,开头和结尾的相关信息除外
    -s              <数据包大小>    设置数据包的大小
tracroute/tracert命令:路由跟踪
telnet命令:远程登陆命令
nmap命令:查看端口是否开启(namp ip地址 -p 端口)
posted @ 2019-02-11 11:12  游走在边缘的人  阅读(466)  评论(0编辑  收藏  举报