Linux基礎知識——網絡管理基礎

OSI七層模型與TCP/IP模型的區別

Linux基礎知識——網絡管理基礎

寫一個腳本,使用ping命令探測172.168.250.1-172.168.250.254之間的所有主機的在線狀態,在線的用綠色表示,不在線的使用紅色表示

#!/bin/bash

for ((IP=1;IP<=254;IP++))
    do
    ping -c 3 -w 3 172.16.250.$IP >> /dev/null 2>&1
    if [ $? -eq 0 ];then 
    echo -e "\033[031m 172.16.250.$IP \033[0m is online"
    else 
    echo -e "\033[032m 172.16.250.$IP \033[0m connects failed"
    fi
    done

常用的網絡管理類工具,描述其使用示例

ifconfig ~configure a network interface

【SYNOPSIS】
          ifconfig [-v] [-a] [-s] [interface]
          ifconfig [-v] interface [aftype] options | address ...

【OPTIONS】
    -a     display all interfaces which are currently available, even if down
    -s     display a short list (like netstat -i)
    interface
        up      This flag causes the interface to be activated
        down    This flag causes the driver for this interface to be shut down
        address xxx.xxx.xxx.xxx     set IP to interface
        dstaddr addr        Set the remote IP address for a point-to-point link (such as PPP)

ip ~show / manipulate routing, devices, policy routing and tunnels

【SYNOPSIS】
   ip [ OPTIONS ] OBJECT { COMMAND | help }
   ip [ -force ] -batch filename

   OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable | tunnel | tuntap | maddr | mroute |
           mrule | monitor | xfrm | netns | l2tp | tcp_metrics }
   OPTIONS := { -V[ersion] | -s[tatistics] | -r[esolve] | -f[amily] { inet | inet6 | ipx | dnet | link } |
           -o[neline] | -n[etns] name }
具體的參考可使用 ip OBJECT help
ip {link|addr|addrlabel……} help

route~show / manipulate the IP routing table

【SYNOPSIS】
route  [-v]  [-A  family  |-4|-6] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M] [window W]
          [irtt I] [reject] [mod] [dyn] [reinstate] [[dev] If]
   route  [-v] [-A family |-4|-6] del [-net|-host] target [gw Gw] [netmask Nm] [metric N] [[dev] If]
【OPTIONS】
    add     add a new route
    del     del a route
    -n     show  numerical  addresses  instead of trying to determine symbolic host names.
【example】
    route add -net 127.0.0.0 netmask 255.0.0.0 dev lo
    route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0
    route add -net 192.57.66.0 netmask 255.255.255.0 gw ipx4

netstat – Print network connections, routing tables, interface statistics, masquerade connections, and mul‐ ticast memberships

【OPTIONS】
    -r, --route              display routing table
        -I, --interfaces=<Iface> display interface table for <Iface>
        -i, --interfaces         display interface table
        -W, --wide               don't truncate IP addresses
        -n, --numeric            don't resolve names
        -e, --extend             display other/more information
        -p, --programs           display PID/Program name for sockets
        -o, --timers             display timers
        -l, --listening          display listening server sockets
        -a, --all                display all sockets (default: connected)

寫一個腳本,完成以下功能:1)假設某目錄(/etc/rc.d/rc3.d/)下分別有K開頭的文件和S開頭的文件若干;2)顯示所有以K開頭的文件的文件名,并且給其附加一個stop字符串;3)顯示所有以S開頭的文件的文件名,并且給其附加一個start字符串;4)分別統計S開頭和K開頭的文件各有多少

#!/bin/bash
declare i=0
declare j=0
cd /etc/rc.d/rc3.d
for file in $(ls|grep -iE "^k|^s")
do
    FC=$(echo $file|cut -b 1)
    case $FC in
    k|K)
        echo "$file"stop
        i=$(($i+1))
    ;;
    s|S)
        echo "$file"start
        j=$(($j+1))
    ;;
    *)
        continue
    ;;
    esac 
done
        echo "the header of K has $i"
        echo "the header of S has $j"

寫一個腳本,完成以下功能:1)腳本能接受用戶名作為參數;2)計算此些用戶的ID之和;

#!/bin/bash

declare sum=0
if [ $# -le 1 ];then
    echo "Please input more than one user's name!"
else

while [ $# -gt 0 ]
do
    id -u $1 >> /dev/null 2>&1
    if [ $? != 0 ];then
    echo "the user $1 is not exist !"&& exit

    else
#   ID=$(id -u $1)
sum=$(($(id -u $1)+$sum))
#   sum=$(($ID+$sum))
    fi
    shift
done
echo "the sum of all user's id is $sum" 
fi

寫一個腳本,1)傳遞一些目錄給腳本;2)逐個顯示每個目錄的所有一級文件或者子目錄的內容類型;3)統計一共多少個目錄,且一共顯示了多少個文件的內容類型

寫一個腳本,通過命令行傳遞一個參數,參數為用戶名,如果用戶的id號大于等于500,則顯示此用戶為普通用戶;

#!/bin/bash

read -p "Please insert a username:" name

if [ -z $name ]
   then 
    echo "U must insert a username!"
    elif [ $(id -u $name) -le 500 ]
       then 
    echo "$name is a manager"
else 
    echo "$name is a ordinary"
    fi

寫一個腳本,1)添加10個用戶user1-user10,密碼同用戶名;2)用戶不存在時才添加,存在時則跳過;3)最后顯示本次一共添加了多少個用戶

#!/bin/bash

declare sum
for (( i=1;i<10;i++ ))
    do
    id user$i>/dev/null 2>&1;
    if [ $? -eq 0 ];then 
        continue
    else
        useradd user$i && echo "user$i"|passwd --stdin user$i>>/dev/null 2>&1;
        echo "create user$i successful!"
    sum=$(($sum+1))
    fi
done
    echo "There are $sum users were created"

寫一個腳本,用ping命令測試172.168.250.20-172.168.250.100以內那些主機在線,將在線的顯示出來

#!/bin/bash
for IP in {20..100}
    do
    ping -c 3 -w 3 192.168.1.$IP >> /dev/null 2>&1
    test $? -eq 0 && echo -e "\033[032m 192.168.1.$IP \033[0m is online" || continue
    done

打印99乘法表

#!/bin/bash

for ((m=1;m<=9;m++))
    do
    echo    
    for ((n=1;n<=m;n++))
    do
    sum=$(($n*$m))
    echo -en "$n*$m=$sum\t"
    done
done
echo

原創文章,作者:396064847,如若轉載,請注明出處:http://www.www58058.com/63219

(0)
396064847396064847
上一篇 2016-12-11
下一篇 2016-12-11

相關推薦

  • Linux權限管理練習

    1、當用戶xiaoming對/testdir 目錄無執行權限時,意味著無法做哪些操作? 無法cd切換進入此目錄,無法創建文件,無法刪除文件,無法查看里面文件的內容,只能ls列出目錄下的內容 2、當用戶xiaoqiang對/testdir 目錄無讀權限時,意味著無法做哪些操作? 無法ls查看目錄下的內容 3、當用戶wangcai 對/testdir 目錄無寫權…

    Linux干貨 2016-08-05
  • Linux發行版的基礎目錄名稱、功能及目錄的命名法則

    Linux發行版的基礎目錄名稱、功能及目錄的命名法則 基礎目錄名稱及功能 /lib 32位系統的基礎共享庫文件和可裝載的內核模塊,用于為/bin和/sbin下的程序提供共享庫,并為內核提供內核模塊 /lib64 64位系統的基礎共享庫文件,用于為/bin和/sbin下的程序提供共享庫 /etc 系統程序的配置文件 /bin 用戶命令的程序文件,所有用戶可用 …

    Linux干貨 2017-07-02
  • lvm簡要及基本操作

        LVM( Logical Volume Manage,邏輯 邏輯卷管理)LVM將一個或多個硬盤的分區在邏輯上集合,相當于一個大硬盤來使用,當硬盤的空間不夠使用的時候,可以繼續將其它的硬盤的分區加入其中,這樣可以實現磁盤空間的動態管理,相對于普通的磁盤分區有很大的靈活性。  &nbs…

    Linux干貨 2016-05-23
  • samba應用

    samba詳解 前言 前面學過了NFS,是一個網絡文件系統,可以讓遠程連接像訪問本地文件一樣,在同一個網絡上的多個用戶間共享目錄和文件系統。只不過NFS只是針對于兩個linux主機,我們現在需要linux主機和windows主機都能共享,這個時候就用到了samba。 1、步驟,允許個別用戶訪問 1、安裝下面三個包: samba samba-common sa…

    Linux干貨 2016-12-21
  • 硬鏈接與軟鏈接的簡述

    我們知道文件都有文件名與數據,這在 Linux 上被分成兩個部分:用戶數據 (user data) 與元數據 (metadata)。用戶數據,即文件數據塊 (data block),數據塊是記錄文件真實內容的地方;而元數據則是文件的附加屬性,如文件大小、創建時間、所有者等信息。在 Linux 中,元數據中的 inode 號(inode 是文件元數據的一部分但…

    Linux干貨 2016-10-20
  • 基于centos7的http的應用

     練習:分別使用CentOS 7和CentOS 6實現以下任務         (1) 配置三個基于名稱的虛擬主機;             (a) discuzX             …

    Linux干貨 2016-10-12

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-12-16 15:06

    文章標題和內容中的相關腳本可以單獨抽出來分成兩個專題~~其中腳本注意縮進,養成良好的習慣。加油~

欧美性久久久久