马哥教育网络班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)
SnooSnoo
上一篇 2016-08-05
下一篇 2016-08-05

相关推荐

  • linux入门第二课

    **linux入门基础** linux 命令类别 内部命令和外部命令 首先我们可以用echo $SHELL 来查询shell 里面会显示我们当前在用的shell 上图是echo $SHELL 也可以用cat /etc/shells来查询系统里面的shell bash其实是一个文件是一个程序 存在于 /bin/bash 目录,这是真是存在的文件,是一个可以执行…

    Linux干货 2017-05-20
  • Linux系统启动过程中grub故障与修复(一)

    GRUB 是引导装入器 — 它负责装入内核并引导 Linux 系统。GRUB 可以引导多种操作系统,如Linux、 DOS、 Windows 。 GRUB共分为三个阶段:stage1主要负责BIOS和GRUB之间的交接,载入存放于各个分区中的开机文件;stage1.5是连接stage1和stage2之间的通道,起着过渡的作用,负责识别stage2所在/bo…

    2017-09-03
  • Linux下的I/O重定向与管道

    一、I/O设备     Linux中,对系统进行操作时,就需要I/O设备与系统产生交互,同时会产生三种数据,标准输入(0)、标准输出(1)、标准错误(2)。其中标准输入(stdin)默认接受来自键盘的输入,标准输出(stdout)和标准错误(stderr)默认向终端窗口输出,改变默认输出和出入的位置,就是I/O重定向。 二、输出重定向到文…

    Linux干货 2016-08-04
  • 网络26期 第五周作业

    1. 显示当前系统上root、fedora或user1用户的默认shell egrep -o “^(root|fedora|user1)\>.*[^:]+$” /etc/passwd | cut -d: -f1,7 2. 找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello(…

    2017-03-13
  • CentOS启动流程及Shell脚本编程练习

    一、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情) 第一步:POST加电自检 主要实现的功能是检测各个外围硬件设备是否存在而且能够正常运行起来,实现这一自检功能的是固化在主板上的ROM(主要代表为CMOS)芯片上的BIOS(Basic Input/Output System)程序。 第二步:Boot Sequence(选择启动设备以加…

    2017-11-26
  • Linux运维之磁盘管理

    ※磁盘管理 计算机是由五大组成部件:输入设备,输出设备,存储器,运算器,控制器,其中输入设备我们称之为I/O设备,如键盘,扫描器,运算器和控制称之为cpu,存储器如,内存,硬盘,优盘。计算机其实只需要内存和cpu其实已经可以完成工作了,但是内存属于随机存储设备,断电之后就丢失数据,所以我们就需要通过其他的辅助存储设备来弥补内存的不足,这些辅存我们称之为外存。…

    Linux干货 2016-08-27

评论列表(1条)

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

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