六、网络工具
6.1 ssh - 远程连接
# 基础连接
ssh user@192.168.1.100 # 密码登录
ssh -i key.pem user@server # 密钥登录
ssh -p 2222 user@server # 指定端口
# 执行远程命令
ssh user@server "ls -la /var/log"
ssh user@server "systemctl restart nginx"
# SSH 隧道(端口转发)
ssh -L 8080:localhost:80 user@server # 本地8080 → 远程80
ssh -R 9090:localhost:3000 user@server # 远程9090 → 本地3000
# 配置文件 ~/.ssh/config
Host myserver
HostName 192.168.1.100
User deploy
Port 2222
IdentityFile ~/.ssh/id_rsa
# 使用别名连接
ssh myserver
6.2 scp - 安全复制
# 上传文件
scp local.txt user@server:/remote/path/
scp -r local_folder/ user@server:/remote/path/ # 递归上传目录
# 下载文件
scp user@server:/remote/file.txt ./local/path/
scp -r user@server:/remote/folder/ ./local/
# 指定端口
scp -P 2222 file.txt user@server:/path/
6.3 curl - 网络请求
# 基础请求
curl https://api.example.com/users # GET 请求
curl -X POST https://api.example.com/users # POST 请求
# 发送数据
curl -d "name=张三&age=25" -X POST https://api.example.com/users
curl -H "Content-Type: application/json" \
-d '{"name":"张三","age":25}' \
https://api.example.com/users
# 添加认证
curl -u username:password https://api.example.com/protected
curl -H "Authorization: Bearer token123" https://api.example.com/data
# 下载文件
curl -O https://example.com/file.zip # 保存为原文件名
curl -o myfile.zip https://example.com/file.zip # 自定义文件名
curl -C - -O https://example.com/large.zip # 断点续传
# 查看响应头
curl -I https://example.com # 只看响应头
curl -v https://example.com # 详细输出(请求+响应)
# 限速
curl --limit-rate 100K -O https://example.com/large.zip
# 代理
curl -x proxy.example.com:8080 https://api.example.com
6.4 wget - 下载工具
# 基础下载
wget https://example.com/file.zip
wget -O myfile.zip https://example.com/file.zip # 自定义文件名
# 断点续传
wget -c https://example.com/large.zip
# 递归下载网站
wget -r -l 3 https://example.com/docs/ # 深度3层
# 限制速度
wget --limit-rate=200k https://example.com/file.zip
# 后台下载
wget -b https://example.com/large.zip
tail -f wget-log # 查看下载日志
6.5 netstat/ss - 网络状态
# 查看端口监听
netstat -tuln # 监听端口
netstat -an | grep :80 # 查看80端口
ss -tuln # 更快的 netstat
# 查看连接状态
netstat -an | grep ESTABLISHED # 已建立的连接
netstat -an | grep TIME_WAIT # 等待关闭的连接
# 查看网络统计
netstat -i # 网卡统计
netstat -r # 路由表
# 查看 PID 和程序名
netstat -tulnp # 需要 root 权限