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.178linux.com/63219

(0)
396064847396064847
上一篇 2016-12-11 14:59
下一篇 2016-12-11 17:25

相关推荐

  • 小白学习Linux系统一周总结

         告别平凡,安定而又没什么前途的工作,我选择了报了门热门的计算机课程--python运维开发。我不知道为什么一开始就学Linux系统,我早预料到这是一个艰难的开始,还好我不是完全没有基础,以前有学过iOS开发。看到着终端中的“\”表示根目录,我轻微有点亲切感,不像第一次看到终端时的恐惧。我总结这周的学习感受,希…

    Linux干货 2017-09-04
  • CentOS程序包管理

    对于Linux系统而言,其能执行的程序为二进制格式,而对于程序开发者而言,直接利用二进制开发程序是不太现实的,所以一般都是利用高级语言来进行软件开发,其程序也即称为源代码;那么我们在对一个程序进行安装、升级、卸载、 查询、校验等操作时,需要对每个源代码进行编译成为二进制程序,那么显然是不太现实的。所以在各Linux发行版中一般都带有程序包管理器。 所谓程序包…

    Linux干货 2016-08-25
  • NFS,samba,vsftpd的基本使用

    一.NFS介绍 NFS(Network File System),全名叫做网络文件系统,是由SUN公司研发的。顾名思义,简单理解就是通过网络互联,将本地的文件系统共享出去,从而实现资源的共享,NFS监听在TCP的2049端口上。当涉及到主机之间的通信时,就会存在安全问题,于是为了安全考虑,主动提出请求的一方(客户端)需要提供一些基本信息来认证,这些信息是需要…

    Linux干货 2017-01-04
  • grup修复与安装操作介绍

    一、bgru Stage1的安装     1、stage1存储在MBR的前446字节,首先破坏。使用dd命令     2、使用grub-install命令安装修复grub stage1     3、使用grub命令修复 二、进入救援模式,修改grub     1、先破坏grub …

    Linux干货 2016-06-03
  • 迁移用户数据到独立分区

    Linux操作系统中,/home目录下为各个普通用户的家目录,主要用于存放用户的配置信息及相关文件。若安装操作系统时,采用了home目录与根目录处在同一分区的分区策略,那么随着用户数据较多,很有可能将分区空间耗尽,导致系统崩溃。所以最好是将用户数据所在目录放在一个独立的分区上,但由于/home目录下已有一些用户数据,要想将home目录建立在一个独立的分区上,…

    Linux干货 2017-08-13
  • zabbix监控Hadoop的实现

            Hadoop日常运行过程中一些参数需要进行实时监控,如:Map、Reduce任务数量,HDFS磁盘使用情况,namenode、datanode在线数量及健康情况,以便更好的掌握整个Hadoop集群架构的运行情况。         下面结合最近工作中的一些…

    Linux干货 2015-03-08

评论列表(1条)

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

    文章标题和内容中的相关脚本可以单独抽出来分成两个专题~~其中脚本注意缩进,养成良好的习惯。加油~