实现原理: [[email protected] ~]$ cat /proc/net/devInter-|   Receive                                                |  Transmitface |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed    lo:1068205690 1288942839    0    0    0     0          0         0 1068205690 1288942839    0    0    0     0       0          0  eth0:91581844 334143895    0    0    0     0          0 145541676 4205113078 3435231517    0    0    0     0       0          0proc/net/dev 文件保存了网卡总流量信息,通过间隔一段间隔,将入网卡与出记录加起来。减去之前就得到实际速率。 程序代码: 复制代码代码如下:awk 'BEGIN{OFMT="%.3f";devf="/proc/net/dev";while(("cat "devf) | getline){ if($0 ~ /:/ && ($10+0) > 0) { split($1,tarr,":"); net[tarr[1]]=$10+tarr[2]; print tarr[1],$10+tarr[2]; }}close(devf);while((system("sleep 1 ")) >=0){ system("clear"); while( getline < devf ) { if($0 ~ /:/ && ($10+0) > 0) { split($1,tarr,":"); if(tarr[1] in net) { print tarr[1],":",($10+tarr[2]-net[tarr[1]])*8/1024,"kb/s"; net[tarr[1]]=$10+tarr[2]; } } } close(devf);}}' 说明:第一个while 是获得总的初始值,$1是网卡出流量,$10是网卡进流量。第2个while会间隔1秒钟启动一次。计算总流量差得到平均每秒流量。 注意:通过getline 逐行读取文件,需要close关闭 。否则在第2次while循环中不能获得数据。 运行结果:

一. VIM高亮进入vim后,在普通模式下输入如下命令,开启php代码高亮显示   :syntax enable   :source $VIMRUNTIME/syntax/php.vim 二. VI常用命令_______________________________________________________一般模式                           光标移动__________________________________________________________h 或 向左方向键                    光标向左移动一个字符j 或 向下方向键                    光标向下移动一个字符k 或 向上方向键                    光标向上移动一个字符l 或 向右方向键                    光标向右移动一个字符Ctrl + f                           屏幕向前翻动一页(常用)Ctrl + b                           屏幕向后翻动一页(常用)Ctrl + d                           屏幕向前翻动半页Ctrl + u                           屏幕向后翻动半页+                                  光标移动到非空格符的下一列-                                  光标移动到非空格符的上一列n<space>                           接下数字后再按空格键,光标会向右移动这一行的                                   n个字符,例如20<space>,则光标会向右移动20个字符0                                  (这是数字0) 移动到这一行的第一个字符处(常用)$                                  移动到这一行的最后一个字符处(常用)H                                  光标移动到这个屏幕最上方的那一行M                                  光标移动到这个屏幕中央的那一行L                                  光标移动到这个屏幕最下方的那一行G                                  移动到这个文件的最后一行(常用)nG                                 移动到这个文件的第n行.例如20G,则会移动到这个文件的                                   第20行(可配合:set nu)n<Enter>                           光标向下移动n行(常用)________________________________________________________________一般模式                           查找替换________________________________________________________________/word                              在光标之前查找一个名为word的字符串?word                              在光标之前查找一个名为的word字符串:n1,n2s/word1/word2/g              在第n1与n2行之间查找word1这个字符串,并将该字符串替换                                   为word2(常用):1,$s/word1/word2/g                从第一行到最后一行查找word1字符串,并将该字符串替换                                   为word2(常用):1,$s/word1/word2/ge               从第一行到最后一行查找word1字符串,并将该字符串替换                                   为word2,且在替换前显示提示符让用户确认(confirm)(常用)__________________________________________________________________一般模式                           删除 复制与粘贴__________________________________________________________________x,X                                x为向后删除一个字符,X为向前删除一个字符(常用)nx                                 向后删除n个字符dd                                 删除光标所在的那一整行(常用)ndd                                删除光标所在行的向下n行,例如,20dd则是删除20行(常用)d1G                                删除光标所在行到第一行的所有数据dG                                 删除光标所在行到最后一行的所有数据yy                                 复制光标所在行(常用)nyy                                复制光标所在行的向下n行,例如,20yy则是复制20行(常用)y1G                                复制光标所在行到第一行的所有数据yG                                 复制光标所在行到最后一行的所有数据p,P                                p为复制的数据粘贴在光标下一行,P则为粘贴在光标上一行(常用)J                                  将光标所在行与下一行的数据结合成一行u                                  恢复前一个动作(常用) ____________________________________________________________________编辑模式                          ___________________________________________________________________i,I                                插入:在当前光标所在处插入输入的文字,已存在的字符会向后                                   退(常用)a,A                                添加:由当前光标所在处的下一个字符开始输入,已存在的字符                                   会向后退(常用)o,O                                插入新的一行:从光标所在处的下一行行首开始输入字符(常用)r,R                                替换:r会替换光标所指的那一个字符:R会一直替换光标所指的                                   文字,直到按下Esc为止(常用)Esc                                退出编辑模式,回到一般模式(常用) ___________________________________________________________________命令行模式                          ___________________________________________________________________ :w                                 将编辑的数据写入硬盘文件中(常用):w!                                若文件属性为只读,强制写入该文件:q                                 退出vi(常用):q!                                若曾修改过文件,又不想保存,使用!为强制退出不保存文件:wq                                保存后退出,若为:wq!,则为强制保存后退出(常用):w [filename]                      将编辑数据保存为另一个文件(类似另存新文档):r [filename]                      在编辑的数据中,读入另一个论据的数据,亦即将filename这                                   个文件内容加到光标所在行的后面:set nu                            显示行号,设定之后,会在每一行的前面显示该行的行号:set nonu                          与set nu相反,为取消行号n1,

以下是100个用法,有什么不对,还请大家指正。 1,echo "aa" > test.txt 和 echo "bb" >> test.txt //>将原文件清空,并且内容写入到文件中,>>将内容放到文件的尾部 2,chmod go+w -R /home/zhangy //给组用户和其他用户添加写的权限 3,tar -tzvf test.tar.gz //列出归档内容 4,du -ah //查看文件列表大小 5,du -sh //查看所有文件的大小总和 6,echo '1+2'|bc -l //数学运算 7,uname -a //查看linux内核等的一些信息 8,badblocks -s /dev/sda //坏道扫描时显示进度 9,time command //查看命令的运行时间 10,ls -lrt //按时间的倒序排序 11,rsync -P //同步时显示进度 12.history -c //清楚历史命令 13,cd - //返回上次目录 14,tree //显示目录树 15,umount -n /mnt/hda2 //强制卸载 16,echo ~/ //显示用户的home目录 17,echo $[5*5] //算术运算 18,echo $((5*5)) //算术运算 19,eval ls;ps aux|grep httpd //这二个命令都能执行 20,free -m //有MB为单位显示内存 21,uptime //显示系统已经运行了多长时间,它依次显示下列信息:现在时间、系统已经运行了多长时间、目前有多少登陆用户、系统在过去的1分钟、5分钟和15分钟内的平均负载 22,加法运算 [[email protected] mytest]# let a=34+3; [[email protected] mytest]# echo $a; 23,export //查看所有环境变量 24,echo $PATH //查看单个变量 25,cmp file1 file2 //文件内容比对 26,clear //清屏 27,echo 23423 |awk --re-interval '/[0-9]{3,}/' //如果不加re-interval的话,不显示 28,cal //得到一个整齐的日历格式 29,wc -l //统计行数,wc -w 统计单词 30,echo "AaDCbd23" |tr "[A-Z]" "[a-z]" 大写变小写,echo "AaDCbdc23" |tr -c b-d = 将b-d之外的字符串替换成= 31,echo "ADSF" | iconv -f UTF8 -t GBK //把字符由utf8转成gbk -f是from和简写,-t好像terminal的简写 32,cat -n file //内容的前面会显示行号 33,chattr +i file //只读,root用户也没法对其进行修改 34,lsattr file //查看文件属性 35,cat /etc/passwd |awk -F: '{print $1}' //查看系统中所有用户 36,cat /etc/group //查看系统中所有的组 37,groups //查前当前用户所在的,所有组 38,usermod -g 组名 用户 //这种方式是覆盖的方式,用的时候要小心,如果用户A性于mysql usermod -g php mysql这样的话只 属于php了, 39,usermod -G 组名 用户 //这种方式是增加的方式,如果用户A性于mysql usermod -g php mysql这样的话,mysql就属于2个组了 40,bc //进入数学计算中去 41,umask 003 u权限是7,g权限是7,其他用户是4,也就是774,777-003=774 42,mkfs -t vfat /dev/hda6 //将移动硬盘里面的一个分区格式化成vfat格式 43,mount /dev/cdrom /media/cdrom //挂载cdrom 44,getent group 532 //通过组ID,来查找组信息 45,last //登录成功用户记录 46,lastb //登录不成功用户记录 47,dump -S /dev/sda2 //查看一下要备份/dev/sda2所要的容量 48,dump -0j -f /dev/hda2/sda2_bak.dump.bz2 /dev/sda2 //将sda2进行备份并压缩 49,restore -t -f /dev/hda2/sda2_bak.dump //查看备份信息 50,restore -r -f /dev/hda2/sda2_bak.dump //还原备份 51,fc-list //查看系统中安装的字体 52,find ./ -type f -exec grep -q "root" {} ; -exec echo {} ; //查找目录下文件所包涵的字符串 53,vmstat 5 //每5显示一下次系统信息,cpu,memory,i/o等 54,top 后 在shift + P 所占进程的排序显示 55,top 后 在shift + M 所占内存的排序显示 56,iptraf -g //查看各个接口的流量 57,ostat -d -x /dev/sda2 2 //用iostat查看磁盘/dev/sda2的磁盘i/o情况,每两秒刷新一次 58, paste -sd '|||n' test //文件的每4行转换成1行,并用|隔开。 59,lsof -i :22 //知道22端口现在运行什么程序 60,lsof -c abc //显示abc进程现在打开的文件 61,lsof -p 12 //看进程号为12的进程打开了哪些文件 63,route //查看路由信息 64,ifup //开启网卡 65,ifdown //关闭网卡 66,route del -net 172.168.0.0 netmask 255.255.0.0 dev eth0 //删除 172.168这个网段 67,route add -net 172.168.10.0 netmask 255.255.255.0 dev eth0 //增加一个路由 68,netstat -tunl //列出监听的网络服务端口 69,netstat -tun //列出已连接的网络服务端口 70,nmap -sP 172.30.4.0/24 //在这个网段内有多少用户在我的主机上操作,一个不错的安全检查工具 71,vgdisplay //查看系统中的可用空间 72,lvextend -L+20G /dev/tank/part1 //向part1这个分区增加20G的空间 73,lvresize -L-10G /dev/tank/part2 //向part2这个分区减少10G的空间 74,pvdisplay //查看磁盘信息 75,mplayer -loop 10 /mnt/song/music/花儿开了.mp3 //循环播放10遍 76,pacman -S firefox -nd //nd去掉依赖 77,wget -c //断点下载 78,chroot /mnt/ubuntu //改变根目录到/mnt/ubuntu 79,ctrl+a //命令行下,光标称动到开头 80,ctrl+e //命令行下,光标移动结尾 81,cut -d: -f 1-4 test //用:分割文件,取分割后的1-4列 82,file /home/zhangy/test.php //用于查看文件的一些基本信息 83,touch test.txt //创建一个空文件 text.txt 84,htpasswd -cbd /usr/local/nginx/conf/authfile //创建访问控制文件 85,df //查看磁盘空间,和当前的磁盘数 86,fdisk -l //查看所有磁盘数 87,alsamixer //进入后,m键可以实现静音 88,killall httpd //把所有httpd进程杀掉 89,killall -9 mysqld_safe //有些进程超级用户也停止不了,-9是强制删除 90,mirror /mysql //下载mysql目录 91,mirror -R /mysql //上传mysql目录 92,rmmod pcspkr //关掉tab提示音 93,modprobe pcspkr //开启tab提示音 94,gpasswd -a zhangy wheel //将zhangy这个用户添加到wheel这个组 95,dd if=/dev/zero of=/virtual/ubuntu.virt.img bs=1M count=4096 //创建一个4G的IMG镜像 96,lspic //显示pci设备 97,lsusb //显示usb设备 98,history | less //less根more有点像,感觉less用着更舒服点 99,ln -s //如果忘了-s就变成硬链接了 100,

如何在solaris中添加删除磁盘和分区建意你先看 IDE 和 SCSI 分配名称 以下例子是格式化 Primary IDE Master 硬盘 查看 IDE 和 SCSI 分配名称后,我们知道 Primary IDE Master 硬盘名称是c0d0。 请先行 Login 成为 root user # drvconfig ( configure the /devices directory ) # disks ( creates /dev entries for hard disks attached to the system ) # format Searching for disks...done AVAILABLE DISK SELECTIONS: 0. c0d0 /[email protected],0/[email protected],1/[email protected]/[email protected],0 1. c1t6d0 /[email protected],0/pci9004,[email protected]/[email protected],0 Specify disk (enter its number): 0 ( 因为 Primary IDE Master 硬盘名称是c0d0,所以选择 0 ) AVAILABLE DRIVE TYPES: 0. other Specify disk type (enter its number):0 ( 正常应该是 0. DEFAULT 1. other,通常应该选择DEFAULT,但是Solaris不明白我的硬盘是什么,所 以只有other可供选择。) 我的IDE HardDisk架构如下:- ( 可以从BIOS Auto Detect查出來,通常都有LBA,LARGE,AUTO三种选择,建意你使用Auto,因為不能大 过16Heads和不能大过63Sectoes ) Cylinders = 25232 Heads = 16 Sectors = 63 Enter number of data cylinders:25232 Enter number of alternate cylinders[2]: Enter number of physical cylinders[25234]: Enter number of heads: 16 Enter number of data sectors/track: 63 Enter rpm of drive[3600]: Enter format time[default]: Enter cylinder skew[default]: Enter track skew[default]: Enter tracks per zone[default]: Enter alternate tracks[default]: Enter alternate sectors[default]: Enter cache control[default]: Enter prefetch threshold[default]: Enter minimum prefetch[default]: Enter maximum prefetch[default]: Enter disk type name (remember quotes): cyl 25232 alt 2 hd 16 sec 63 selecting c0d0 No current partition list No defect list found [disk formatted, no defect list found] FORMAT MENU: disk - select a disk type - select (define) a disk type partition - select (define) a partition table current - describe the current disk format - format and analyze the disk fdisk - run the fdisk program repair - repair a defective sector show - translate a disk address label - write label to the disk analyze - surface analysis defect - defect list management backup - search for backup labels verify - read and display labels save - save new disk/partition definitions volname - set 8-character volume name ! - execute , then return quit format>fdisk No fdisk table exists. The default partition for the disk is: a 100% "SOLARIS System" partition Type "y" to accept the default partition, otherwise type "n" to edit the partition table. y WARNING: Solaris fdisk partition changed - Please relabel the disk format>fdisk Total disk size is 25232 cylinders Cylinder size is 1008 (512 byte) blocks Cylinders Partition Status Type Start End Length % ========= ====== ============ ===== === ====== === WARNING: no partitions are defined! SELECT ONE OF THE FOLLOWING: 1. Create a partition 2. Specify the active partition 3. Delete a partition 4. Exit (update disk configuration and exit) 5. Cancel (exit without updating disk configuration) Enter Selection: 1 Select the partition type to create: 1=SOLARIS 2=UNIX 3=PCIXOS 4=Other 5=DOS12 6=DOS16 7=DOSEXT 8=DOSBIG 9=DOS16LBA A=x86 Boot B=Diagnostic C=FAT32 D=FAT32LBA E=DOSEXTLBA 0=Exit? 1 Specify the percentage of disk to use for this partition (or type "c" to specify the size in cylinders). 100 Should this become the active partition? If yes, it will be activated each time the computer is reset or turned on. Please type "y" or "n". n Total disk size is 25232 cylinders Cylinder size is 1008 (512 byte) blocks Cylinders Partition Status Type StartEnd Length % ========= ====== ============ ======== ====== === 1Solaris1 2523125231 100 WARNING: no partitions are defined! SELECT ONE OF THE FOLLOWING: 1. Create a partition 2. Specify the active partition 3. Delete a partition 4. Exit (update disk configuration and exit) 5. Cancel (exit without updating disk configuration) Enter Selection: 4 WARNING: Solaris fdisk partition changed - Please relabel the disk format> partition PARTITION MENU: 0 - change `0' partition 1 - change `1' partition 2 - change `2' partition 3 - change `3' partition 4 - change `4' partition 5 - change `5' partition 6 - change `6' partition 7 - change `7' partition select - select a predefined table modify - modify a predefined partition table name - name the current table print - display the current table label - write partition map and label to the disk ! - execute , then return quit partition> print Current partition table (cyl): Total disk cylinders available: 25229 + 2 (reserved cylinders) Part Tag Flag Cylinders Size Blocks 0 root wm 0 0 (0/0/0) 0 1 swap wu 0 0 (0/0/0) 0 2 backup wu 0 - 25228 12.13GB (25229/0/0) 25430832 3 unassigned wm 0 0 (0/0/0) 0 4 unassigned wm 0 0 (0/0/0) 0 5 unassigned wm 0 0 (0/0/0) 0 6 usr wm 0 0 (0/0/0) 0 7 unassigned wm 0 0 (0/0/0) 0 8 boot wu 0 - 0 0.49MB (1/0/0) 1008 9 alternates wm 1 - 2 0.98MB (2/0/0) partition> 0 ( Part 2, 8, 9 是不需要进行任何修改) Part Tag Flag Cylinders Size Blocks 0 root wm 0 0 (0/0/0) 0 Enter partition id tag[root]: ( 只可使用 unassigned, boot, root, swap, usr, backup, stand, var, home, alternates ) Enter partition permission flags[wm]: ( wm - read-write, mountable,wu - read-write, unmountable,rm - read-only, mountable,ru - read-only, unmountable ) Enter new starting cyl[0]: 3 ( 從 Part 8 - 9 可以看到Cylinders 0 - 2 已经给系统使用,所以要 由 3 开始 ) Enter partition size[0b, 0c, 0.00mb, 0.00gb]: ? Expecting up to 25427808 blocks, 25226 cylinders, 12415.92 megabytes, or 12.12 gigabytes Enter partition size[0b, 0c, 0.00mb, 0.00gb]: 25427808b partition> print Current partition table (cyl): Total disk cylinders available: 25229 + 2 (reserved cylinders) Part Tag Flag Cylinders Size Blocks 0 root wm 3 - 25228 12.13GB (25226/0/0) 25427808 1 swap wu 0 0 (0/0/0) 0 2 backup wu 0 - 25228 12.13GB (25229/0/0) 25430832 3 unassigned wm 0 0 (0/0/0) 0 4 unassigned wm 0 0 (0/0/0) 0 5 unassigned wm 0 0 (0/0/0) 0 6 usr wm 0 0 (0/0/0) 0 7 unassigned wm 0 0 (0/0/0) 0 8 boot wu 0 - 0 0.49MB (1/0/0) 1008 9 alternates wm 1 - 2 0.98MB (2/0/0) partition> label Ready to label disk, continue? y partition> quit format> label ( 为了保险所以输入多一次label ) Ready to label disk, continue? y format> quit # newfs /dev/rdsk/c0d0s0 ( c0d0 是硬盘的名称,可参考IDE 和 SCSI 分配名称。s0 是 Part 0。 newfs: construct a new file system /dev/rdsk/c0d0s0: (y/n)? y /dev/rdsk/c0d0s0: 25427808 sectors in 25226 cylinders of 16 tracks, 63 sectors 12415.9MB in 287 cyl groups (88 c/g, 43.31MB/g, 5504 i/g) super-block backups (for fsck -F ufs -o b=#) at: 32, 88800, 177568, 266336, 355104, 443872, 532640, 621408, 710176, 798944, 887712, 976480, 1065248, 1154016, 1242784, 1331552, 1419296, 1508064, 1596832, 1685600, 1774368, 1863136, 1951904, 2040672, 2129440, 2218208, 2306976, 2395744, 2484512, 2573280, 2662048, 2750816, 2838560, 2927328, 3016096, 3104864, 3193632, 3282400, 3371168, 3459936, 3548704, 3637472, 3726240, 3815008, 3903776, 3992544, 4081312, 4170080, 4257824, 4346592, 4435360, 4524128, 4612896, 4701664, 4790432, 4879200, 4967968, 5056736, 5145504, 5234272, 5323040, 5411808, 5500576, 5589344, 5677088, 5765856, 5854624, 5943392, 6032160, 6120928, 6209696, 6298464, 6387232, 6476000, 6564768, 6653536, 6742304, 6831072, 6919840, 7008608, 7096352, 7185120, 7273888, 7362656, 7451424, 7540192, 7628960, 7717728, 7806496, 7895264, 7984032, 8072800, 8161568, 8250336, 8339104, 8427872, 8515616, 8604384, 8693152, 8781920, 8870688, 8959456, 9048224, 9136992, 9225760, 9314528, 9403296, 9492064, 9580832, 9669600, 9758368, 9847136, 9934880, 10023648, 10112416, 10201184, 10289952, 10378720, 10467488, 10556256, 10645024, 10733792, 10822560, 10911328, 11000096, 11088864, 11177632, 11266400, 11354144, 11442912, 11531680, 11620448, 11709216, 11797984, 11886752, 11975520, 12064288, 12153056, 12241824, 12330592, 12419360, 12508128, 12596896, 12685664, 12773408, 12862176, 12950944, 13039712, 13128480, 13217248, 13306016, 13394784, 13483552, 13572320, 13661088, 13749856, 13838624, 13927392, 14016160, 14104928, 14192672, 14281440, 14370208, 14458976, 14547744, 14636512, 14725280, 14814048, 14902816, 14991584, 15080352, 15169120, 15257888, 15346656, 15435424, 15524192, 15611936, 15700704, 15789472, 15878240, 15967008, 16055776, 16144544, 16233312, 16322080, 16410848, 16499616, 16588384, 16677152, 16765920, 16854688, 16943456, 17031200, 17119968, 17208736, 17297504, 17386272, 17475040, 17563808, 17652576, 17741344, 17830112, 17918880, 18007648, 18096416, 18185184, 18273952, 18362720, 18450464, 18539232, 18628000, 18716768, 18805536, 18894304, 18983072, 19071840, 19160608, 19249376, 19338144, 19426912, 19515680, 19604448, 19693216, 19781984, 19869728, 19958496, 20047264, 20136032, 20224800, 20313568, 20402336, 20491104, 20579872, 20668640, 20757408, 20846176, 20934944, 21023712, 21112480, 21201248, 21288992, 21377760, 21466528, 21555296, 21644064, 21732832, 21821600, 21910368, 21999136, 22087904, 22176672, 22265440, 22354208, 22442976, 22531744, 22620512, 22708256, 22797024, 22885792, 22974560, 23063328, 23152096, 23240864, 23329632, 23418400, 23507168, 23595936, 23684704, 23773472, 23862240, 23951008, 24039776, 24127520, 24216288, 24305056, 24393824, 24482592, 24571360, 24660128, 24748896, 24837664, 24926432,25015200, 25103968, 25192736, 25281504, 25370272, 现在打算把 /dev/rdsk/c0d0s0 mount 在 /mnt/newhd # cd /mnt # mkdir newhd 在 /etc/vfstab Auto mount 的设定 device to mount = /dev/dsk/c0d0s0 device to fsck = /dev/rdsk/c0d0s0 mount point = /mnt/newhd FS type = ufs fsck pass = 1 mount at boot = yes mount options = - # pico vfstab or vi vfstab 加入 /dev/dsk/c0d0s0 /dev/rdsk/c0d0s0 /mnt/newhd ufs 1 yes - # mount /mnt/newhd 完成 ! Good luck!

一、约定1、网关上已经对下面所带的机器作了绑定。网关IP:192.168.1.1 MAC:00:02:B3:38:08:622、要进行绑定的Linux主机IP:192.168.1.2 MAC:00:04:61:9A:8D:B2二、绑定步骤1、先使用arp和arp -a查看一下当前ARP缓存列表[[email protected] ~]# arpAddress                HWtype   HWaddress           Flags Mask          Iface192.168.1.234          ether 00:04:61:AE:11:2B C                   eth0192.168.1.145          ether 00:13:20:E9:11:04 C                   eth0192.168.1.1              ether 00:02:B3:38:08:62 C                   eth0说明:Address:主机的IP地址Hwtype:主机的硬件类型Hwaddress:主机的硬件地址Flags Mask:记录标志,“C“表示arp高速缓存中的条目,“M“表示静态的arp条目。[[email protected] ~]# arp -a? (192.168.1.234) at 00:04:61:AE:11:2B [ether] on eth0? (192.168.1.1) at 00:16:76:22:23:86 [ether] on eth02、新建一个静态的mac--〉ip对应表文件:ip-mac,将要绑定的IP和MAC地下写入此文件,格式为 ip mac。[[email protected] ~]# echo ’192.168.1.1 00:02:B3:38:08:62 ’ 〉 /etc/ip-mac[[email protected] ~]# more /etc/ip-mac192.168.1.1 00:02:B3:38:08:623、设置开机自动绑定[[email protected] ~]# echo ’arp -f /etc/ip-mac ’ 〉〉 /etc/rc.d/rc.local4、手动执行一下绑定[[email protected] ~]# arp -f /etc/ip-mac5、确认绑定是否成功[[email protected] ~]# arpAddress                HWtype   HWaddress           Flags Mask          Iface192.168.0.205          ether 00:02:B3:A7:85:48 C                   eth0192.168.1.234          ether 00:04:61:AE:11:2B C                   eth0192.168.1.1              ether 00:02:B3:38:08:62 CM                    eth0[[email protected] ~]# arp -a? (192.168.0.205) at 00:02:B3:A7:85:48 [ether] on eth0? (192.168.1.234) at 00:04:61:AE:11:2B [ether] on eth0? (192.168.1.1) at 00:02:B3:38:08:62 [ether] PERM on eth0从绑定前后的ARP缓存列表中,可以看到网关(192.168.1.1)的记录标志已经改变,说明绑定成功。三、添加信任的Windows主机(192.168.1.10)1、Linux主机(192.168.1.2)上操作[[email protected] ~]# echo ’192.168.1.10 00:04:61:AE:09:14’ 〉〉 /etc/ip-mac[[email protected] ~]# arp -f /etc/ip-mac2、Windows主机(192.168.1.10)上操作1)清除ARP缓存C:\Documents and Settings\Administrator〉arp -d2)绑定Linux主机的IP和MAC地址C:\Documents and Settings\Administrator〉arp -s 192.168.1.2 00-04-61-9A-8D-B2你可以将上面2个步骤写在一个BAT(批处理)文件中,这样做的好处是,今后如果要增加其它机器的绑定,只需维护这个文件就可以了。例:@echo off arp -d arp -s 192.168.1.2 00-04-61-9A-8D-B2exit 注意:Linux和Widows上的MAC地址格式不同。Linux表示为:AA:AA:AA:AA:AA:AA,Windows表示为:AA-AA-AA-AA-AA-AA。

分类:网页制作

时间:2016-02-22 04:16:17