老李分享:《Linux Shell脚本攻略》 要点(六)

本文介绍了一系列实用的Linux网络管理命令,包括打印网络接口列表、查看名字服务器、进行DNS查找及探测局域网内活动主机等操作。此外还提供了一个用于监控多台服务器运行时间的脚本示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

老李分享:《Linux Shell脚本攻略》 要点(六)

 
1、打印网络接口列表
[root@localhost touch_more]# ifconfig | cut -c-10 | tr -d ' ' | tr -s '\n'
eth0
lo
//cut -c-10 ;  输出前10个字符;
//tr -d ' ' ;      删除所有空格;
//tr -s '\n';     压缩重复的换行符
 
2、查看名字服务器
[root@localhost touch_more]# cat /etc/resolv.conf 
# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 192.168.119.2
 
3、DNS查找
[root@localhost touch_more]# nslookup www.youkuaiyun.com
Server:         192.168.119.2
Address:        192.168.119.2#53

Non-authoritative answer:
www.youkuaiyun.com    canonical name = www.youkuaiyun.com.aqb.so.
Name:   www.youkuaiyun.com.aqb.so
Address: 14.17.69.22
 
4、列举出局域网中同一网段的所有的活动主机

[root@localhost program_test]# cat list_active_hosts.sh 
#!/bin/bash

for ip in 192.168.119.{1..255} ;
do
ping $ip -c 2 &> /dev/null;

if [ $? -eq 0 ];
then
echo $ip is active!
fi
done
[root@localhost program_test]# ./list_active_hosts.sh 
192.168.119.1 is active!
192.168.119.2 is active!

5、系统运行时间监视

<pre name="code" class="plain" style="font-size: 14px;">[root@localhost program_test]# cat ssh_test.sh
#!/bin/bash

IP_LIST="192.168.119.1 192.168.119.2 192.168.119.128"
USER="yxy"

for ip in $IP_LIST;
do
utime=$(ssh $USER@$ip uptime | awk '{ print $3 }' )
echo $ip uptime: $utime
done

 

转载于:https://www.cnblogs.com/poptest/p/4988968.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值