自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Shell腳本 – 查看網(wǎng)絡(luò)接口信息

系統(tǒng) Linux
本文介紹如何是用shell腳本查看網(wǎng)絡(luò)接口的ip地址、MAC地址、網(wǎng)絡(luò)速率等信息。

[[404873]]

本文介紹如何是用shell腳本查看網(wǎng)絡(luò)接口的ip地址、MAC地址、網(wǎng)絡(luò)速率等信息。

系統(tǒng)環(huán)境

Centos7

1)檢查可用的網(wǎng)絡(luò)接口

使用ip和awk命令,過濾出狀態(tài)為UP的網(wǎng)絡(luò)接口。

  1. [root@localhost ~]# ip ad|awk '/state UP/ {print $2}' 
  2. ens33: 
  3. ens38: 

2)查看網(wǎng)絡(luò)接口的IP地址

使用下面命令過濾出每個(gè)接口的ip地址:

  1. [root@localhost ~]# ip -o addr |awk '/inet/{print $2,$4}' 
  2. lo 127.0.0.1/8 
  3. lo ::1/128 
  4. ens33 192.168.43.138/24 
  5. ens33 fe80::214e:53b4:43f6:5495/64 
  6. ens38 172.25.254.130/24 
  7. ens38 fe80::c2ff:9dbc:76be:6dd9/64 
  8. 或者只查看IPv4地址: 
  9. [root@localhost ~]# ip addr | grep inet|grep -v 'inet6'|awk '{print $NF, $2}' 
  10. lo 127.0.0.1/8 
  11. ens33 192.168.43.138/24 
  12. ens38 172.25.254.130/24 

3)查看網(wǎng)卡的MAC地址

如果只想查看網(wǎng)絡(luò)接口名稱和相應(yīng)的MAC地址,請使用以下命令。檢查特定的網(wǎng)絡(luò)接口的MAC地址:

  1. [root@localhost ~]# ip link show ens33 | awk '/link/{print $2}' 
  2. 00:0c:29:99:ee:d9 

查看所有網(wǎng)絡(luò)接口的MAC地址,可以寫一個(gè)腳本來實(shí)現(xiàn):

  1. [root@localhost ~]# cat mac-address.sh  
  2. #!/bin/bash 
  3. ip addr |awk '/state UP/{print $2}' | sed 's/://' | while read output 
  4. do 
  5. echo $output
  6. ethtool -P $output 
  7. done 

查看一下運(yùn)行結(jié)果:

4)查看網(wǎng)絡(luò)接口的速度

如果要在Linux上檢查網(wǎng)絡(luò)接口端口速度,可以使用ethtool工具。下面是查看特定網(wǎng)絡(luò)接口的速度:

  1. [root@localhost ~]# ethtool ens33|grep "Speed:" 
  2. Speed: 1000Mb/s 

查看所有接口的網(wǎng)絡(luò)速度,可以寫一個(gè)腳本來實(shí)現(xiàn):

  1. [root@localhost ~]# cat port-speed.sh  
  2. #!/bin/bash 
  3. ip addr |awk '/state UP/{print $2}' | sed 's/://' | while read output 
  4. do 
  5. echo $output
  6. ethtool $output |grep "Speed:" 
  7. done 

查看一下運(yùn)行結(jié)果:

5)查看網(wǎng)絡(luò)接口信息的Shell腳本

下面這個(gè)腳本,我們來實(shí)現(xiàn)查看主機(jī)名、IPv4、IPv6、MAC地址、網(wǎng)絡(luò)接口速度信息:

  1. [root@localhost ~]# cat nic-info.sh  
  2. #!/bin/bash 
  3. hostname 
  4. echo "-------------" 
  5. for iname in $(ip addr |awk '/state UP/{print $2}'
  6. do 
  7. echo "$iname" 
  8. ip addr show $iname | grep inet | awk '{printf "%s:\t%s\n",$1,$2}' 
  9. ip link show $iname | grep link | awk '{printf "MAC:\t%s\n",$2}' 
  10. ethtool ens33 | awk '/Speed/{printf "%s\t%s\n",$1,$2}' 
  11. done 

本文轉(zhuǎn)載自微信公眾號「Linux就該這么學(xué)」,可以通過以下二維碼關(guān)注。轉(zhuǎn)載本文請聯(lián)系Linux就該這么學(xué)公眾號。

 

責(zé)任編輯:武曉燕 來源: Linux就該這么學(xué)
相關(guān)推薦

2011-04-01 11:31:22

OSPF

2021-03-29 10:09:22

Windows服務(wù)器端口

2019-12-05 09:00:27

BashShellLinux

2010-06-17 14:45:50

RS-232C協(xié)議

2024-11-27 09:19:25

2019-08-09 13:50:08

shellLinux

2012-04-26 14:02:58

ibmdw

2021-07-02 06:54:44

Shell腳本 Linux

2022-06-21 09:26:21

Shell腳本JavaScript

2011-09-27 13:52:41

2020-06-17 10:42:54

shellshell腳本Linux

2019-03-20 10:00:34

Linux網(wǎng)絡(luò)接口命令

2020-11-02 08:23:36

shell腳本Linux

2023-07-31 08:45:10

Shell腳本

2009-11-18 13:52:30

PHP shell腳本

2011-06-28 10:11:05

Qt Qt 4.1.0 注冊表

2015-08-10 14:42:40

Explain SheShell 命令

2020-06-16 08:44:23

Shell服務(wù)器

2009-12-01 09:13:51

shell腳本linux

2014-08-08 16:17:49

shell腳本linux
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號