Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use shell script to view network interface information

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use shell script to view network interface information". In daily operation, I believe many people have doubts about how to use shell script to view network interface information. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to use shell script to view network interface information". Next, please follow the editor to study!

System environment

Centos7

1) check available network interfaces

Use the ip and awk commands to filter out network interfaces with a status of UP.

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

2) View the IP address of the network interface

Filter out the ip address of each interface using the following command:

[root@localhost ~] # ip-o addr | awk'/ inet/ {print $2J 4}'lo 127.0.0.1/8lo:: 1/128ens33 192.168.43.138/24ens33 fe80::214e:53b4:43f6:5495/64ens38 172.25.254.130/24ens38 fe80::c2ff:9dbc:76be:6dd9/64 or just look at the IPv4 address: [root@localhost ~] # ip addr | grep inet | grep-v 'inet6' | awk' {print $NF $2}'lo 127.0.0.1/8ens33 192.168.43.138/24ens38 172.25.254.130) check the MAC address of the network card

If you only want to view the network interface name and the corresponding MAC address, use the following command. Check the MAC address of a specific network interface:

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

By looking at the MAC addresses of all network interfaces, you can write a script to do this:

[root@localhost ~] # cat MacMutual address.shrunken cat BASPHS addr | awk'/ state UP/ {print $2}'| sed's Unix Unix Lash'| while read outputdoecho $output:ethtool-P $outputdone

Check the results of the run:

4) check the speed of the network interface

If you want to check the speed of the network interface port on Linux, you can use the ethtool tool. The following is the speed at which a specific network interface can be viewed: [root@localhost ~] # ethtool ens33 | grep "Speed:" Speed: 1000Mb/s

To check the network speed of all interfaces, you can write a script to do this:

[root@localhost ~] # cat port speed.shroud output output grep "Speed:" done addr | awk'/ state UP/ {print $2}'| sed's Unix Candle'| while read outputdoecho $speed.output |

Check the results of the run:

5) Shell script to view network interface information

In the following script, let's view the hostname, IPv4, IPv6, MAC address, and network interface speed information:

[root@localhost ~] # cat nicaquinfo.shangxinxinxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (for iname in) doecho "$iname" ip addr show $iname | grep inet | awk'{printf $2} 'ethtool ens33 | awk' / Speed/ {printf "% s\ t% s\ n", $1 done 2} 'here The study on "how to use shell script to view network interface information" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report