1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。
 三层交换机:将路由技术和交换技术合二为一的技术,当对第一次数据流进行路由后,会产生一个MAC地址与IP地址相对应的映射表,当同样的数据流再次通过时,将根据映射表进行数据交换而不在进行路由。 路由器:工作于网络层,将从收到的数据中取出包头地址,根据地址和算法计算出最佳路径发送数据包至目标地址,应逻辑上独立的子网。
2、IP地址的分类有哪些?子网掩码的表示形式及其作用
ip地址采用网路号+主机号的方式进行分类,大致5类: A类:第一个字段为网络号,后面三个字段类主机号,网络号十进制表示范围从1.0.0.1-126.255.255.254. B类:前两个字段为网络号,后两个字段为主机号,网络地址的最高位以“10”开始,地址范围从128.1.0.1-191.255.255.254. C类:前三段字段为网络号,后一字段为主机号,网络地址的最高位以“110”开始,网络号十进制表示范围从192.0.1.1-223.255.255.254. D类:以1110开始,用于多点广播,范围从224.0.0.1-239.255.255.254. E类:以1111开始,仅作实验用。 子网掩码的表示形式可以分为两种,以4个字节表示或数值表示,例如:192.168.1.105/255.255.255.0 或 192.168.1.105/24. 子网掩码主要用于区分不同的ip是否属于同一网段,主要是通过对不同的二进制表示的ip与掩码分别进行与运算,两者结果相同则为同一网段,否则不属于同一网段。
3、计算机网络的分成模型有哪些(OSI模型和TCP/IP模型),每一层的功能及涉及到的物理设备有哪些。

4、如何将Linux主机接入到TCP/IP网络,请描述详细的步骤。(手动指定的方式)
配置主机接入网络大致分三步:
1.手动配置ip:
进入配置网卡配置文件 cd /etc/sysconfig/network-scripts/ifcfg-eno16777736,BOOTPROTO=STATIC.
添加ip地址: ifconfig eno16777736 192.168.1.110/24.
2.添加路由:
route add default gw 192.68.1.0.
3.配置DNS
配置文件路径 /etc/resolv.conf
4.重启网卡并进行车市
dig -x A www.testpage.com
如果能成功解析说明配置成功。
5、为Linux主机配置网络信息的方式有哪些,请描述各个过程。
主要有:
(1)ifconfig
ifconfig: 查看本地ip,网卡信息
ifconfig DEV add IP/NETMASK 添加多个ip
(2) ip 家族
ip address {add|del|show|flush) dev
(3) 配置文件 /etc/sysconfig/network-scripts/IFACE.
6、写一个脚本,使用ping命令探测172.16.250.1-172.16.250.254之间的所有主机的在线状态;在线的主机使用绿色显示;不在线的主使用红色显示;
#!/bin/bash
for i in {1..254};do
if ping -w 1 -c 1 192.168.1.$i &> /dev/null;then
echo -e "\033[32m192.168.1.$i\033[0m"
else
echo -e "\033[31m192.168.1.$i\033[0m"
fi
done

7、详细描述每个网络接口的配置文件中各个参数的含义和其所对应的值;
TYPE=Ethernet 网络类型 DEFROUTE=yes 默认路由 IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6是否初始化 IPV6_AUTOCONF=yes 是否自动配置ipv6 IPV6_DEFROUTE=yes 默认路由 NAME=eno16777736 接口名称 UUID=d87d3568-cfd1-4b17-9639-6dccf13b36e3 此设备的ID DEVICE=eno16777736 此配置文件对应的设备的名称 ONBOOT=yes 系统引导过程中是否激活此接口 BOOTPROTO=shared 采用什么协议配置接口,通常有 DHCP,BOOTP,STATIC,NONE IPADDR=192.168.1.102 此接口的IP 地址 PREFIX=24 ip 掩码 GATEWAY=192.168.1.1 网关 IPV6_PEERDNS=yes 启用DHCP协议时是否允许DHCP server分配的dns服务器指向覆盖本地手动指定的DNS服务器指向;
8、如何给网络接口配置多个地址,有哪些方式?
(1)ifconfig eno16777736 add 192.168.1.109 (2)ip addr add 192.168.1.112 dev eno16777736 (3)配置文件
9、常用的网络管理类工具有哪些,并用示例形式描述他们的使用方法。 (1)netstate
[root@localhost ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.1.102:53 0.0.0.0:* LISTEN 5686/dnsmasq
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1925/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1083/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1084/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1888/master
tcp6 0 0 :::22 :::* LISTEN 1083/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1084/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1888/master
(2) ss
[root@localhost ~]# ss -tnlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 192.168.1.102:53 *:* users:(("dnsmasq",pid=5686,fd=7))
LISTEN 0 5 192.168.122.1:53 *:* users:(("dnsmasq",pid=1925,fd=6))
LISTEN 0 128 *:22 *:* users:(("sshd",pid=1083,fd=3))
LISTEN 0 128 127.0.0.1:631 *:* users:(("cupsd",pid=1084,fd=13))
LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=1888,fd=13))
LISTEN 0 128 :::22 :::* users:(("sshd",pid=1083,fd=4))
LISTEN 0 128 ::1:631 :::* users:(("cupsd",pid=1084,fd=12))
LISTEN 0 100 ::1:25 :::* users:(("master",pid=1888,fd=14))
[root@localhost ~]# ss -unlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
UNCONN 0 0 *:5353 *:* users:(("avahi-daemon",pid=769,fd=12))
UNCONN 0 0 127.0.0.1:323 *:* users:(("chronyd",pid=822,fd=1))
UNCONN 0 0 *:35806 *:* users:(("avahi-daemon",pid=769,fd=13))
UNCONN 0 0 192.168.1.102:53 *:* users:(("dnsmasq",pid=5686,fd=6))
UNCONN 0 0 192.168.122.1:53 *:* users:(("dnsmasq",pid=1925,fd=5))
UNCONN 0 0 *%eno16777736:67 *:* users:(("dnsmasq",pid=5686,fd=4))
UNCONN 0 0 *%virbr0:67 *:* users:(("dnsmasq",pid=1925,fd=3))
UNCONN 0 0 ::1:323 :::* users:(("chronyd",pid=822,fd=2))
10、Linux系统软件包管理方法(安装、升级、卸载等操作)有哪些,以及如何管理的。 (1) rpm能对下载至本地的rpm包进行管理 rpm -ivh PACKAGENAME 安装 rpm -upgrade PACKAGENAME 升级 rpm -e PACKAGENAME 卸载 rpm 无法解决安装过程中的依赖关系 (2)yum 能解决安装过程中出现的依赖关系 yum install PACKAGENAME 安装 yum upgrade | update PACKGENAME 升级更新 yum remove PACKAGENAME 卸载 yum group list yum group install PACKAGENAME 组包的查询
(3)编译安装
./configure,make,make install
11、如何使用发行版光盘作为yum repository,请描述该过程。
(1) 装入发行光盘
(2) 挂载光盘至某个挂载点 mount /dev/sr0 /media/
(3) 建立仓库 vim /etc/yum.repos.d/cdrom.repo
(4) 编辑cdromp.repo
[cdrom]
name=cdrepos
baseurl=file:///media
gpgcheck=1
enable=0
(5)yum makecache,done.
12、写一个脚本,完成以下功能 (1) 假设某目录(/etc/rc.d/rc3.d/)下分别有K开头的文件和S开头的文件若干; (2) 显示所有以K开头的文件的文件名,并且给其附加一个stop字符串; (3) 显示所有以S开头的文件的文件名,并且给其附加一个start字符串; (4) 分别统计S开头和K开头的文件各有多少;
#!/bin/bash/
declare -i total_k=0
declare -i total_s=0
for i in `(ls /etc/rc.d/rc3.d/ | grep "\<K.*")`
do
echo " $i stop "
let total_k=total_k+1
done
for i in `(ls /etc/rc.d/rc3.d/ | grep "\<S.*")`
do
echo "$i start"
let total_s=total_s+1
done
echo "k files: $total_k, S files: $total_s"
[root@localhost tmp]# bash init.sh
K50netconsole stop
S10network start
k files: 1, S files: 1
13、写一个脚本,完成以下功能 (1) 脚本能接受用户名作为参数; (2) 计算此些用户的ID之和;
#!/bin/bash/
declare -a username
declare -i ids
declare -i id_sum=0
echo -n "please input all username:";read -a username
for i in $(seq 0 $[${#username[*]}-1])
do
ids=`(grep ${username[$i]} /etc/passwd | cut -d: -f3)`
id_sum=$id_sum+$ids
done
echo "total sum of id: $id_sum"
[root@localhost tmp]# bash idcounter.sh
please input all username:zabbix ftp ntp
total sum of id: 1049
14、写一个脚本 (1) 传递一些目录给此脚本; (2) 逐个显示每个目录的所有一级文件或子目录的内容类型; (3) 统计一共有多少个目录;且一共显示了多少个文件的内容类型;
#!/bin/bash
for i in `seq 1 $#`;do
ls -l $1
dir_sum=`ls -l $1 | awk '/^d/ {print $0}' | wc -l`
type_num=`ls -l $1 | awk -F "r" '!/^total/ {print $1}' | sort -u | wc -l`
echo "there are $dir_sum directory in $1, the item type num is $type_num"
shift
done
15、写一个脚本 通过命令行传递一个参数给脚本,参数为用户名 如果用户的id号大于等于500,则显示此用户为普通用户;
#!/bin/bash
grep $1 /etc/passwd |awk -F: '{$3>=500?usertype="common user":usertype="system user";print $1,$3, usertype}'
[root@localhost ~]# bash userid.sh httpd
apache 48 system user
[root@localhost ~]#
16、写一个脚本 (1) 添加10用户user1-user10;密码同用户名; (2) 用户不存在时才添加;存在时则跳过; (3) 最后显示本次共添加了多少用户;
#!/bin/bash
declare -i total_add=0
for i in {1..10}
do
if `(grep user$i /etc/passwd &> /dev/null)`;then
echo "user$i exist"
else
useradd user$i
echo "user$i" | passwd --stdin user$i
total_add=$total_add+1
fi
done
echo "total add users this time : $total_add"
[root@localhost ~]# bash userid.sh
user1 exist
Changing password for user user2.
passwd: all authentication tokens updated successfully.
Changing password for user user3.
passwd: all authentication tokens updated successfully.
Changing password for user user4.
passwd: all authentication tokens updated successfully.
Changing password for user user5.
passwd: all authentication tokens updated successfully.
Changing password for user user6.
passwd: all authentication tokens updated successfully.
Changing password for user user7.
passwd: all authentication tokens updated successfully.
Changing password for user user8.
passwd: all authentication tokens updated successfully.
Changing password for user user9.
passwd: all authentication tokens updated successfully.
Changing password for user user10.
passwd: all authentication tokens updated successfully.
total add users this time : 9
17、写一脚本,用ping命令测试172.16.250.20-172.16.250.100以内有哪些主机在线,将在线的显示出来;
#!/bin/bash
for i in {100..120}
do
ping -w 1 -c 1 192.168.1.$i &> /dev/null && echo -e "\033[32m192.168.1.$i\033[0m"
done
~
18、打印九九乘法表;”
#!/bin/bash
for i in {1..9}
do
j=1
for j in $(seq $i)
do
echo -n "$j x $i = $[ $j*$i ] "
done
echo
done
[root@localhost ~]# bash mathchart.sh
1 x 1 = 1
1 x 2 = 2 2 x 2 = 4
1 x 3 = 3 2 x 3 = 6 3 x 3 = 9
1 x 4 = 4 2 x 4 = 8 3 x 4 = 12 4 x 4 = 16
1 x 5 = 5 2 x 5 = 10 3 x 5 = 15 4 x 5 = 20 5 x 5 = 25
1 x 6 = 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36
1 x 7 = 7 2 x 7 = 14 3 x 7 = 21 4 x 7 = 28 5 x 7 = 35 6 x 7 = 42 7 x 7 = 49
1 x 8 = 8 2 x 8 = 16 3 x 8 = 24 4 x 8 = 32 5 x 8 = 40 6 x 8 = 48 7 x 8 = 56 8 x 8 = 64
1 x 9 = 9 2 x 9 = 18 3 x 9 = 27 4 x 9 = 36 5 x 9 = 45 6 x 9 = 54 7 x 9 = 63 8 x 9 = 72 9 x 9 = 81
~
原创文章,作者:diglinux,如若转载,请注明出处:http://www.178linux.com/72170

