1.你希望从服务器上下载一个软件,你的机器有两块网卡eth0和eth1,地址配置如下:
Eth0: 192.168.6.25/24
Eth1: 172.16.101.25/24
默认网关: 192.168.6.1/24
服务器地址:211.138.18.30
此时,发现你的机器有两个路由条目:
Destination Gateway Genmask Flags MSS Window irtt Iface
211.138.0.0 * 255.255.0.0 U 0 0 0 eth0
211.138.16.0 * 255.255.240.0 U 0 0 0 eth1
请问:你的机器去服务器下载软件,会如何选路,为什么?
解答:依据最小化原则选择eth1。可以精确匹配就精确匹配,不能精确匹配局走大段
详细描述:
一台机器有两块网卡eth0和eth1,要访问211.138.18.30服务器,根据最小化原则会先匹配最小网段,如果最小网段不匹配,再匹配最大网段。
由题可知211.138.16.0做了子网划分,用ipcalc工具可以分析:
wget #或者自己从网上下载一个ipcalc工具 chmod +x ipcalc ./ipcalc 211.138.16.0 255.255.240.0 Address: 211.138.16.0 11010011.10001010.0001 0000.00000000 Netmask: 255.255.240.0 = 20 11111111.11111111.1111 0000.00000000 Wildcard: 0.0.15.255 00000000.00000000.0000 1111.11111111 => Network: 211.138.16.0/20 11010011.10001010.0001 0000.00000000 HostMin: 211.138.16.1 11010011.10001010.0001 0000.00000001 HostMax: 211.138.31.254 11010011.10001010.0001 1111.11111110 Broadcast: 211.138.31.255 11010011.10001010.0001 1111.11111111 Hosts/Net: 4094 Class C
备注:网段是211.138.16.0/20,最小网段是从211.138.16.1到211.138.31.254,可以匹配到服务器地址211.138.18.30,所以机器去服务器下载软件会选择eth1
2.请用shell或perl编写一个画直角梯形程序(a.sh),接收用户输入的参数n,m
例如:a.sh 4 6
* * * *
* * * * *
* * * * * *
解答:
脚本一:
[[email protected] 2015-12-01]# sh a.sh
****
*****
******
[[email protected] 2015-12-01]# cat a.sh #/bin/sh for i in `seq 4 6` do for j in `seq $i` do echo -n ‘*‘ done echo done
脚本二:
[[email protected] 2015-12-01]# sh t.sh 4 6
* * * *
* * * * *
* * * * * *
[[email protected] 2015-12-01]# cat t.sh #!/bin/bash if [ $# -ne 2 ];then echo "error!!!" exit fi if [ $1 -gt $2 ];then i=$2 j=$1 else i=$1 j=$2 fi for m in `seq $i $j`;do str=‘‘ for i in `seq 1 $m`;do str="$str\t*" done echo $str | sed ‘s/\\t/ /g‘ done
脚本三:
[[email protected] 2015-12-01]# sh h.sh 4 6
* * * *
* * * * *
* * * * * *
[[email protected] 2015-12-01]# cat h.sh #!/bin/bash if [ $# -ne 2 ];then echo "error!!!" exit fi if [ $1 -gt $2 ];then i=$2 j=$1 else i=$1 j=$2 fi for m in `seq $i $j`;do str=‘‘ for i in `seq 1 $m`;do str="$str\t*" done echo $str | sed ‘s/\\t/ /g‘ done
附:
[[email protected]8ctZ 2015-12-01]# seq 3
1
2
3
[[email protected] 2015-12-01]# for i in $(seq 3);do echo $(seq 3);done
1 2 3
1 2 3
1 2 3
输出10行,每行3个数字
[[email protected] 2015-12-01]# for i in $(seq 10);do echo $(seq 3);done
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
输出10行,每行10个数字
[[email protected] 2015-12-01]# for i in $(seq 10);do echo $(seq 10);done
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
[[email protected] 2015-12-01]# tstr=""; for (( i = 0; i < 10; i++)); do echo "$tstr*"; tstr="$tstr*"; done
*
**
***
****
*****
******
*******
********
*********
**********
脚本输出直角梯形:
#/bin/sh for i in `seq 3 5` do forj in `seq $i` do echo-n ‘*‘ done echo done
接收用户输入的参数:
#/bin/sh while true do echo -n "pls enter the number:" $1 $2 read line sleep 1 echo "$line" done
顺便分享一下我扒来的shell学习方法:
http://www.chinaunix.net/old_jh/24/312462.html
shell综合水平测试题:
http://bbs.chinaunix.net/thread-476260-1-1.html
http://oldboy.blog.51cto.com/2561410/1718607
刀不磨要生锈。