马哥教育网络班21期+第8周课程练习

1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。

集线器:工作在物理层,对信号作放大处理,转发比特流,所有端口都是共享带宽都是一个冲突域,使用在小型局域网内。

网桥:早期的二层数据链路层设备,可以建立和维护MAC地址表,独享带宽,每个端口是一个冲突域,使用在小型局域网内。

交换机:工作在数据链路层,可以学习和维护MAC地址,之后报文基于MAC转发,独享带宽,每个端口是一个冲突域,有的可以划分VLAN,使用在局域网内。

三层交换机:工作在网络层,在不同VLAN间通信提供基于硬件模块的快速转发,支持路由器的部分功能,一次路由,多次转发,一般使用在局域网的汇聚层,或者核心层。

路由器:工作在网络层,连接不同网络,基于路由表为不同网络间通信提供ip路由,使用在城域网或者局域网内。

2、IP地址的分类有哪些?子网掩码的,表示形式及其作用。

A类:1.0.0.0-126.255.255.255 mask 255.0.0.0/8 private 10.0.0.0-10.255.255.255 net 2^7 host 2^24-2

B类:128.0.0.0-191.255.255.255 mask 255.255.0.0/16 private 172.16.0.0-172.31.255.255 net 2^14 host 2^16-2

C类:192.0.0.0-223.255.255.255 mask 255.255.255.0/24 private 192.168.0.0-192.168.255.255 

net 2^21 host 2^8-2

D类:multicast 224.0.0.0-239.255.255.255

E类:reservation 240.0.0.0-255.255.255.254 

3、计算机网络的分成模型有哪些(OSI模型和TCP/IP模型),每一层的功能及涉及到的物理设备有哪些。

OSI:物理层(比特流),数据链路层(数据帧),网络层(IP数据段),传输层(TCP,UDP数据包),会话层(控制管理会话),表示层(编码,加密),应用层(应用层协议,软件)

TCP/IP:网络连接接口层,网络层,传输层,应用层

4、如何将Linux主机接入到TCP/IP网络,请描述详细的步骤。(手动指定的方式)

IP/mask Route/Gateway DNS 分别可以静态指定,动态分配(DHCP)

ifconfig interface ip netmask , ip addr add ip/mask dev interface,route add -net 0.0.0.0 0.0.0.0 gw 0.0.0.0,全是临时生效

5、为Linux主机配置网络信息的方式有哪些,请描述各个过程。

例如/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

HWADDR=00:0C:29:E7:51:E1

TYPE=Ethernet

UUID=d1c7dd22-10f6-4d5e-910e-71c6ae9cc57d

ONBOOT=no

NM_CONTROLLED=yes

BOOTPROTO=dhcp

IPADDR:指明IP地址;

NETMASK:子网掩码;

GATEWAY: 默认网关;

DNS1:第一个DNS服务器指向;

DNS2:第二个DNS服务器指向;

/etc/sysconfig/network-scripts/route-IFACE

TARGET via GW

/etc/resolv.conf

nameserver 192.168.40.2

6、写一个脚本,使用ping命令探测192.168.40.1-192.168.40.254之间的所有主机的在线状态;

     在线的主机使用绿色显示;

     不在线的主使用红色显示;

[root@centos test]# bash -x  exercise6.sh  | head -3
+ net=192.168.40.
+ for i in '{1..255}'
+ ping -c 3 192.168.40.1
+ '[' 1 -eq 0 ']'
+ echo -e 'host:\033[31m 192.168.40.1  is down! \033[0m'
+ for i in '{1..255}'
+ ping -c 3 192.168.40.2
host: 192.168.40.1  is down! 
+ '[' 0 -eq 0 ']'
+ echo -e 'host:\033[32m 192.168.40.2 is up! \033[0m'
+ for i in '{1..255}'
+ ping -c 3 192.168.40.3
host: 192.168.40.2 is up! 
+ '[' 1 -eq 0 ']'
+ echo -e 'host:\033[31m 192.168.40.3  is down! \033[0m'
+ for i in '{1..255}'
+ ping -c 3 192.168.40.4
host: 192.168.40.3  is down! 
+ '[' 1 -eq 0 ']'
+ echo -e 'host:\033[31m 192.168.40.4  is down! \033[0m'
[root@centos test]# cat /test/exercise6.sh 
#!/bin/bash
net=192.168.40.
for i in {1..255};do
ping  -c 3 $net$i&>/dev/null
if [ $? -eq 0 ];then
echo  -e "host:\033[32m $net$i is up! \033[0m"
else
echo  -e "host:\033[31m $net$i  is down! \033[0m"
fi
done

7、详细描述每个网络接口的配置文件中各个参数的含义和其所对应的值;

DEVICE=eth0

HWADDR=00:0C:29:E7:51:E1

TYPE=Ethernet

UUID=d1c7dd22-10f6-4d5e-910e-71c6ae9cc57d

ONBOOT=no

NM_CONTROLLED=yes

BOOTPROTO=dhcp

IPADDR:指明IP地址;

NETMASK:子网掩码;

GATEWAY: 默认网关;

DNS1:第一个DNS服务器指向;

DNS2:第二个DNS服务器指向

8、如何给网络接口配置多个地址,有哪些方式?

一般采用网卡别名形式,ifconfig interface{0..+} ip netmask , ip addr add ip/mask dev interface{0..+}

9、常用的网络管理类工具有哪些,并用示例形式描述他们的使用方法。

ip:ip addr add ip/mask dev interface, ip {link/addr} show, ip link set interface up/down, ip addr flush dev interface, ip addr { add | del } IFADDR dev STRING

ifconfig: ifconfig interface ip netmask, ifconfig interface up/down

setup:网络设置导向

nmcli [OPTIONS] OBJECT { COMMAND | help }

nmcli con show,nmcli dev show interface, nmcli device disconnect/connect interface,nmcli connection add type ethernet con-name NAME_OF_CONNECTION ifname interface-name ip4 IP_ADDRESS gw4 GW_ADDRESS,

nmcli connection modify IFACE [+|-]setting.property value

setting.property:

ipv4.addresses

ipv4.gateway

ipv4.dns1

10、Linux系统软件包管理方法(安装、升级、卸载等操作)有哪些,以及如何管理的。

rpm   安装:-ivh, –nodeps, –replacepkgs

      卸载:-e, –nodeps

      升级:-Uvh, -Fvh, –nodeps, –oldpackage

      查询:-q, -qa, -qf, -qi, -qd, -qc, -q –scripts, -q –changlog, -q –provides, -q –requires,其中-c: 查询程序的配置文件-d: 查询程序的文档-i: information-l: 查看指定的程序包安装后生成的所有文件;–scripts:程序包自带的脚本片断-R: 查询指定的程序包所依赖的CAPABILITY;-p 是针对未安装的rpm包作查询动作

      校验:-V

      导入GPG密钥:–import, -K, –nodigest, –nosignature

      数据库重建:–initdb, –rebuilddb

yum   

       安装程序包:

       install package1 [package2] […]

       reinstall package1 [package2] […]  (重新安装)

       升级程序包:

       update [package1] [package2] […]

       downgrade package1 [package2] […] (降级)

       检查可用升级:

       check-update

       卸载程序包:

       remove | erase package1 [package2] […]

       查看程序包information:

       info […]

       查看指定的特性(可以是某文件)是由哪个程序包所提供:

       provides | whatprovides feature1 [feature2] […]

       清理本地缓存:

      clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]

      构建缓存:

      makecache

      搜索:

      search string1 [string2] […]

      查看指定包所依赖的capabilities:

      deplist package1 [package2] […]

      包组管理的相关命令:

      groupinstall group1 [group2] […]

      groupupdate group1 [group2] […]

      grouplist [hidden] [groupwildcard] […]

      groupremove group1 [group2] […]

      groupinfo group1 […]

11、如何使用发行版光盘作为yum repository,请描述该过程。

mount /dev/cdrom /media/

在/etc/yum.repos.d/中新建以.repo结尾的文件,并输入以下内容

[c6-media]

name=CentOS-$releasever – Media

baseurl=file:///media/

gpgcheck=0

enabled=1

12、写一个脚本,完成以下功能

   (1) 假设某目录(/etc/rc.d/rc3.d/)下分别有K开头的文件和S开头的文件若干;

   (2) 显示所有以K开头的文件的文件名,并且给其附加一个stop字符串;

   (3) 显示所有以S开头的文件的文件名,并且给其附加一个start字符串;

   (4) 分别统计S开头和K开头的文件各有多少;

startS99libvirt-guests
startS99local
Begin_K:27
Begin_S:33
[root@centos test]# cat exercise7.sh 
#!/bin/bash
dir=/etc/rc.d/rc3.d
begin_K=$(ls  $dir | grep "^K" | wc -l)
begin_S=$(ls  $dir | grep "^S" | wc -l)
for i in $(ls  $dir);do
echo "$i"| grep "^K" &>/dev/null && echo "stop$i" || echo "start$i"
done
echo "Begin_K:$begin_K"
echo "Begin_S:$begin_S"

13、写一个脚本,完成以下功能

   (1) 脚本能接受用户名作为参数;

   (2) 计算此些用户的ID之和;

[root@centos test]# ./exercise8.sh hehe haha
hehe  must be a user account!
haha  must be a user account!
usersid:0
[root@centos test]# ./exercise8.sh test derulo
test  must be a user account!
usersid:500
[root@centos test]# ./exercise8.sh test1 derulo
usersid:1002
[root@centos test]# cat exercise8.sh 
#!/bin/bash
[ $# -eq 0 ] && echo "At least one user account,My Darling!" && exit 12
declare -i sum=0
for i in $*;do
id $i &> /dev/null ||  echo "$i  must be a user account!"
if id $i &> /dev/null ;then
let sum+=$(id $i | cut -d " " -f1 | tr "()" " " | cut -d"=" -f2 |cut -d" " -f1
)
fi        
done     
echo "usersid:$sum"

14、写一个脚本

   (1) 传递一些目录给此脚本;

   (2) 逐个显示每个目录的所有一级文件或子目录的内容类型;

   (3) 统计一共有多少个目录;且一共显示了多少个文件的内容类型;

[root@centos test]# ./exercise1.sh /etc/rc.d/rc3.d/S55sshd /etc/issue /nono /dev/sda1 /etc/
/etc/rc.d/rc3.d/S55sshd is a symbol link file.
/etc/issue is a Common file.
/nono file or directory doesn't exisits!
/dev/sda1 is anther type.
/etc/ is a directory.
in total files:1
in total directories:1
in total symbol link files:1
[root@centos test]# cat exercise1.sh 
#!/bin/bash
declare -i filenum=0
declare -i dirnum=0 
declare -i linknum=0
[ $# -eq 0 ] && echo "Please input a few files or dicrectories!" && exit 12
for i in $*; do
if [ ! -e $i ];then
echo "$i file or directory doesn't exisits!"
continue
elif [ -f $i -a ! -h $i  ];then echo "$i is a Common file."
let filenum++
elif [ -d $i ];then echo "$i is a directory."
let dirnum++
elif [ -L $i ];then echo "$i is a symbol link file."
let linknum++
else
echo "$i is anther type."
fi
done
echo "in total files:$filenum"
echo "in total directories:$dirnum"
echo "in total symbol link files:$linknum"

15、写一个脚本

  通过命令行传递一个参数给脚本,参数为用户名

  如果用户的id号大于等于500,则显示此用户为普通用户;

[root@centos test]# ./exercise12.sh ntp
System User!
[root@centos test]# ./exercise12.sh derulo
Common User!
[root@centos test]# ./exercise12.sh hehe
user doesn't exsits!
[root@centos test]# ./exercise12.sh hehe haha
available for one user!
[root@centos test]# cat exercise12.sh 
#!/bin/bash
[ $# -eq 0 ] && echo "at least one user!" && exit 12
[ $# -gt  1 ] && echo "available for one user!" && exit 11
 ! id $1 &> /dev/null  &&   echo "user doesn't exsits!" && exit 10
v=$(id $1 | cut -d " " -f1 | tr "()" " " | cut -d"=" -f2 |cut -d" " -f1)
if [ $v -ge 500 ];then
echo "Common User!"
else
echo "System User!"
fi

16、写一个脚本

   (1) 添加10用户user1-user10;密码同用户名;

   (2) 用户不存在时才添加;存在时则跳过;

   (3) 最后显示本次共添加了多少用户;

[root@centos test]# useradd user1
[root@centos test]# useradd user3
[root@centos test]# useradd user4
[root@centos test]# useradd user9
[root@centos test]# ./exercise13.sh 
user1 exisits!
Changing password for user user2.
passwd: all authentication tokens updated successfully.
user2 added!
user3 exisits!
user4 exisits!
Changing password for user user5.
passwd: all authentication tokens updated successfully.
user5 added!
Changing password for user user6.
passwd: all authentication tokens updated successfully.
user6 added!
Changing password for user user7.
passwd: all authentication tokens updated successfully.
user7 added!
Changing password for user user8.
passwd: all authentication tokens updated successfully.
user8 added!
user9 exisits!
Changing password for user user10.
passwd: all authentication tokens updated successfully.
user10 added!
added:6
exisit:4
[root@centos test]# cat exercise13.sh 
#!/bin/bash
declare -i exisitnum=0  
declare -i addnum=0  
for i in {1..10};do
if id user$i &>/dev/null ;then
echo "user$i exisits!"
let exisitnum++
continue
else 
useradd user$i && echo "$i" | passwd --stdin user$i && echo "user$i added!"
let addnum++
fi
done
echo -e "added:$addnum\nexisit:$exisitnum"

17、打印九九乘法表;

[root@centos test]# cat exercise2.sh 
#!/bin/bash
for j in {1..9}; do
for i in $(seq 1 $j); do
echo -e -n "${i}X${j}=$[$i*$j]\t"
done
echo
done

原创文章,作者:Snoo,如若转载,请注明出处:http://www.178linux.com/27106

(0)
上一篇 2016-08-05 16:15
下一篇 2016-08-05 16:15

相关推荐

  • 马哥教育网络班21期第9周课程练习

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash # declare -i nologin_user;other_user all_users=`awk -F':'…

    Linux干货 2016-09-19
  • RHEL6.4 yum访问HTTPS源时出错

    在RHEL6.4上安装OpenStack时,使用epel的源,但源是https的,进行安装时,总报下面的错误。     https://repos.fedorapeople.org/repos/openstack/openstack-icehouse/epel-6/repodata/repomd.xml:  …

    Linux干货 2016-02-28
  • shell脚本的一点补充

    脚本内容补充 数组 变量:存储单个元素的内存空间数组:存储多个元素的连续的内存空间,相当于多个变量的集合。 数组名和索引 索引:编号从0开始,属于数值索引注意:索引可支持使用自定义的格式,而不仅是数值格式,即为关联索引,bash4.0版本之后开始支持。bash的数组支持稀疏格式(索引不连续) 数组的使用 声明数组: declare -a ARRAY_NAME…

    Linux干货 2016-08-24
  • 关于大型网站技术演进的思考(十四)–网站静态化处理—前后端分离—上(6)

    原文出处: 夏天的森林   前文讲到了CSI技术,这就说明网站静态化技术的讲述已经推进到了浏览器端了即真正到了web前端的范畴了,而时下web前端技术的前沿之一就是前后端 分离技术了,那么在这里网站静态化技术和前后端分离技术产生了交集,所以今天我将讨论下前后端分离技术,前后端分离技术讨论完后,下一篇文章我将会以网站 静态化技术的…

    Linux干货 2015-03-03
  • sed对比grep之理解

    sed对比grep之理解 很多时候回车按下,没有结果,或是报错。 检查发现都是低级错误,关键是习惯刚学完grep,有写习惯没改过来。 sed语法很重要。script语法写对了,就成功了一大半,剩下的就是正则表达式的问题了。 sed与grep的区别是 grep是个行过滤器,筛选符合条件的行。也可以只显示每行匹配到的文本(-o选项),不对文本进行编辑,只是显示查…

    Linux干货 2016-08-10
  • Linux基础学习总结(六)

    一、创建一个10G分区,并格式为ext4文件系统; 1、要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; [root@blog ~]# fdisk /dev/sdfCommand (m for help): nCommand action e extended p primary partition (1…

    2016-11-06

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-05 17:01

    写的很好,排版还可以在漂亮一点,加油