初中級DBA必須要學會的9個Linux網路命令,看看你有哪些還沒用過
筆者不久前寫了一篇文章《做DBA必須學會,不會會死的11個Linux基本命令》,博文地址為:http://www.bkjia.com/os/201504/390274.html
此篇文章,則是寫的初中級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協議相關的統計資料,一般用於檢驗本機各連接埠的網路連接情況
常用用法:
(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
|
查看伺服器的某個連接埠有哪些機器在串連,以及串連的數量
[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'
|
列出指定連接埠所啟動並執行程式,以及有哪些IP在串連該連接埠(即指定連接埠被誰佔用,哪些本地或遠程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
|
統計串連特定連接埠最多的遠程或本地的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
(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 |