linux network tools - yaokun123/php-wiki GitHub Wiki

网络工具

一、查询网络服务和端口

netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。

netstat -apn|grep 3306

1、-a, --all Show both listening and non-listening (for TCP this means established connections) sockets
2、-l, --listening Show only listening sockets.
3、-p, --program Show the PID and name of the program to which each socket belongs
4、-n, --numeric Show numerical addresses instead of trying to determine symbolic host, port or user names

lsof(list open files)是一个列出当前系统打开文件的工具。在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件。所以如传输控制协议 (TCP) 和用户数据报协议 (UDP) 套接字等; 在查询网络端口时,经常会用到这个工具。

查询7902端口现在运行什么程序:
1、查询使用该端口的进程的PID:lsof -i:7902
2、使用ps工具查询进程详情:ps -fe | grep 30294

二、网络路由

1、查看路由状态:                    route -n
2、发送ping包到地址IP:              ping IP
3、探测前往地址IP的路由路径:          traceroute IP
4、DNS查询,寻找域名domain对应的IP:   host domain
5、反向DNS查询                      host IP

三、镜像下载

直接下载文件或者网页

wget url

常用选项:
–limit-rate :下载限速
-o:指定日志文件;输出都写入日志;
-c:断点续传

四、ftp、sftp、lftp、ssh

五、网络复制

将本地localpath指向的文件上传到远程主机的path路径:
scp localpath ID@host:path

以ssh协议,遍历下载path路径下的整个文件系统,到本地的localpath:
scp -r ID@site:path localpath