DukeDuke
主页
文档转换
关于我们
主页
文档转换
关于我们
  • Linux 系统

    • Linux 系统管理
    • Linux 网络管理
    • Linux 文件管理
    • Linux 命令大全
  • Nginx Web 服务器

    • Nginx 安装 与 配置
    • Nginx 负载均衡
    • Nginx SSL证书配置
    • Nginx Keepalived 高可用
  • Docker 容器

    • Docker 简介
    • Docker 安装与配置
    • Docker 命令
    • Docker 部署 Nginx
    • Docker 部署 MySQL
    • Docker 部署 Redis
  • 服务器

    • 塔式服务器
    • 机架式服务器
    • 刀片服务器
  • Git 版本控制
  • Jenkins 持续集成
  • Jmeter 性能测试
  • Let's Encrypt 免费SSL证书

Linux 网络管理

网络命令

netstat - 显示网络连接状态

命令参数解释表格:

参数说明示例
-t显示 TCP 连接netstat -t
-u显示 UDP 连接netstat -u
-l显示监听端口netstat -l
-n显示数字地址netstat -n
-p显示进程信息netstat -p
-a显示所有连接netstat -a

输出参数解释表格:

输出字段说明示例
Proto协议类型tcp
Recv-Q接收队列0
Send-Q发送队列0
Local Address本地地址127.0.0.1:8080
Foreign Address远程地址0.0.0.0:*
State连接状态LISTEN
PID/Program name进程 ID/程序名1234/nginx

指令输出示例:

$ netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:8080         0.0.0.0:*               LISTEN      1234/nginx
tcp        0      0 0.0.0.0:22             0.0.0.0:*               LISTEN      5678/sshd
tcp6       0      0 :::80                   :::*                    LISTEN      9012/apache2

ping - 测试网络连通性

命令参数解释表格:

参数说明示例
-c指定发送次数ping -c 4 8.8.8.8
-i指定发送间隔(秒)ping -i 2 8.8.8.8
-s指定数据包大小ping -s 1000 8.8.8.8
-t设置 TTL 值ping -t 64 8.8.8.8
-W设置超时时间ping -W 5 8.8.8.8

输出参数解释表格:

输出字段说明示例
icmp_seqICMP 序列号1
ttl生存时间64
time响应时间2.5 ms
bytes数据包大小64

指令输出示例:

$ ping -c 4 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=64 time=2.5 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=64 time=2.3 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=64 time=2.4 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=64 time=2.6 ms

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 2.300/2.450/2.600/0.100 ms

软件包管理命令

apt - Debian/Ubuntu 包管理

命令参数解释表格:

参数说明示例
update更新包列表apt update
upgrade升级包apt upgrade
install安装包apt install nginx
remove删除包apt remove nginx
purge完全删除包apt purge nginx
search搜索包apt search nginx
show显示包信息apt show nginx
list列出包apt list --installed

指令输出示例:

$ apt update
Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Fetched 379 kB in 2s (189 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

$ apt install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  nginx-common nginx-core
The following NEW packages will be installed:
  nginx nginx-common nginx-core
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,234 kB of archives.
After this operation, 3,456 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

yum - CentOS/RHEL 包管理

命令参数解释表格:

参数说明示例
install安装包yum install nginx
remove删除包yum remove nginx
update更新包yum update
search搜索包yum search nginx
info显示包信息yum info nginx
list列出包yum list installed
clean清理缓存yum clean all

指令输出示例:

$ yum install nginx
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.16.1-1.el7 will be installed
--> Finished dependency resolution

Dependencies Resolved

================================================================================
 Package        Arch           Version                Repository            Size
================================================================================
Installing:
 nginx          x86_64         1:1.16.1-1.el7        epel                 1.5 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 1.5 M
Installed size: 5.2 M
Is this ok [y/d/N]: y

远程连接命令

ssh - 安全远程连接

命令参数解释表格:

参数说明示例
-p指定端口号ssh -p 2222 user@host
-i指定私钥文件ssh -i ~/.ssh/id_rsa user@host
-X启用 X11 转发ssh -X user@host
-L本地端口转发ssh -L 8080:localhost:80 user@host
-D动态端口转发ssh -D 1080 user@host
-t强制分配伪终端ssh -t user@host
-v详细模式ssh -v user@host

指令输出示例:

$ ssh user@192.168.1.100
user@192.168.1.100's password:
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-74-generic x86_64)

$ ssh -p 2222 -i ~/.ssh/id_rsa user@host
# 使用指定端口和私钥连接

$ ssh -L 8080:localhost:80 user@host
# 本地8080端口转发到远程80端口

scp - 安全文件传输

命令参数解释表格:

参数说明示例
-r递归复制目录scp -r dir/ user@host:/path/
-P指定端口号scp -P 2222 file user@host:/path/
-i指定私钥文件scp -i ~/.ssh/id_rsa file user@host:/path/
-v详细模式scp -v file user@host:/path/
-C启用压缩scp -C file user@host:/path/
-p保留文件属性scp -p file user@host:/path/

指令输出示例:

$ scp file.txt user@192.168.1.100:/home/user/
user@192.168.1.100's password:
file.txt                                    100%   25     0.0KB/s   00:00

$ scp -r documents/ user@192.168.1.100:/home/user/
user@192.168.1.100's password:
file1.txt                                  100%   25     0.0KB/s   00:00
file2.txt                                  100%   30     0.0KB/s   00:00

rsync - 远程同步

命令参数解释表格:

参数说明示例
-a归档模式rsync -a source/ dest/
-v详细模式rsync -v file dest/
-z压缩传输rsync -z file dest/
-r递归复制rsync -r dir/ dest/
-P显示进度rsync -P file dest/
-n试运行rsync -n -a source/ dest/
--delete删除目标多余文件rsync -a --delete source/ dest/
-e指定远程 shellrsync -e "ssh -p 2222" file user@host:/path/

指令输出示例:

$ rsync -avz /local/dir/ user@host:/remote/dir/
sending incremental file list
./
file1.txt
file2.txt

sent 1234 bytes  received 567 bytes  3602.00 bytes/sec
total size is 8901  speedup is 4.94

$ rsync -avz --delete /backup/ user@host:/backup/
sending incremental file list
deleting old_file.txt
./
new_file.txt

sent 2345 bytes  received 678 bytes  6046.00 bytes/sec
total size is 12345  speedup is 2.04

文件传输命令

wget - 下载文件

命令参数解释表格:

参数说明示例
-c断点续传wget -c http://example.com/file
-O指定输出文件名wget -O filename http://example.com/file
-P指定下载目录wget -P /downloads/ http://example.com/file
-r递归下载wget -r http://example.com/
-np不跟随父目录链接wget -r -np http://example.com/
-q静默模式wget -q http://example.com/file
-b后台下载wget -b http://example.com/file
--limit-rate限制下载速度wget --limit-rate=1m http://example.com/file

指令输出示例:

$ wget http://example.com/file.txt
--2023-12-15 14:30:00--  http://example.com/file.txt
Resolving example.com... 93.184.216.34
Connecting to example.com|93.184.216.34|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1234 (1.2K) [text/plain]
Saving to: 'file.txt'

100%[======================================>] 1,234       --.-K/s   in 0.1s

2023-12-15 14:30:00 (12.3 KB/s) - 'file.txt' saved [1234/1234]

$ wget -c -O backup.tar.gz http://example.com/backup.tar.gz
# 断点续传并指定输出文件名

curl - 传输数据

命令参数解释表格:

参数说明示例
-o保存到文件curl -o file http://example.com/file
-O使用远程文件名curl -O http://example.com/file.txt
-L跟随重定向curl -L http://example.com/redirect
-H添加 HTTP 头curl -H "Authorization: Bearer token" http://api.com
-d发送 POST 数据curl -d "name=value" http://api.com
-X指定 HTTP 方法curl -X POST http://api.com
-k忽略 SSL 证书curl -k https://example.com
-s静默模式curl -s http://example.com
-w自定义输出格式curl -w "%{http_code}" http://example.com

指令输出示例:

$ curl -o file.txt http://example.com/file
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1234  100  1234    0     0  12340      0 --:--:-- --:--:-- --:--:-- 12340

$ curl -H "Content-Type: application/json" -d '{"key":"value"}' http://api.com
{"status":"success","message":"Data received"}

$ curl -w "HTTP Status: %{http_code}\nTime: %{time_total}s\n" http://example.com
HTTP Status: 200
Time: 0.123s

系统监控命令

htop - 交互式进程查看器

命令参数解释表格:

参数说明示例
-p指定进程 IDhtop -p 1234
-u指定用户名htop -u username
-d设置刷新间隔htop -d 5
-C隐藏 CPU 使用率htop -C
-t显示树状结构htop -t

htop 界面说明:

按键功能
F1显示帮助
F2设置
F3搜索进程
F4过滤进程
F5树状显示
F6排序
F9杀死进程
F10退出

指令输出示例:

$ htop
# 显示交互式进程管理器界面
# 显示CPU、内存使用情况,可交互操作

iotop - 监控磁盘 I/O

命令参数解释表格:

参数说明示例
-o只显示有 I/O 的进程iotop -o
-b批处理模式iotop -b
-n指定刷新次数iotop -n 10
-d设置刷新间隔iotop -d 2
-p指定进程 IDiotop -p 1234

指令输出示例:

$ iotop
Total DISK READ:         0.00 B/s | Total DISK WRITE:         0.00 B/s
Current DISK READ:       0.00 B/s | Current DISK WRITE:       0.00 B/s
    TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND
   1234 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % systemd
   1235 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % kthreadd

nethogs - 监控网络使用

命令参数解释表格:

参数说明示例
-t跟踪模式nethogs -t
-d设置刷新间隔nethogs -d 5
-v详细模式nethogs -v
-c指定刷新次数nethogs -c 10

指令输出示例:

$ nethogs
# 显示网络使用情况
# 按进程显示网络流量
最近更新:: 2026/4/17 13:21
Contributors: Duke
Prev
Linux 系统管理
Next
Linux 文件管理