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.www58058.com/27106
寫的很好,排版還可以在漂亮一點,加油