此篇文章,则是写的初中级DBA必需要学会的9个Linux网络命令。这些命令对一个DBA在维护管理、故障排除方面是否能高效的开展工作,起着举足轻重的作用。
1、ethtool
Ethtool是用于查询及设置网卡參数的命令。用得最多的,莫过于查看网卡的速度,如百兆、千兆、万兆。
经常使用使用方法:
(1)ethtool eth0 [eth0是一号网卡。实际应用时依据自己的网卡编号进行改动]
查看网卡的支持信息与执行速率信息
[oracle@ol6-single ~]$ ethtoo l eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s --网卡执行速度
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
(2)ethtool –I eth0
查看网卡的驱动版本号与固件版本号信息
[oracle@ol6-single ~]$ ethtool -i eth0
driver: e1000
version: 7.3.21-k8-NAPI --驱动版本号
firmware-version: N/A --固件版本号
bus-info: 0000:02:00.0
1.2 netstat
Netstat是控制台命令,是一个监控TCP/IP网络的执行情况的工具,它能够显示路由表、实际的网络连接以及每个网络接口设备的状态信息。包含IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各port的网络连接情况
经常使用使用方法:
(1) netstat –r
查看路由表信息
[oracle@ol6-single ~]$ netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
(2) netstat–i
显示网络接口信息
[oracle@ol6-single ~]$ netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 9011 0 0 0 1652 0 0 0 BMRU
lo 16436 0 2359 0 0 0 2359 0 0 0 LRU
(3) netstat–ie
显示网络接口的具体信息,与ifconfig命令输出的结果安全同样
[oracle@ol6-single ~]$ netstat -ie
Kernel Interface table
eth0 Link encap:Ethernet HWaddr 00:0C:29:5E:35:00
inet addr:192.168.2.150 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe5e:3500/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9170 errors:0 dropped:0 overruns:0 frame:0
TX packets:1672 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:825449 (806.1 KiB) TX bytes:669089 (653.4 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2387 errors:0 dropped:0 overruns:0 frame:0
TX packets:2387 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:145938 (142.5 KiB) TX bytes:145938 (142.5 KiB)
(4) netstat-nat
查看server的某个port有哪些机器在连接,以及连接的数量
[oracle@ol6-single ~]$ netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:36174 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 52 192.168.2.150:22 192.168.2.1:60302 ESTABLISHED
tcp 0 0 192.168.2.150:41029 192.168.2.150:1521 ESTABLISHED
tcp 0 0 :::36352 :::* LISTEN
tcp 0 0 :::111 :::* LISTEN
tcp 0 0 :::45104 :::* LISTEN
tcp 0 0 :::1521 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:631 :::* LISTEN
tcp 0 0 ::ffff:192.168.2.150:1521 ::ffff:192.168.2.1:59812 ESTABLISHED
tcp 0 0 ::ffff:192.168.2.150:1521 ::ffff:192.168.2.150:41029 ESTABLISHED
tcp 0 0 ::ffff:192.168.2.150:1521 ::ffff:192.168.2.1:60023 ESTABLISHED
tcp 0 0 ::ffff:192.168.2.150:1521 ::ffff:192.168.2.1:60035 ESTABLISHED
(5) netstat–an |grep ':1521'
列出指定port所执行的程序,以及有哪些IP在连接该port(即指定port被谁占用,哪些本地或远程IP在连接它)
[oracle@ol6-single ~]$ netstat -an |grep ':1521'
tcp 0 0 192.168.2.150:41029 192.168.2.150:1521 ESTABLISHED
tcp 0 0 :::1521 :::* LISTEN
tcp 0 0 ::ffff:192.168.2.150:1521 ::ffff:192.168.2.1:59812 ESTABLISHED
tcp 0 0 ::ffff:192.168.2.150:1521 ::ffff:192.168.2.150:41029 ESTABLISHED
tcp 0 0 ::ffff:192.168.2.150:1521 ::ffff:192.168.2.1:60023 ESTABLISHED
tcp 0 0 ::ffff:192.168.2.150:1521 ::ffff:192.168.2.1:60035 ESTABLISHED
(6) netstat -nat | grep "192.168.2.150:1521" |awk '{print $5}'|awk -F: '{print$1}'|sort|uniq -c|sort -nr|head -20
统计连接特定port最多的远程或本地的IP地址及数量
[oracle@ol6-single ~]$ netstat -nat | grep "192.168.2.150:1521" |awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -20
4
1 192.168.2.150
1.3 ifconfig
ifconfig是用来显示与配置内核的网络接口。
它是在启动时使用的,在必要时设置接口。
略
1.4 ss
ss命令用于显示socket状态。他能够显示PACKET sockets, TCP sockets,UDP sockets, DCCP sockets, RAW sockets, Unix domain sockets等等统计。
它比其它工具展示等多tcp和state信息. 它是一个很有用、高速、有效的跟踪IP连接和sockets的新工具。
经常使用使用方法:
(1) ss
[root@ol6-single ~]# ss
(2)ss -V
输出ss版本号信息
[root@ol6-single ~]# ss -V
ss utility, iproute2-ss091226
(3)ss –s
显示当前SOCKET的具体信息
[root@ol6-single ~]# ss -s
Total: 350 (kernel 354)
TCP: 17 (estab 6, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 9
Transport Total IP IPv6
* 354 - -
RAW 0 0 0
UDP 14 7 7
TCP 17 7 10
INET 31 14 17
FRAG 0 0 0
1.6 traceroute
路由跟踪,在网络故障时,定位出在哪一个路由或网络上非常重要
经常使用使用方法:
(1)traceroute IP
[root@ol6-single ~]# traceroute 192.168.2.150
traceroute to 192.168.2.150 (192.168.2.150), 30 hops max, 60 byte packets
1 ol6-single (192.168.2.150) 0.024 ms 0.007 ms 0.005 ms
1.7 nslookup
nslookup是用来通过解析IP地址与域名的相应关系的命令。
经常使用使用方法:
[oracle@ol6-single ~]$ nslookup www.163.com
名称: 163.xdwscache.glb0.lxdns.com
Address: 122.191.127.8
Aliases: www.163.com
www.163.com.lxdns.com
1.8 ifup
网络接口启动命令
经常使用使用方法:
启动处于关闭状态的网络接口
[root@ol6-single ~]# ifup eth0
1.9 ifdown
网络接口关闭命令
经常使用使用方法:
关闭处于启动状态的网络接口
[root@ol6-single ~]# ifdown eth0
本文作者:黎俊杰(网名:踩点),从事”系统架构、操作系统、存储设备、数据库、中间件、应用程序“六个层面系统性的性能优化工作
欢迎增加系统性能优化专业群。共同探讨性能优化技术。群号:258187244