首页 > 系统 > Linux > 正文

Linux管理与网络小技巧

2020-06-07 13:30:40
字体:
来源:转载
供稿:网友

1、 lsof 用法小全

lsof abc.txt 显示开启文件 abc.txt 的进程

lsof -i :22 知道 22 端口现在运行什么程序

lsof -c nsd  显示 nsd 进程现在打开的文件

lsof -g gid 显示归属 gid 的进程情况

lsof +d /usr/local/  显示目录下被进程开启的文件

lsof +D /usr/local/ 同上,但是会搜索目录下的目录,时间较长

lsof -d 4   显示使用 fd 为4 的进程

lsof -i [i]  用以显示符合条件的进程情况

语法: lsof -i[46] [protocol][@hostname|hostaddr][:service|port]

46 --> IPv4 or IPv6

protocol --> TCP or UDP

hostname --> Internet host name

hostaddr --> IPv4 位置

service --> /etc/service中的 service name (可以不止一个)

port -->  端口号(可以不止一个)

例子: TCP:25 - TCP and port 25

@1.2.3.4 - Internet IPv4 host address 1.2.3.4

tcp@ohaha.ks.edu.tw:ftp - TCP protocol host:ohaha.ks.edu.tw service name:ftp

lsof -n 不将 IP转换为 hostname,预设是不加上-n参数

例子: lsof -i tcp@ohaha.ks.edu.tw:ftp -n

lsof -p 12    看进程号为 12的进程打开了哪些文件

2、grep 不显示本身进程

#ps -aux|grep httpd|grep -v grep

grep -v grep可以取消显示你所执行的 grep 本身这个进程,-v 参数是不显示所列出的进程名

3、查看本机IP

ifconfig |grep "inet" |cut -c 0-36|sed -e 's/[a-zA-Z: ]//g'

hostname –i

4、查看有多少活动的Httpd进程

#!/bin/sh

while (true)

do

pstree |grep "*/[httpd/]$"|sed 's/.*-/([0-9][0-9]*/)/*/[httpd/]$//1/'

sleep 3

done

   同样可以引用到其它的进程

5、设置 com1口,让超级终端通过 com1口进行登录

第一步:确认有/sbin/agetty,编辑/etc/inittab,添加

7:2345:respawn:/sbin/agetty /dev/ttyS0 9600

9600bps 是因为连路由器时缺省一般都是这种速率,也可以设成

19200、38400、57600、115200

第二步:修改/etc/securetty,添加一行:ttyS0,确保 root 用户能登录

第三步:重启机器,就可以拔掉鼠标键盘显示器(启动时最好还是要看看输出信息)了

6、查找或删除正在使用某文件的进程

fuser filename

fuser -k filename

7、已知网络中一个机器的硬件地址,如何知道它所对应的 IP地址

在 Linux 下,假定要查“00:0A:EB:27:17:B9”这样一个硬件地址所对应的 IP 地址,可以使

用以下命令:

# cat /proc/net/arp |grep 00:0A:EB:27:17:B9

192.168.2.54 0x1 0x6 00:0A:EB:27:17:B9 *eth2

另外,还可以用“arp -a”命令查询:

# arp  –a|grep 00:0A:EB:27:17:B9

(192.168.2.54)at 00:0A:EB:27:17:B9[ether] on eth2

8、在 Linux下如何绑定 IP地址和硬件地址

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表