第七章:網絡操作
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.csdn.net
Server: 192.168.119.2
Address: 192.168.119.2#53
Non-authoritative answer:
www.csdn.net canonical name = www.csdn.net.aqb.so.
Name: www.csdn.net.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
作者:銘毅天下
轉載請标明出處,原文位址:
http://blog.csdn.net/laoyang360/article/details/42364877