怎么使用shell脚本查看网络接口信息
发表于:2024-10-25 作者:千家信息网编辑
千家信息网最后更新 2024年10月25日,这篇文章主要介绍"怎么使用shell脚本查看网络接口信息",在日常操作中,相信很多人在怎么使用shell脚本查看网络接口信息问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答
千家信息网最后更新 2024年10月25日怎么使用shell脚本查看网络接口信息
这篇文章主要介绍"怎么使用shell脚本查看网络接口信息",在日常操作中,相信很多人在怎么使用shell脚本查看网络接口信息问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"怎么使用shell脚本查看网络接口信息"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
系统环境
Centos7
1)检查可用的网络接口
使用ip
和awk
命令,过滤出状态为UP的网络接口。
[root@localhost ~]# ip ad|awk '/state UP/ {print $2}'ens33:ens38:
2)查看网络接口的IP地址
使用下面命令过滤出每个接口的ip地址:
[root@localhost ~]# ip -o addr |awk '/inet/{print $2,$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或者只查看IPv4地址:[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/24
3)查看网卡的MAC地址
如果只想查看网络接口名称和相应的MAC地址,请使用以下命令。检查特定的网络接口的MAC地址:
[root@localhost ~]# ip link show ens33 | awk '/link/{print $2}'00:0c:29:99:ee:d9
查看所有网络接口的MAC地址,可以写一个脚本来实现:
[root@localhost ~]# cat mac-address.sh#!/bin/baship addr |awk '/state UP/{print $2}' | sed 's/://' | while read outputdoecho $output:ethtool -P $outputdone
查看一下运行结果:
4)查看网络接口的速度
如果要在Linux上检查网络接口端口速度,可以使用ethtool工具。下面是查看特定网络接口的速度: [root@localhost ~]# ethtool ens33|grep "Speed:" Speed: 1000Mb/s
查看所有接口的网络速度,可以写一个脚本来实现:
[root@localhost ~]# cat port-speed.sh#!/bin/baship addr |awk '/state UP/{print $2}' | sed 's/://' | while read outputdoecho $output:ethtool $output |grep "Speed:"done
查看一下运行结果:
5)查看网络接口信息的Shell脚本
下面这个脚本,我们来实现查看主机名、IPv4、IPv6、MAC地址、网络接口速度信息:
[root@localhost ~]# cat nic-info.sh#!/bin/bashhostnameecho "-------------"for iname in $(ip addr |awk '/state UP/{print $2}')doecho "$iname"ip addr show $iname | grep inet | awk '{printf "%s:\t%s\n",$1,$2}'ip link show $iname | grep link | awk '{printf "MAC:\t%s\n",$2}'ethtool ens33 | awk '/Speed/{printf "%s\t%s\n",$1,$2}'done
到此,关于"怎么使用shell脚本查看网络接口信息"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
接口
网络
脚本
地址
信息
速度
学习
命令
检查
更多
结果
帮助
运行
实用
接下来
主机
名称
工具
文章
方法
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
广州国产化服务器厂商
三星服务器内存2g ddr3
深圳盛扬网络技术有限公司
服务器共享扫描仪
在我的世界里怎么退出服务器
安徽智慧团建软件开发电话
网络安全运动2017
电脑智能网络安全模式
网络安全的概念英语
昌吉学院网络技术中心
南宁网络技术开发公司
南通公司网络安全准入控制系统
高速网络技术介绍
20年网络安全威胁
南京 网络安全 公司排名
网络安全小报五年级摸板
曙光服务器引导
数据库物理储存与逻辑结构设计
网络技术专科怎么毕业
上海技术网络技术出厂价格
常用数据库建模
网络安全小故事有哪些
秦皇岛软件开发销售公司
计算机网络技术员比赛
电脑智能网络安全模式
网络安全的概念英语
市面主流的云服务器有哪些比比较
开速软件开发股份有限公司官网
江西pdu服务器专用电源批发商
我的世界1.8.9pvp服务器ip地址