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.www58058.com/72170