Solaris10常用命令-例子

更新时间:2024-03-29 18:27:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Solaris常用命令和例子

1)

ok>probe-ide //Ultra5/10、Blade100/150 ok>probe-scsi-all //Ultra60、E450、V480

ok probe-scsi-all

/pci@1f,4000/scsi@3,1

/pci@1f,4000/scsi@3 Target 0

Unit 0 Disk QUANTUM VK4550J SUN4.2G8817 Target 6

Unit 0 Removable Read Only device TOSHIBA 2395 XM5701TASUN12XCD fsck 例: ok boot

Boot path: /ssm@0,0/pci@1c,700000/pci@1/SUNW,isptwo@4/sd@0,0:a Boot args: -s Loading ufs-file-system package 1.4 04 Aug 1995 13:02:54. FCode UFS Reader 1.11 97/07/10 16:19:15. Loading: /platform/SUNW,Sun-Fire/ufsboot Loading: /platform/sun4u/ufsboot

SunOS Release 5.8 Version Generic_110096-04 64-bit

Copyright 1983-2000 Sun Microsystems, Inc. All rights reserved. WARNING: todsg_get(): TOD SRAM magic error WARNING: todsg_get(): turned off using tod configuring IPv4 interfaces: hme1. Hostname: qame-a

The / file system (/dev/rdsk/c4t0d0s0) is being checked.

/dev/rdsk/c4t0d0s0: INCORRECT BLOCK COUNT I=50905 (4 should be 0) (CORRECTED) /dev/rdsk/c4t0d0s0: INCORRECT BLOCK COUNT I=50906 (2 should be 0) (CORRECTED) /dev/rdsk/c4t0d0s0: INCORRECT BLOCK COUNT I=50907 (2 should be 0) (CORRECTED) /dev/rdsk/c4t0d0s0: INCORRECT BLOCK COUNT I=539350 (18 should be 0) (CORRECTED) /dev/rdsk/c4t0d0s0: INCORRECT BLOCK COUNT I=539351 (2 should be 0) (CORRECTED) /dev/rdsk/c4t0d0s0: INCORRECT BLOCK COUNT I=753040 (2 should be 0) (CORRECTED) /dev/rdsk/c4t0d0s0: INCORRECT BLOCK COUNT I=804088 (2 should be 0) (CORRECTED) /dev/rdsk/c4t0d0s0: INCORRECT BLOCK COUNT I=881943 (2 should be 0) (CORRECTED) /dev/rdsk/c4t0d0s0: INCORRECT BLOCK COUNT I=881944 (2 should be 0) (CORRECTED) /dev/rdsk/c4t0d0s0: INCORRECT BLOCK COUNT I=885317 (6 should be 0) (CORRECTED) /dev/rdsk/c4t0d0s0: 7499747 DUP I=885355

/dev/rdsk/c4t0d0s0: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.

WARNING - Unable to repair the / filesystem. Run fsck

manually (fsck -F ufs /dev/rdsk/c4t0d0s0). Exit the shell when done to continue the boot process.

Type control-d to proceed with normal startup, (or give root password for system maintenance): #fsck –y

ok boot cdrom –s

#fsck –y /dev/rdsk/c0t0d0s0

2)

终端控制

ctrl+s :终止屏幕输出,如用cat命令输出时,要停一下 ctrl+q :恢复ctrl+q的输出

ctrl+c :中断当前的活动,返回命令提示符

ctrl+d :表示文件的结束或退出,如退出终端窗口 ctrl+u :擦除整个命令行

ctrl+w :擦除命令行最后一个单词 ctrl+h :擦除命令行最后一个字符 3)

# uname –a //查看操作系统版本以及内核版本 SunOS 5.7 Generic_106541-19 sun4u sparc sun4u

SunOS:

OS5.5.1=solaris2.5.1 OS5.6=solaris2.6 OS5.7=solaris7 OS5.8=solaris8

Unix kernel:

32 bit SPARC - /platform/sun4u/kernel/unix

64 bit SPARC - /platform/sun4u/kernel/sparcv9/unix intel - /platform/i86pc/kernel/unix 4)

# date

# date mmddHHMM[[cc]yy][.SS] # date

2003年10月12日 星期日 10时04分16秒 CST (CST是Chinese Standard Time的缩写) # date 10121003 设置时间为10月12日10时03分

5)

#stings

#stings /usr/bin/cat

能够用来打印可执行文件或二进制文件中的可读字符。 6)

常用文本文件的命令

#cat -n test.txt //显示行号

#more test.txt | more 键值 目的

空格 滚动到下一屏 回车 一次滚动一行 b 向后移动一屏 f 向前移动一屏

h 显示更多特性的帮助菜单 q 退出,返回shell提示符 /string 向前搜索字符串string n 查找下一处匹配

head

#head -5 /export/home/wing/test.txt //显示开始的5行

#head chap*|more //显示所有以chap开头的文件的头部

用来显示一个或多个文件的前n行,默认省略-n参数将显示文件的前10行。 tail

#tail -5 /export/home/wing/test.txt //显示最后5行

#tail +5 /export/home/wing/test.txt //显示第5行开始到结束

用来显示一个文件的最后n行,默认省略-n参数将显示文件的最后10行。

# tail -f /var/adm/messages //实时自动浏览syslog入口

Oct 6 00:20:26 wing genunix: [ID 936769 kern.info] sd0 is /pci@0,0/pci-ide@7,1/ide@1/sd@0,0 Oct 6 00:20:26 wing pcplusmp: [ID 637496 kern.info] pcplusmp: fdc (fdc) instance 0 vector 0x6 ioapi

c 0x1 intin 0x6 is bound to cpu 0

Oct 6 00:20:26 wing last message repeated 1 time

Oct 6 00:20:26 wing isa: [ID 202937 kern.info] ISA-device: fdc0 Oct 6 00:20:26 wing fdc: [ID 114370 kern.info] fd0 at fdc0

Oct 6 00:20:26 wing genunix: [ID 936769 kern.info] fd0 is /isa/fdc@1,3f0/fd@0,0

Oct 6 00:20:30 wing i8042: [ID 526150 kern.info] 8042 device: mouse@1, mouse8042 # 0 Oct 6 00:20:30 wing genunix: [ID 936769 kern.info] mouse80420 is /isa/i8042@1,60/mouse@1 Oct 6 00:21:37 wing login: [ID 722452 auth.error] user2netname: (nis+ lookup): Error in accessin

g N

IS+ cold start file... is NIS+ installed?

Oct 6 00:21:47 wing last message repeated 1 time

Oct 6 00:52:07 wing login: [ID 722452 auth.error] user2netname: (nis+ lookup): Error in accessing N

IS+ cold start file... is NIS+ installed? wc

#wc /export/home/wing/test.txt //显示文件的行、单词、字节数

#wc -l /export/home/wing/test.txt //显示文件的行数

选项 功能 -l 统计行数 -w 统计单词数 -c 统计字节数 -m 统计字符数 diff

#diff -i test.txt test2.txt //忽略文章中的大小写

#diff -c test.txt test2.txt //进行细致的比较生成一个差别表

8)常用文件和文件夹操作命令: touch

#touch test1.txt test2.txt test3.txt //可以一次创建多个文件

mkdir

#mkdir /export/home/wing

#mkdir -p /export/home/wing //在路径中名中不存在的目录将被创建 #rmdir dir //所要删除的目录必须是空的 rm

rm -i test.txt test2.txt //交互式删除文件

rm -r /tem/testd //删除目录和目录下的文件

rm -ir /tem/testd //交互式的删除目录和目录下的文件 cp

cp -i oldfilename newfilename //交互式拷贝

cp /export/home/keven/ok.txt /export/home/wing/test.txt

cp -ri /export/home/keven /export/home/wing 整个目录一起拷 cp -rp 文件属性一起拷贝

ls $ ls -n 总数 12

-rw-r--r-- 1 0 1 247 10月 2 07:53 list

-rw-r--r-- 2 1002 100 62 10月 2 01:10 ok.txt drwxr-xr-x 2 0 1 512 10月 1 21:27 ss

-rw-r--r-- 1 1002 100 171 10月 3 01:10 test.txt -rw-r--r-- 1 1002 100 120 10月 2 20:54 test1 -rw-r--r-- 1 1002 100 0 9月 30 08:54 test2 -rw-r--r-- 1 1002 100 0 9月 30 08:54 test3 -rw-r--r-- 1 0 1 247 10月 2 07:58 tt.txt

# ls -ld using_samba //查看目录的权限

drwxr-xr-x 2 root other 512 5月 8 22:23 using_samba

$ ls -a

. .cshrc list ss test1 test3 .. .login ok.txt test.txt test2 tt.txt

$ ls -l 总数 12

-rw-r--r-- 1 root other 247 10月 2 07:53 list -rw-r--r-- 2 keven user 62 10月 2 01:10 ok.txt drwxr-xr-x 2 root other 512 10月 1 21:27 ss -rw-r--r-- 1 keven user 171 10月 3 01:10 test.txt -rw-r--r-- 1 keven user 120 10月 2 20:54 test1 -rw-r--r-- 1 keven user 0 9月 30 08:54 test2 -rw-r--r-- 1 keven user 0 9月 30 08:54 test3 -rw-r--r-- 1 root other 247 10月 2 07:58 tt.txt

$ ls -F //列出目录名

TT_DB/ keven/ temp/ user2/ www/ cole/ lost+found/ user1/ wing/

符号 文件类型 / 文件夹

* 可执行文件

(none) 无格式文件或者ASCII文件 @ 链接符

如:

# ls -F

accept* gsscred* metaset* i86/ //目录 acctadm* halt* metastat* roleadd*

add_drv* hostconfig* metasync* test.txt //ASCII cachefslog@ in.rlogind* mount* rtquery*

cachefswssize@链接文件 in.routed* mountall* rwall*//可执行文件

$ ls -R //递归显示 .:

TT_DB keven temp user2 www cole lost+found user1 wing

./cole:

inetservices.txt services services.txt

./keven:

dir test.txt

./keven/dir:

./lost+found:

./lost+found: 权限被否定

./temp: so.tar.gz

./user1:

./user2:

./wing:

aa dead.letter mywife.tar ok passwd.txt test

./wing/test:

./www: $

$ ls . //显示当前目录 dir test.txt

$ ls .. //显示当前目录的父目录,支持路径表示符如~

TT_DB keven temp user2 www cole lost+found user1 wing $ ls -i test.txt test1.txt //节点检查 64 test.txt 65 test1.txt

$ ls -il test.txt test1.txt

64 -rw-r--r-- 1 keven sysadmin 27 10月 12 17:27 test.txt 65 -rw-r--r-- 1 keven sysadmin 0 10月 12 17:25 test1.txt $ ls -ld //只显示目录

drwxr-xr-x 3 keven sysadmin 512 10月 12 17:25 . file

$ file passwd.txt

passwd.txt: ascii文本 lp

$lp ok.txt myfile test.txt

$lp -p evans1 test.txt //-p后为打印机evans1 $lpstat // 打印队列状态 ln

#ln file1 newfile

#ln file1 directory/newfilename 硬链接 #ln ~/book/chap* /home/brad

为每个chap文件都创建了链接,把这些链接指向/home/brad目录 如果文件有多个指向它的硬盘链接,只是删除该文件并不能有效的释放磁盘空间,你将不得不删除掉所有指向它的硬链接。

#ln -s src target

是软链接,存储的只是路径,用ls -l 可以看到,如果原文件已移走或删除,该名,则target就没有用了,删除和该名链接同样用rm

如果文件有多个指向它的硬盘链接,只是删除该文件并不能有效的释放磁盘空间,你将不得不删除掉所有指向它的硬链接。

# ln -s /export/home/ddd /var 既把/export/home/ddd目录链接到/var下面 在var下面生成ddd 链接符号。当/var满了是时候用 mv

#mv oldfilename newfilename 改名文件或文件夹

#mv source_file(s) target_directory 移动文件到其它目录

find

#find . -name test.txt //搜索当前目录 #find dir -name test.txt #find / -name test.txt

#find /export/home -name test.txt

#find ~ -name ‘*tif’ //用户的主目录

#find /export -name core -exec rm {} \\ //搜索core文件并删除它们 #find dir -type d //文件类型

#find /export -type d -name test //文件夹名为test

#find /export -size +400 //文件大于400块的512byte =1 blocks #find /export -name test.txt -exec rm {} \\; //查找并删除 #find /export -name test.txt -ok rm {} \\; //交互模式删除 y #find /export -user keven //按用户查找

#find / -user UID -exec rm{} \\; //查找该用户的文件并删除 #find / -name pfile -print>find.txt 2>null.txt&

//找到则放入find.txt,否则就放到null.txt 程序在后台运行

# find /export -name tex.txt -exec rm {} \\; //{} \\中间有一个空格 $ find ~ -name ’*es’ //es的前面为任意字符

搜索表达式 意义 定义

name filename 文件名 搜索所有匹配的给定的文件,可以接受元字符(如? *) type filetype 文件类型 搜索匹配给定文件类型的文件(d为目录)

mtime [+|-]n 修改的时间 搜索所有修改时间或者大于,或小于给定时间的文件 atime[+|-]n 访问的时间 搜索所有访问时间或者大于,或者小于给定时间的文件

user loginid -group groupid 用户ID和属组ID 搜索所有匹配登陆ID的所有者或属组ID的文件

perm mode 权限 搜索所有匹配给定权限的文件(只允许八进制模式)

size[+|-]n[c] 搜索所有大小或者大于,小于n的文件,n以512字节每块计算,如果后面有ac,则以字符(字节)计算

-print 基将搜索结果输出到标准输出。该结果是一个全路径名的文件名 列表

-exec command{}\\; exec选项必须通过\\;来终止;这样使得find命令可以应用于指定命令中搜索准则中给出的每个文件

-ok command{}\\; -exec的交互格式.这个选项用于要求来自用户的输入命令.如 rm -i

-ls 使用长列表格式打印当前路径.这个表达式最常用于链接一个输出,把它重定向到一个文件中,以便稍后进行检查 grep

#grep root /etc/passwd //在passwd中查找root #grep -i root /etc/passwd //忽略大小写

#grep -v root /etc/passwd //显示除了含有root的行 # grep -c root group //统计有多少行

10

# grep -l root passwd group hosts //查找文件中包含root的文件 passwd group

正则表达式 功能 例子 结果

.(dot) 匹配任意字符可以多次使用,类似ls命令 grep chap.. file 显示所有包含chap,且之后还有两个字符的行

*(asterisk) 在模式上匹配0个或多个字符 grep chap* file 显示所有包含chap,且之后可以是任意字符

\\(back slash) 告诉shell按照字面意思理解\\之后的特殊字符 grep dollar\\* file 显示所有包含dollar*的行./告诉shell按照字面意思理解*,而不是通配符

^ (caret) 匹配所有以指定模式打头的所有行 grep ^name file 显示所有以Name开头的行 $ 匹配所有以指定模式结尾的行 grep $800 file 显示所有以800结尾的行 [] 匹配模式中的一个字符 grep [64.128] 显示所有包含64MB或128MB的行 -i 忽略大小写

-v 反包含.除了该字符串之外的行 sort

#cat test.txt oggg aaa ddkk ddgfg kk 11 34 22

#sort test.txt 11 22 34 aaa ddgfg ddkk kk oggg

# ls -ld t* >list # cat list

-rw-r--r-- 1 keven user 32 10月 2 07:51 test.txt -rw-r--r-- 1 keven user 0 9月 30 08:54 test1 -rw-r--r-- 1 keven user 0 9月 30 08:54 test2 -rw-r--r-- 1 keven user 0 9月 30 08:54 test3 # sort -rn +4 list -o tt.txt //翻转排序 头4个字符

# ls

list ok.txt ss test.txt test1 test2 test3 tt.txt # cat tt.txt

-rw-r--r-- 1 keven user 32 10月 2 07:51 test.txt -rw-r--r-- 1 keven user 0 9月 30 08:54 test3 -rw-r--r-- 1 keven user 0 9月 30 08:54 test2 -rw-r--r-- 1 keven user 0 9月 30 08:54 test1 #sort +5M +6n list -o up.txt

选项 描述

-n 进行数字排序,n可以单独和短横线连接,或者可以跟着一个区域参数 (+|-)n 以第n个分隔符的区域开始或结束。默认的分割符是空格

-r 翻转排序的顺序。r可以单独与短横线连用,或者可以跟着一个区域参数 -f 在排列中忽略大小写

+nM 把开始的三个字符做为月份名称的简写来排序

-d 使用字典排序,只用字母和空格排序,其它的符号忽略 -o filename 把所有输出放到文件名中 vi

vi(文本输入模式) 命令 功能

a 在光标后追加文本 A 在行末追加文本 i 在光标前追加文本

o 在光标下插入新的一行 vi(末行模式) 命令 功能

:w 写缓冲区,保存更改继续在vi中工作 :w new_filename 把缓冲区写如new_filename :wq 或 ZZ 写缓冲区,保存修改,然后退出vi :q! 不保存修改而退出

:wq! 写缓冲区保存修改然后推出vi,如果你是文件的所有者将忽略只读属性 e! 取消自上次保存以来所做的修改 :x 等价于:wq! wq

u 取消最近的一次编辑

vi(命令模式) 命令 功能

j(或向下箭头) 向下移动一行 k(或向上箭头) 向上移动一行 h(或向左箭头) 向后移动一个字符 l(或向右箭头) 向前移动一个字符 空格 向右移动一个字符

w 向前移动一个单词(包括标点)

b 向后移动一个单词(包括标点) $ 移动到行末

0(零)或 ^ 移动到行首 回车 移动到下一行首

vi(命令模式和末行模式) 命令 功能

x (小写) 删除光标处字符 dw 删除单词

3dw 删除三个单词 dd 删除光标所在的行 3dd 删除三行

yy 拉出一行拷贝,放到剪贴板中 p(小写) 把拉出行放到当前之下 P(大写) 把拉出行放到当前之上 :set nu 显示行号 :set nonu 隐藏行号

:set showmode 显示当前操作模式(如用vedit将自动打开) :set noshowmode 关闭模式显示 :set 显示所有vi变量

:set all 显示所有可能的vi变量和它们的当前的值 G 到达文件的最后一行 :21 到达第21行

/string 向前搜索字符串string ?string 向后搜索字符串string n 查找匹配的下一个字符串

df -k # df -k

Filesystem kbytes used avail capacity Mounted on /dev/dsk/c0d0s0 63127 36137 20678 64% /

/dev/dsk/c0d0s6 1201014 768820 372144 68% /usr /proc 0 0 0 0% /proc

mnttab 0 0 0 0% /etc/mnttab fd 0 0 0 0% /dev/fd

/dev/dsk/c0d0s3 55047 25063 24480 51% /var swap 608948 24 608924 1% /var/run swap 609216 292 608924 1% /tmp /dev/dsk/c0d0s5 24239 15 21801 1% /opt

/dev/dsk/c0d0s7 2691830 112 2637882 1% /export/home /dev/dsk/c0d0s1 462639 306816 109560 74% /usr/openwin

du -k

#du -k /export //递归显示文件夹中的文件或文件夹

# du -sk /etc 查看目录的使用情况 总树统计 # du -k /etc 逐个查看

# du -k /export | sort -n 可以迅速发现那个目录是最大的。 tar

# tar cvf backup.tar list ok.txt test.txt //备份生成backup.tar a list 1K a ok.txt 1K a test.txt 1K

#tar rvf backup.tar tt.txt //追加tt.txt到backu.tar中去

# tar cvf backup.tar tt.txt //注意会覆盖backup.tar原有的文件 a tt.txt 1K

# tar cvf /export/home/wing/mywife.tar ok2.txt ss // 备份到另一个目录 # tar xvf backup.tar //全部还原出来

# tar xvf backup.tar tt.txt //把指定的文件还原出来 tar: 块大小 = 4

x tt.txt, 290 bytes, 1 tape blocks

# tar tvf backup.tar //查看里面被压缩了的文件名,并没有解压出来 tar: 块大小 = 4

-rw-rw-rw- 1002/1 290 2003 10月 3 02:10 tt.txt

$tar uf myarch mydir //t a r将比较每个存档文件和用户目录中文件的最近更新时间,然后将任何自从上次存档以来所改变的文件拷贝到档案中

参数 说明

c 创建一个新的tar文件 t 列出tar文件的内容

x 从tar文件中解压出指定的文件

r 向已有的tar文件追加一个新文件进去 f 指定文件名 v 详细模式

m 将在从一个档案中抽取文件时,不要给它新的时戳

compress

# compress -v kk.txt mm.txt

kk.txt: 压缩:58.18% -- 用kk.txt.Z替换 //注意原来的文件将被.Z所替代 mm.txt: 压缩:1.33% -- 用mm.txt.Z替换 # ls

err.txt kk.txt.Z mm.txt.Z tt.txt

# uncompress -v ok2.txt.Z //解压缩,注意原来的.Z文件将被ok2.txt替代 # uncompress -c test1.Z|more //只是查看文件的内容,没有解压出来 zip

#zip winzip test1.txt test2.txt //生成winzip.zip文件 #unzip winzip.zip //解压缩

gzip

# gzip -v test2 test3

test2: 0.0% -- replaced with test2.gz//注意把原来的给替换了 test3: 0.0% -- replaced with test3.gz # ls

test2.gz test3.gz

gunzip

#gunzip test2.gz

gzcat

#gzcat tt.txt.gz

-rw-r--r-- 1 keven user 32 10月 2 07:51 test.txt -rw-r--r-- 1 keven user 0 9月 30 08:54 test3 -rw-r--r-- 1 keven user 0 9月 30 08:54 test2 -rw-r--r-- 1 keven user 0 9月 30 08:54 test1

9)常见系统查看命令: swap

# swap -s //列出一个系统虚拟交换空间的摘要。

total: 25728k bytes allocated + 6140k reserved = 31868k used,56496k available

# swap -l //列出系统物理交换空间的详细说明。 swapfile dev swaplo blocks free /dev/dsk/c0t3d0s1 32,28 8 98792 90384

vmstat //查看虚拟内存状态 # vmstat

kthr memory page disk faults cpu

r b w swap free re mf pi po fr de sr cd f0 s0 -- in sy cs us sy id

0 0 0 635012 40880 10 36 21 0 1 0 231 3 0 0 0 116 287 184 1 1 99

# vmstat -s 0 swap ins 0 swap outs

0 pages swapped in 0 pages swapped out

84899 total address trans. faults taken //地址解析错误 5916 page ins 6 page outs

12283 pages paged in 9 pages paged out 22759 total reclaims

22759 reclaims from free list 0 micro (hat) faults

84899 minor (as) faults //小错误 5186 major faults //主要错误

16092 copy-on-write faults //写复制操作错误 22331 zero fill page faults

539644 pages examined by the clock daemon 18 revolutions of the clock hand 570 pages freed by the clock daemon 550 forks 17 vforks 514 execs

431543 cpu context switches 272891 device interrupts 105553 traps

671500 system calls

97227 total name lookups (cache hits 96%) 1297 user cpu 1388 system cpu 230813 idle cpu 1542 wait cpu #

mpstat //系统负载cpu等信息 # mpstat 5 //每隔5秒刷新一次

CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl 0 32 2 0 114 68 181 5 0 1 0 263 0 1 1 98 0 2 0 0 101 55 160 1 0 0 0 58 0 0 0 100 0 0 0 0 101 55 164 1 0 0 0 70 0 0 0 100 0 0 0 0 99 52 158 1 0 0 0 48 0 0 0 100 0 22 0 0 102 56 164 1 0 0 0 136 0 0 0 100

who # who

root console 10月 2 19:23 (:0) (本地登陆)

wing pts/2 10月 2 19:22 (192.168.0.1)(远程登陆)

# who -q //登陆用户统计

root wing # users=2

# who -r //运行级别

. run-level 3 10月 2 19:20 3 0 S

$ who -Hu

NAME LINE TIME IDLE PID COMMENTS keven pts/2 10月 12 10:57 . 389 (192.168.0.1) user pts/3 10月 12 10:16 0:52 368 (192.168.0.1) PID为用户登陆上来的进程,#kill -9 368 把此用户踢出

$ who

root console 10月 3 19:21 (:0)

keven pts/6 10月 3 22:11 (192.168.0.1) wing pts/2 10月 3 22:11 (192.168.0.1) cole pts/3 10月 3 22:11 (192.168.0.1) w $w

下午11点01分 运行 3:43, 4 users, 平均负载:0.00, 0.00, 0.02 用户名 终端号 登入时间 闲置 JCPU PCPU 执行命令

root console 下午 7点21分 3:40 10 1 /usr/dt/bin/dtscreen -mode blank keven pts/6 下午10点11分 -csh wing pts/2 下午10点11分 5 w cole pts/3 下午10点11分 50 -ksh $ w keven

下午11点10分 运行 3:52, 4 users, 平均负载:0.00, 0.00, 0.02 用户名 终端号 登入时间 闲置 JCPU PCPU 执行命令 keven pts/6 下午10点11分 9 -csh

logins # logins

root 0 other 1 Super-User daemon 1 other 1 bin 2 bin 2 sys 3 sys 3

adm 4 adm 4 Admin

uucp 5 uucp 5 uucp Admin nuucp 9 nuucp 9 uucp Admin

smmsp 25 smmsp 25 SendMail Message Submission Program listen 37 adm 4 Network Admin lp 71 lp 8 Line Printer Admin

wing 1001 adm 4 my wife keven 1002 user 100 user1 1003 adm 4 user2 1004 adm 4 cole 1005 adm 4

nobody 60001 nobody 60001 Nobody

noaccess 60002 noaccess 60002 No Access User nobody4 65534 nogroup 65534 SunOS 4.x Nobody last

$ last //当前系统的使用历史使用模式

keven pts/2 192.168.0.1 Mon Oct 6 00:55 仍在登录状态 cole pts/6 192.168.0.1 Mon Oct 6 00:52 仍在登录状态 root console :0 Mon Oct 6 00:44 仍在登录状态 wing pts/3 192.168.0.1 Mon Oct 6 00:21 仍在登录状态 keven pts/2 192.168.0.1 Mon Oct 6 00:21 - 00:55 (00:34) reboot system boot Mon Oct 6 00:20

keven pts/2 192.168.0.1 Sun Oct 5 19:47 - 20:02 (00:14) reboot system boot Sun Oct 5 19:46

wing pts/1 192.168.0.1 Sun Oct 5 07:47 - 07:48 (00:00) keven pts/1 192.168.0.1 Sun Oct 5 06:24 - 07:47 (01:23) root console :0 Sun Oct 5 06:22 - 07:48 (01:25) keven pts/1 192.168.0.1 Sun Oct 5 06:21 - 06:24 (00:02) reboot system boot Sun Oct 5 06:21

cole pts/6 192.168.0.1 Sun Oct 5 01:58 - 03:09 (01:11) wing pts/5 192.168.0.1 Sun Oct 5 01:58 - 03:10 (01:11)

finger # finger

Login Name TTY Idle When Where root Super-User console Thu 19:23 :0

wing my wife pts/2 Thu 19:22 192.168.0.1 $ finger -s keven //指定查看的用户

Login Name TTY Idle When Where keven admin pts/6 11 Fri 22:11 192.168.0.1

$ finger @www //查看一台主机的登陆用户状况www为主机名 [www]

Login Name TTY Idle When Where root Super-User console 1 Fri 19:21 :0

keven admin pts/6 13 Fri 22:11 192.168.0.1 #finger -s username@hostname #finger @webserver.com

#finger username@webserver.com

$ finger -l keven //长格式显示

Login name: keven In real life: admin Directory: /export/home/keven Shell: /bin/ksh On since Oct 12 10:16:41 on pts/2 from 192.168.0.1 24 seconds Idle Time No unread mail No Plan.

# finger user1

Login name: user1 In real life:

Directory: /export/home/wing Shell: /bin/sh On since Oct 12 11:11:33 on pts/3 from 192.168.0.1 4 minutes 8 seconds Idle Time No unread mail No Plan.

$ finger -m //只搜索登陆的用户名 id # id

uid=0(root) gid=1(other) //为当前用户的ID,而不是原始登陆ID

who am i

# who am i //真实的UID root console Oct 2 19:23 (:0)

wing pts/2 Oct 2 19:41 (192.168.0.1)

用户和权限 chmod

#chmod u+r test.txt #chmod go+rw test.txt #chmod o-w test.txt #chmod 555 test.txt

#chmod +t dir //粘带位权限 #chmod g+s file.txt //setuid #chmod u+s file.txt //setgid

chown

#chown new_owner filename

#chown -R new_owner directoryname

chgrp

#chgrp new_group filename #chgrp -R new_group filename

groups

$ groups //显示自己所在的组 adm

$ groups root //显示该用户属于什么组

other root bin sys adm uucp mail tty lp nuucp daemon

useradd

#useradd user3

#useradd -u 1006 -g 4 -d /export/home/user3 -s /bin/sh -c “web user” user3 //完整的添加用户 #useradd -u 1006 -g 4 -d /export/home/user3 -m -s /bin/sh -c “web user” user3 //创建用户的同时创建主目录文件

参数 说明

-c 对每个用户的注释,记录每个用户的个人信息 -d 用户主目录路径

-m 用来创建用户的主目录,通常与-d路径名一起用 -g 用户的默认组 -g 用户的默认gid

-e 帐号不再有效,通常在创建临时帐号用

-f 许可用户的最大闲置天数,在创建临时帐号时用到 -u 用户的uid

-s 用户的shell路径

userdel

#userdel user7 //把user7删除,但是不删住目录 #userdel -r username //把主目录一起删除

usermod

# usermod -u 1005 -c adminisrator cole //修改用户的一些信息 #usermod -G group1 ,group2 username //把用户添加到多个组 # usermod -G sys,sysadmin cole

passwd

#passwd -f user //下次登陆时强制其改变密码 #passwd user //修改其密码

#passwd -l user //锁住用户不能登陆 #passwd -x 30 user //口令有效期为30天

#passwd -w 3 user //口令失效的前3天提醒用户修改

groupadd

# groupadd -g 2000 usergroup

groupdel

#groupdel groupname

groupmod

#groupmod -n newname oldname

#groupmod -g gid groupname //修改其gid #groupmod -g gid -n newname oldname

进程管理 ps

字段概述:

F十六进制标志,它们加起来表示进程的当前状态。

如下所述:00 进程终止,而且它们在进程表中的空间已释放。01 系统进程,长驻内存02 进程被父进程跟踪04 进程被父进程跟踪而且已被停止08 该进程无法被信号量唤醒10 该进程当前在内存中,而且被锁定直到一个事件完成20 进程不能被交换出

S 进程当前状态,由以下字母之一显示: O 当前正在处理器上运行 S 睡眠;等待I/O事件完成

R 运行结束I 空闲;进程被创建 Z 僵死。进程已终止 T由于父进程跟踪而停止 X 等待更多的内存

UID进程所有者的用户ID PID进程ID PPID父进程ID

C 进程的CPU使用情况(即进程占CPU时间的百分比) PRI 进程优先权方案。较大的数表示较低的优先权

NI 进程的nice值,该值与优先权方案相关联。使一个进程“nicer”意指降低该进程的优先权,以使它不会用尽CPU的时间

SZ进程请求的虚拟内存量。这是该系统对内存需求的一个好的指标。

TTY 启动进程(或者父进程)的终端。带问号的进程无控制终端(通常为系统进程) TIME自进程启动以来占CPU时间总量 COMD产生进程的命令 # ps -f

UID PID PPID C STIME TTY TIME CMD keven 360 358 0 19:19:19 pts/2 0:00 -csh keven 477 360 0 19:28:14 pts/2 0:00 ps -f # ps -u wing //特定用户 PID TTY TIME CMD 368 pts/3 0:00 sh # ps

PID TTY TIME CMD 360 pts/2 0:00 csh 475 pts/2 0:00 ps # ps -e

PID TTY TIME CMD 0 ? 0:01 sched 1 ? 0:00 init 2 ? 0:00 pageout 3 ? 0:00 fsflush 328 ? 0:00 sac 331 ? 0:00 ttymon 153 ? 0:00 rpcbind

# ps -ecl //PRI为进程优先权,这里98为最高

F S UID PID PPID CLS PRI ADDR SZ WCHAN TTY TIME CMD 19 T 0 0 0 SYS 96 fec287cc 0 ? 0:00 sched 8 S 0 1 0 TS 59 de7a8808 319 dea06e16 ? 0:00 init 19 S 0 2 0 SYS 98 de7a8108 0 fec4d4b8 ? 0:00 pageout 19 S 0 3 0 SYS 60 de7a7a08 0 fecea0bc ? 0:01 fsflush 8 S 0 329 1 TS 59 de7a7308 448 deac8d68 ? 0:00 sac

8 S 0 256 1 TS 59 de7a6c08 1084 deeb7f02 ? 0:00 sendmail

$ ps -eaf

UID PID PPID C STIME TTY TIME CMD root 0 0 0 19:18:44 ? 0:01 sched root 1 0 0 19:18:44 ? 0:00 /etc/init - root 2 0 0 19:18:44 ? 0:00 pageout root 3 0 0 19:18:44 ? 0:00 fsflush

root 328 1 0 19:19:10 ? 0:00 /usr/lib/saf/sac -t 300 root 331 328 0 19:19:10 ? 0:00 /usr/lib/saf/ttymon root 153 1 0 19:18:53 ? 0:00 /usr/sbin/rpcbind

#ps -eaf |grep wing

root 317 1 0 19:19:10 ? 0:00 /usr/lib/dmi/snmpXdmid -s wing root 329 1 0 19:19:10 console 0:00 /usr/lib/saf/ttymon -g -h -p wing console login: -T sun-color -d /dev/console wing 368 366 0 19:19:47 pts/3 0:00 -sh

用法:ps [ -aAdeflcjLPy ] [ -o 格式 ] [ -t 项列表 ] [ -u 用户列表 ] [ -U 用户列表 ] [ -G 组列表 ]

[ -p proclist ] [ -g pgrplist ] [ -s sidlist ] 选项 意义 功能

ps 无选项 显示在当前shell和终端窗口中的用户进程信息

ps -e every 显示系统中每一个进程的信息

ps -f full 生成一个长列表,显示每个进程的所有可用信息 ps -u userid user 显示特定用户的所有进程信息 $ ps -u wing //wing为用户名 PID TTY TIME CMD 368 pts/3 0:00 sh 494 pts/3 0:00 ps $ ps -U wing

PID TTY TIME CMD 368 pts/3 0:00 sh 495 pts/3 0:00 ps

$ ps -G user //user为组名 PID TTY TIME CMD 360 pts/2 0:00 csh # ps -ecl

F S UID PID PPID CLS PRI ADDR SZ WCHAN TTY TIME CMD 19 T 0 0 0 SYS 96 fec287cc 0 ? 0:00 sched 8 S 0 1 0 TS 59 de7a8808 319 dea06e16 ? 0:00 init kill

signal: 1 暂停 2 中断 3 退出 4 非法指令 5 跟踪中断 6 Abort

7 EMT指令(Emulation竞争trap) 8 浮点格式的异常情况

9 kill(不能被捕获或忽略) 10 通道错误

11不合法的内存区段 12 错误系统调用

13 写入不可读的连通管道 14 alarm clock 15 软件结束信号 16 用户定义的信号1 17用户定义的信号2 18 子进程状态被改变 19 电源坏掉

20窗口(Window)的大小被改变 21Urgent(紧急的)Socket Condition

22 Pollable(可查询的)event 23 停止

24 由用户终止 25 继续执行 26 停止终端输入 27 停止终端输出

28 virtual Timer expired 29 Profiling time expired 30 超过CPU时间 31 超过文件大小限制 32 Socket I/O possible

#kill -9 368 //强行杀死一个进程

#kill 368 //杀死一个进程,使用15为默认值,为软杀死 kill -HUP ID //重启一个进程

软件管理 pkgadd

#pkgadd -d /tem softwarename 软件名gpw-6.94-sol8-intel-local.gz #gunzip gpw-6.94-sol8-intel-local.gz

#head gpw-6.94-sol8-intel-local.gz //查看文件的版本信息 #pkgadd -d gpw-6.94-sol8-intel-local.gz

pkginfo

#pkginfo //安装了的软件包 pkgchk

#pkgchk pkginst //检查软件包的完整性 #pkgchk -f pkginst //处理软件包问题 #pkgchk -n pkginst //忽略包的不稳定性

#pkgchk -l -p /usr/bin/mydir //获取已安装文件的包属性 pkgrm

#pkgrm pkginst //删除软件包

#pkgrm pkginst1 pkginst2 //同时删除多个包 showrev

#showrev -p //显示已安装的补丁

patchadd

#patchadd patchname //安装补丁

#patchadd -M patch1 patch2 //同时安装多个补丁

#patchadd -d -R /export/mars /var/spool/patch/11102-12 //目的 源路径

//不允许对补丁安装进行现场恢复

补丁安装实例

2.6_Recommended.tar.z 补丁名 1

#df -k dir //查看该目录的大小 #tar xvf 2.6_Recommended.tar.z #./install

参数 功能

-B 指定存储恢复现场信息的目录,而不是默认目录 -C 如果需要,指定需要打补丁的网络安装映象的路径 -d 不接受可恢复现场的补丁安装 -M 指定定位补丁的可选目录 -p 打印所有已安装的补丁列表 -u 不让文件安装生效

-R 为客户安装指定可选根目录

-S 从服务器为客户端安装补丁,客户机共享服务器操作系统目录

patchrm

#patchrm patchname // 删除补丁

#patchrm -C /export/solaris_2.9/tools/1065-15 //从客户端系统删除补丁

引导和启动过程、ok模式 #shutdown #reboot #init 0 #boot -r

ok setenv boot-device disk //将默认的启动设备改为disk boot-device = disk

ok printenv boot-device //验正启动设备 boot-device disk disk

ok reset

ok test net //测试回路网络设备 ok watch-clock //测试时钟设备 ok boot -r //重新引导系统 ok boot net //从网络启动 ok boot cdrom //从光盘启动 ok boot floppy //从软盘启动

ok boot tape //从磁带引导系统 ok watch-net //检查网络是否联通

ok probe-scsi //检查系统检测出的所有磁盘设备,并得到可用的设备列表 ok banner //检测内存、系统固件的openboot版本信息 ok boot -s //进入单用户模式

#reboot -l -- -r //重新引导不在系统日记里记录 #shutdown - i 0 -g 120 -y #sync;init 0

#traceroute www.abc.com init

#init q //重新初始化运行级别 #init 0 //硬件维护模式 #init 1 //单用户模式 #init 2 //NFS不可用 #init 3 //NFS可用 #init 4 //用户定义状态 #init 5 //关闭系统电源 #init 6 //挂起操作系统 #init s //进入管理状态

网络配置

etc/hostname.interface //是这块网卡的名字或机器的名字 # cat hostname.pcn0 wing

# cat hosts #

# Internet host table #

127.0.0.1 localhost 192.168.0.11 wing # hostname wing

# cat netmasks

192.168.0.0 255.255.255.0

#ifconfig le0 172.16.255.1 netmask 255.255.255.0

配置网络端口状态 #ifconfig le0 up/down

配置网络端口是否可用

#ifconfig le0 plumb/unplumb

#ifconfig -a 这个地址只有root用户使用时才显示。如果一个非root用户使用ifconfig命令,那么只有IP地址 # ifconfig -a

lo0: flags=1000849 mtu 8232 index 1 inet 127.0.0.1 netmask ff000000

hme0: flags=1000843 mtu 1500 index 2 inet 192.168.10.25 netmask ffffff00 broadcast 192.168.10.255 ether 8:0:20:a2:11:de #

#ifconfig le0 192.168.0.3 netmask 255.255.255.0 broadcast 192.168.0.255 up banner

你也可以在系统还没有启动时在ok提示符下敲入banner来找到MAC地址,CPU 型号和频率。 ok banner

un Ultra 5/10 UPA/PCI (UltraSPARC-IIi 300MHz), Keyboard Present OpenBoot 3.1.1 64 MB memory installed, Serial #9361102. Ethernet address 8:0:20:8e:d6:ce, HostID: 808ed6ce.

# arp -a //登陆用户

Net to Media Table: IPv4

Device IP Address Mask Flags Phys Addr ------ -------------------- --------------- ----- ---------------

pcn0 192.168.0.1 255.255.255.255 00:03:0f:fd:6d:0c pcn0 wing 255.255.255.255 SP 00:0c:29:19:a1:54 pcn0 224.0.0.0 240.0.0.0 SM 01:00:5e:00:00:00

# netstat // 网络状态

TCP: IPv4

Local Address Remote Address Swind Send-Q Rwind Recv-Q State -------------------- -------------------- ----- ------ ----- ------ -------

wing.telnet 192.168.0.1.1030 7168 0 66608 0 ESTABLISHED wing.telnet 192.168.0.1.1032 6253 1 66608 0 ESTABLISHED

Active UNIX domain sockets

Address Type Vnode Conn Local Addr Remote Addr df187cc0 stream-ord dee4c1c0 00000000 /tmp/.X11-unix/X0

df187de8 stream-ord 00000000 00000000 #

# netstat -r //查看路由表

Routing Table: IPv4

Destination Gateway Flags Ref Use Interface -------------------- -------------------- ----- ----- ------ --------- 192.168.0.0 wing U 1 3 pcn0 224.0.0.0 wing U 1 0 pcn0 default wing UG 1 0

localhost localhost UH 2 6 lo0

# netstat -g

Group Memberships: IPv4

Interface Group RefCnt --------- -------------------- ------ lo0 224.0.0.1 1 pcn0 224.0.0.1 1

# netstat -p

Net to Media Table: IPv4

Device IP Address Mask Flags Phys Addr ------ -------------------- --------------- ----- ---------------

pcn0 192.168.0.1 255.255.255.255 00:03:0f:fd:6d:0c pcn0 solaris9 255.255.255.255 SP 00:0c:29:80:4c:0a pcn0 224.0.0.0 240.0.0.0 SM 01:00:5e:00:00:00 #

# netstat -s

RAWIP

rawipInDatagrams = 0 rawipInErrors = 0 rawipInCksumErrs = 0 rawipOutDatagrams = 0 rawipOutErrors = 0

UDP

udpInDatagrams = 923 udpInErrors = 0 udpOutDatagrams = 928 udpOutErrors = 0

TCP tcpRtoAlgorithm = 4 tcpRtoMin = 400 tcpRtoMax = 60000 tcpMaxConn = -1 tcpActiveOpens = 18 tcpPassiveOpens = 21 tcpAttemptFails = 0 tcpEstabResets = 0 tcpCurrEstab = 31 tcpOutSegs = 715

tcpOutDataSegs = 524 tcpOutDataBytes = 52210 tcpRetransSegs = 0 tcpRetransBytes = 0 tcpOutAck = 191 tcpOutAckDelayed = 90 tcpOutUrg = 0 tcpOutWinUpdate = 0 tcpOutWinProbe = 0 tcpOutControl = 47 tcpOutRsts = 0 tcpOutFastRetrans = 0 tcpInSegs = 925

tcpInAckSegs = 505 tcpInAckBytes = 52216 tcpInDupAck = 7 tcpInAckUnsent = 0 tcpInInorderSegs = 524 tcpInInorderBytes = 45645 tcpInUnorderSegs = 0 tcpInUnorderBytes = 0 tcpInDupSegs = 0 tcpInDupBytes = 0 tcpInPartDupSegs = 0 tcpInPartDupBytes = 0 tcpInPastWinSegs = 0 tcpInPastWinBytes = 0 tcpInWinProbe = 0 tcpInWinUpdate = 0 tcpInClosed = 0 tcpRttNoUpdate = 0 tcpRttUpdate = 497 tcpTimRetrans = 0 tcpTimRetransDrop = 0 tcpTimKeepalive = 0 tcpTimKeepaliveProbe= 0 tcpTimKeepaliveDrop = 0 tcpListenDrop = 0 tcpListenDropQ0 = 0 tcpHalfOpenDrop = 0 tcpOutSackRetrans = 0

IPv4 ipForwarding = 2 ipDefaultTTL = 255 ipInReceives = 422 ipInHdrErrors = 0 ipInAddrErrors = 0 ipInCksumErrs = 0 ipForwDatagrams = 0 ipForwProhibits = 0 ipInUnknownProtos = 0 ipInDiscards = 0 ipInDelivers = 1832 ipOutRequests = 265 ipOutDiscards = 0 ipOutNoRoutes = 0 ipReasmTimeout = 60 ipReasmReqds = 0 ipReasmOKs = 0 ipReasmFails = 0 ipReasmDuplicates = 0 ipReasmPartDups = 0 ipFragOKs = 0 ipFragFails = 0 ipFragCreates = 0 ipRoutingDiscards = 0 tcpInErrs = 0 udpNoPorts = 20

udpInCksumErrs = 0 udpInOverflows = 0 rawipInOverflows = 0 ipsecInSucceeded = 0 ipsecInFailed = 0 ipInIPv6 = 0 ipOutIPv6 = 0 ipOutSwitchIPv6 = 8

IPv6 ipv6Forwarding = 2 ipv6DefaultHopLimit = 255 ipv6InReceives = 0 ipv6InHdrErrors = 0 ipv6InTooBigErrors = 0 ipv6InNoRoutes = 0 ipv6InAddrErrors = 0 ipv6InUnknownProtos = 0 ipv6InTruncatedPkts = 0 ipv6InDiscards = 0 ipv6InDelivers = 0 ipv6OutForwDatagrams= 0 ipv6OutRequests = 0 ipv6OutDiscards = 0 ipv6OutNoRoutes = 0 ipv6OutFragOKs = 0 ipv6OutFragFails = 0 ipv6OutFragCreates = 0 ipv6ReasmReqds = 0 ipv6ReasmOKs = 0 ipv6ReasmFails = 0 ipv6InMcastPkts = 0 ipv6OutMcastPkts = 0 ipv6ReasmDuplicates = 0 ipv6ReasmPartDups = 0 ipv6ForwProhibits = 0 udpInCksumErrs = 0 udpInOverflows = 0 rawipInOverflows = 0 ipv6InIPv4 = 0 ipv6OutIPv4 = 0 ipv6OutSwitchIPv4 = 0

ICMPv4 icmpInMsgs = 5 icmpInErrors = 0 icmpInCksumErrs = 0 icmpInUnknowns = 0 icmpInDestUnreachs = 5 icmpInTimeExcds = 0 icmpInParmProbs = 0 icmpInSrcQuenchs = 0 icmpInRedirects = 0 icmpInBadRedirects = 0 icmpInEchos = 0 icmpInEchoReps = 0

icmpInTimestamps = 0 icmpInTimestampReps = 0 icmpInAddrMasks = 0 icmpInAddrMaskReps = 0 icmpInFragNeeded = 0 icmpOutMsgs = 5 icmpOutDrops = 0 icmpOutErrors = 0

icmpOutDestUnreachs = 5 icmpOutTimeExcds = 0 icmpOutParmProbs = 0 icmpOutSrcQuenchs = 0 icmpOutRedirects = 0 icmpOutEchos = 0 icmpOutEchoReps = 0 icmpOutTimestamps = 0 icmpOutTimestampReps= 0 icmpOutAddrMasks = 0 icmpOutAddrMaskReps = 0 icmpOutFragNeeded = 0 icmpInOverflows = 0

ICMPv6 icmp6InMsgs = 0 icmp6InErrors = 0 icmp6InDestUnreachs = 0 icmp6InAdminProhibs = 0 icmp6InTimeExcds = 0 icmp6InParmProblems = 0 icmp6InPktTooBigs = 0 icmp6InEchos = 0 icmp6InEchoReplies = 0 icmp6InRouterSols = 0 icmp6InRouterAds = 0 icmp6InNeighborSols = 0 icmp6InNeighborAds = 0 icmp6InRedirects = 0 icmp6InBadRedirects = 0 icmp6InGroupQueries = 0

icmp6InGroupResps = 0 icmp6InGroupReds = 0 icmp6InOverflows = 0

icmp6OutMsgs = 0 icmp6OutErrors = 0

icmp6OutDestUnreachs= 0 icmp6OutAdminProhibs= 0 icmp6OutTimeExcds = 0 icmp6OutParmProblems= 0 icmp6OutPktTooBigs = 0 icmp6OutEchos = 0 icmp6OutEchoReplies = 0 icmp6OutRouterSols = 0 icmp6OutRouterAds = 0 icmp6OutNeighborSols= 0 icmp6OutNeighborAds = 0 icmp6OutRedirects = 0 icmp6OutGroupQueries= 0 icmp6OutGroupResps = 0 icmp6OutGroupReds = 0

IGMP:

0 messages received

0 messages received with too few bytes 0 messages received with bad checksum 0 membership queries received

0 membership queries received with invalid field(s) 0 membership reports received

0 membership reports received with invalid field(s)

0 membership reports received for groups to which we belong 0 membership reports sent

# netstat -M

Virtual Interface Table is empty

Multicast Forwarding Cache is empty #

# netstat -r //网络接口状态

Routing Table: IPv4

Destination Gateway Flags Ref Use Interface -------------------- -------------------- ----- ----- ------ --------- 192.168.0.0 solaris9 U 1 1 pcn0 192.168.0.0 address2 U 1 0 pcn0:1 224.0.0.0 solaris9 U 1 0 pcn0 default 192.168.0.1 UG 1 0 localhost localhost UH 2 6 lo0 # netstat -rn

Routing Table: IPv4

Destination Gateway Flags Ref Use Interface -------------------- -------------------- ----- ----- ------ --------- 192.168.0.0 192.168.0.3 U 1 1 pcn0 192.168.0.0 192.168.0.5 U 1 0 pcn0:1 224.0.0.0 192.168.0.3 U 1 0 pcn0 default 192.168.0.1 UG 1 0 127.0.0.1 127.0.0.1 UH 2 6 lo0 #

# netstat -i 1 5

input pcn0 output input (Total) output

packets errs packets errs colls packets errs packets errs colls 1187 0 1318 0 0 3699 0 3830 0 0 4 0 4 0 0 4 0 4 0 0 3 0 3 0 0 5 0 5 0 0 4 0 4 0 0 4 0 4 0 0 3 0 4 0 0 5 0 6 0 0 #

snoop

# snoop -c 3 //抓取3IP包

Using device /dev/pcn0 (promiscuous mode) 192.168.0.1 -> solaris9 TELNET C port=3013

solaris9 -> 192.168.0.1 TELNET R port=3013 Using device /dev/pc 192.168.0.1 -> solaris9 TELNET C port=3013 3 packets captured #

# snoop -v -c 2 //抓取两个详细的IP包。 Using device /dev/pcn0 (promiscuous mode) ETHER: ----- Ether Header ----- ETHER:

ETHER: Packet 1 arrived at 1:43:41.42 ETHER: Packet size = 60 bytes

ETHER: Destination = 0:c:29:80:4c:a, ETHER: Source = 0:3:f:fd:6d:c, ETHER: Ethertype = 0800 (IP) ETHER:

IP: ----- IP Header -----

IP:

IP: Version = 4

IP: Header length = 20 bytes IP: Type of service = 0x00

IP: xxx. .... = 0 (precedence) IP: ...0 .... = normal delay

IP: .... 0... = normal throughput IP: .... .0.. = normal reliability

IP: .... ..0. = not ECN capable transport

IP: .... ...0 = no ECN congestion experienced IP: Total length = 40 bytes IP: Identification = 1627 IP: Flags = 0x4

IP: .1.. .... = do not fragment IP: ..0. .... = last fragment IP: Fragment offset = 0 bytes

IP: Time to live = 128 seconds/hops IP: Protocol = 6 (TCP)

IP: Header checksum = 7320

IP: Source address = 192.168.0.1, 192.168.0.1 IP: Destination address = 192.168.0.3, solaris9 IP: No options IP:

TCP: ----- TCP Header ----- TCP:

TCP: Source port = 3013

TCP: Destination port = 23 (TELNET) TCP: Sequence number = 769864152

TCP: Acknowledgement number = 52297913 TCP: Data offset = 20 bytes TCP: Flags = 0x10

TCP: 0... .... = No ECN congestion window reduced TCP: .0.. .... = No ECN echo TCP: ..0. .... = No urgent pointer TCP: ...1 .... = Acknowledgement TCP: .... 0... = No push TCP: .... .0.. = No reset TCP: .... ..0. = No Syn TCP: .... ...0 = No Fin TCP: Window = 17292 TCP: Checksum = 0x7b85 TCP: Urgent pointer = 0 TCP: No options TCP:

TELNET: ----- TELNET: ----- TELNET: TELNET: \ TELNET:

ETHER: ----- Ether Header ----- ETHER:

ETHER: Packet 2 arrived at 1:43:41.42 ETHER: Packet size = 97 bytes

ETHER: Destination = 0:3:f:fd:6d:c, ETHER: Source = 0:c:29:80:4c:a, ETHER: Ethertype = 0800 (IP) ETHER:

IP: ----- IP Header ----- IP:

IP: Version = 4

IP: Header length = 20 bytes IP: Type of service = 0x00

IP: xxx. .... = 0 (precedence) IP: ...0 .... = normal delay

IP: .... 0... = normal throughput IP: .... .0.. = normal reliability

IP: .... ..0. = not ECN capable transport

IP: .... ...0 = no ECN congestion experienced IP: Total length = 83 bytes IP: Identification = 50744 IP: Flags = 0x4

IP: .1.. .... = do not fragment IP: ..0. .... = last fragment IP: Fragment offset = 0 bytes

IP: Time to live = 60 seconds/hops IP: Protocol = 6 (TCP)

IP: Header checksum = f717

IP: Source address = 192.168.0.3, solaris9

IP: Destination address = 192.168.0.1, 192.168.0.1 IP: No options IP:

TCP: ----- TCP Header ----- TCP:

TCP: Source port = 23

TCP: Destination port = 3013

TCP: Sequence number = 52297913

TCP: Acknowledgement number = 769864152 TCP: Data offset = 20 bytes

TCP: Flags = 0x18

TCP: 0... .... = No ECN congestion window reduced TCP: .0.. .... = No ECN echo TCP: ..0. .... = No urgent pointer TCP: ...1 .... = Acknowledgement TCP: .... 1... = Push TCP: .... .0.. = No reset TCP: .... ..0. = No Syn TCP: .... ...0 = No Fin TCP: Window = 64240 TCP: Checksum = 0xd1f6 TCP: Urgent pointer = 0 TCP: No options TCP:

TELNET: ----- TELNET: ----- TELNET:

TELNET: \ TELNET:

2 packets captured #

# snoop host1 host2

host1 -> host2 ICMP Echo request host2 -> host1 ICMP Echo reply

使用snoop实用程序判定系统间实际上传送的什么信,判断网络畅通 # snoop -a dhcp

Snoop 的使用

Snoop 是Solaris 系统中自带的工具, 是一个用于显示网络通讯的程序, 它 可捕获IP 包并将其显示或保存到指定文件. (限超级用户使用snoop) Snoop 可将捕获的包以一行的形式加以总结或用多行加以详细的描述(有 调用不同的参数-v -V来实现). 在总结方式下(-V ) , 将仅显示最高层的相关协

议, 例如一个NFS 包将仅显示NFS 信息, 其低层的RPC, UDP, IP, Ethernet 帧信息将不会显示, 但是当加上相应的参数(-v ), 这些信息都能被显示出来. 参数简介:

[ -a ] # Listen to packets on audio

[ -d device ] # settable to le?, ie?, bf?, tr? [ -s snaplen ] # Truncate packets

[ -c count ] # Quit after count packets [ -P ] # Turn OFF promiscuous mode [ -D ] # Report dropped packets [ -S ] # Report packet size

[ -i file ] # Read previously captured packets

[ -o file ] # Capture packets in file

[ -n file ] # Load addr-to-name table from file [ -N ] # Create addr-to-name table

[ -t r|a|d ] # Time: Relative, Absolute or Delta [ -v ] # Verbose packet display [ -V ] # Show all summary lines

[ -p first[,last] ] # Select packet(s) to display

[ -x offset[,length] ] # Hex dump from offset for length [ -C ] # Print packet filter code

由于snoop 的使用非常灵活, 希望能通过下面一些例子的学习来其常见用法. 1. 监听所有以本机为源和目的的包并将其显示出来. # snoop

2. 监听所有以主机A为源和目的的包并将其显示出来. ( A为主机名, 下同) - 2 -

# snoop A

3. 监听所有A和B之间的包并将其保存到文件file. # snoop -o file A B

4. 显示文件file 中指定的包(99-108) # snoop - i file -p 99,108

99 0.0027 boutique -> sunroof NFS C GETATTR FH=8E6C 100 0.0046 sunroof -> boutique NFS R GETATTR OK

101 0.0080 boutique -> sunroof NFS C RENAME FH=8E6C MTra00192 to .nfs08

102 0.0102 marmot -> viper NFS C LOOKUP FH=561E screen.r.13.i386 103 0.0072 viper -> marmot NFS R LOOKUP No such file or directory 104 0.0085 bugbomb -> sunroof RLOGIN C PORT=1023 h 105 0.0005 kandinsky -> sparky RSTAT C Get Statistics

106 0.0004 beeblebrox -> sunroof NFS C GETATTR FH=0307 107 0.0021 sparky -> kandinsky RSTAT R

108 0.0073 office -> jeremiah NFS C READ FH=2584 at 40960 for 8192 5. 详细查看文件file 中第101 个包: # snoop - i file - v -p101

ETHER: ----- Ether Header ----- ETHER:

ETHER: Packet 101 arrived at 16:09:53.59 ETHER: Packet size = 210 bytes

ETHER: Destination = 8:0:20:1:3d:94, Sun

ETHER: Source = 8:0:69:1:5f:e, Silicon Graphics ETHER: Ethertype = 0800 (IP) ETHER:

IP: ----- IP Header ----- IP:

IP: Version = 4, header length = 20 bytes IP: Type of service = 00

IP: ..0. .... = routine

IP: ...0 .... = normal delay

IP: .... 0... = normal throughput IP: .... .0.. = normal reliability IP: Total length = 196 bytes IP: Identification 19846 IP: Flags = 0X

IP: .0.. .... = may fragment IP: ..0. .... = more fragments ? - 3 - ?

6. 查看主机A和主机B之间的NFS 包(命令中的and 和or 为相应的逻辑运 算)

# snoop - i file rpc nfs and A and B

1 0.0000 A -> B NFS C GETATTR FH=8E6C 2 0.0046 B -> A NFS R GETATTR OK

3 0.0080 A -> B NFS C RENAME FH=8E6C MTra00192 to .nfs08 7. 将这些符合条件的包保存到另一文件file2 中: # snoop - i file -o file2 rpc nfs A B

8. 监听主机A和主机B间所有TCP 80 端口或UDP80端口的包 # snoop A and B and (tcp or udp) and port 80 9. 监听所有的广播包 # snoop broadcast

Using device /dev/hme (promiscuous mode)

10.10.10.50 -> BROADCAST UDP D=177 S=2541 LEN=35 10.10.10.50 -> BROADCAST UDP D=177 S=2541 LEN=35 10.10.10.50 -> BROADCAST UDP D=177 S=2541 LEN=35 10. 监听所有的多播包, 并显示详细内容. #snoop -v multicast

ETHER: ----- Ether Header ----- ETHER:

ETHER: Packet 1 arrived at 12:33:2.16 ETHER: Packet size = 69 bytes

ETHER: Destination = ff:ff:ff:ff:ff:ff, (broadcast) ETHER: Source = 0:4:76:46:8f:50, ETHER: Ethertype = 0800 (IP) ETHER:

IP: ----- IP Header ----- IP:

IP: Version = 4

IP: Header length = 20 bytes IP: Type of service = 0x00 IP: xxx. .... = 0 (precedence)

IP: ...0 .... = normal delay - 4 -

IP: .... 0... = normal throughput IP: .... .0.. = normal reliability IP: Total length = 55 bytes IP: Identification = 14658 IP: Flags = 0x0

IP: .0.. .... = may fragment IP: ..0. .... = last fragment IP: Fragment offset = 0 bytes

IP: Time to live = 128 seconds/hops IP: Protocol = 17 (UDP) IP: Header checksum = ed38

IP: Source address = 10.10.10.50, 10.10.10.50

IP: Destination address = 255.255.255.255, BROADCAST IP: No options IP:

UDP: ----- UDP Header ----- UDP:

UDP: Source port = 2541 UDP: Destination port = 177 UDP: Length = 35

UDP: Checksum = 8E35 UDP:

ETHER: ----- Ether Header ----- ETHER:

ETHER: Packet 2 arrived at 12:33:12.16 ETHER: Packet size = 69 bytes

ETHER: Destination = ff:ff:ff:ff:ff:ff, (broadcast) ETHER: Source = 0:4:76:46:8f:50, ETHER: Ethertype = 0800 (IP) ETHER:

IP: ----- IP Header ----- IP:

IP: Version = 4

IP: Header length = 20 bytes IP: Type of service = 0x00 IP: xxx. .... = 0 (precedence) IP: ...0 .... = normal delay

IP: .... 0... = normal throughput IP: .... .0.. = normal reliability IP: Total length = 55 bytes IP: Identification = 14985 IP: Flags = 0x0

IP: .0.. .... = may fragment IP: ..0. .... = last fragment IP: Fragment offset = 0 bytes

IP: Time to live = 128 seconds/hops IP: Protocol = 17 (UDP) IP: Header checksum = ebf1

IP: Source address = 10.10.10.50, 10.10.10.50 - 5 -

IP: Destination address = 255.255.255.255, BROADCAST IP: No options IP:

UDP: ----- UDP Header ----- UDP:

UDP: Source port = 2541 UDP: Destination port = 177 UDP: Length = 35

UDP: Checksum = 8E35 UDP:

11.监听所有的NTP 协议包 # snoop |grep - i NTP

Using device /dev/hme (promiscuous mode)

ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:48:50 2002) ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:49:54 2002) ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:50:58 2002) ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:52:02 2002) ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:53:06 2002) ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:54:10 2002)

这里我们也可看到NTP server 每隔约一分钟即向多播地址广播一次.

设备管理

软盘

#volcheck

fdformat [-dDeEfHlLmMUqvx] [-b label] [-B filename] [-t dos- type] [devname] //格式化

prtconf

# prtconf //配置信息

System Configuration: Sun Microsystems i86pc Memory size: 128 Megabytes //内存 System Peripherals (Software Nodes):

i86pc

+boot (driver not attached)

memory (driver not attached) aliases (driver not attached) chosen (driver not attached)

i86pc-memory (driver not attached) i86pc-mmu (driver not attached) openprom (driver not attached) options, instance #0

packages (driver not attached)

delayed-writes (driver not attached) itu-props (driver not attached) isa, instance #0

motherboard (driver not attached) asy, instance #0 asy, instance #1

lp (driver not attached) fdc, instance #0 fd, instance #0

fd, instance #1 (driver not attached) i8042, instance #0

keyboard, instance #0 mouse, instance #0

PNP0C02 (driver not attached) PNP0C02 (driver not attached) PNP0C02 (driver not attached) bios (driver not attached) bios (driver not attached) bios (driver not attached) pci, instance #0

pci15ad,1976 (driver not attached) pci8086,7191 (driver not attached) pci15ad,1976 (driver not attached) pci-ide, instance #0 ide, instance #0 cmdk, instance #0 ide, instance #1 sd, instance #0

pci15ad,1976, instance #0

pci15ad,1976 (driver not attached) display, instance #0

pci1022,2000, instance #0

pci1274,1371 (driver not attached) used-resources (driver not attached) objmgr, instance #0

cpus (driver not attached)

cpu, instance #0 (driver not attached) pseudo, instance #0 #

# prtconf | grep Memory //查看内存 Memory size: 128 Megabytes

eject

#eject floppy

eeprom

#eeprom selftest -#megs=64 //修改系统自检到的内存数

sysdef

#sysdef //更详细的体系机构

SUN服务器网络安装: 提供网络安装的服务器端:

1)vi /etc/hosts //写入被安装客户端IP 和主机名 ....

192.168.0.230 root loghost svcs | grep network

svcadm restart svc:network/phycis:default //修改IP后需重启服务

2)vi /etc/ethers //写入服务器的mac 和主机名 11:11:11:11:11:11 root

3)cd /cdrom /sol/Tools

./add_to_install_client root sun4u

share //共享

4)svcadm disable svc:network/nfs /server/:default

svcadm enable svc:network/nfs /server/:default //重启nfs服务

被安装的客户端: 1.sc>poweron //通电

2.sc>console -f //进入OK模式 3.[3] ok banner //可查看mac

4.[3] ok boot net //开始网络安装系统

选择DEC VT100

ok boot net -s 单用户模式启动

本文来源:https://www.bwwdw.com/article/jhlr.html

Top