Linux学习笔记4 重点!网络排障命令

网络排障命令

命令行下载工具wget

wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.20.17.tar.gz

复制代码
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.20.17.tar.gz

限速下载

复制代码
wget --limit-rate=1M https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.20.17.tar.gz

使用wget -c进行断点续传

复制代码
wget -c https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.20.17.tar.gz

测试服务器是否支持断点续传

复制代码
wget -S http://mirrors.163.com 2>&1 |grep "Accept-Range"

说明支持断点续传:按字节。

让下载的文件按指定文件名保存。

wget -o filename

复制代码
wget -o 1.tar.gz https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.20.17.tar.gz

-o 后面跟-可以代表输出到标准输出,也就是命令行上。

curl工具

官方文档:

curl - 如何使用

探测一个网站的header

复制代码
curl -I https://www.baidu.com

类似于wget中的-S选项

显示网站的http状态码

复制代码
curl -s -o /dev/null -w %{http_code}"\n" https://www.baidu.com

-s表示安静模式

-o表示输出到哪里,这里指的是输出到空设备中

-w表示输出定义的元数据也就是会给后面的httpcode赋值、

注意这里我们"\n"紧跟在%{http_code}后面。中间如果有空格会导致输出和我们预料的不同。

关于http状态码:

常见的有404等

HTTP 响应状态码 - HTTP | MDN (mozilla.org)

复制代码
curl -s -o \dev\null -w %{http_code}"\n"%{time_total}"\n"%{redirect_url}"\n" http://blog.csdn.net

输出的三个结果分别是:

301定向操作状态码,解析网站总时间,跳转后的url。

curl实现重定向

下面是两个例子:代表用户使用curl请求某个网址时,当出现了301,或者302重定向操作,就会按照我们的-L参数去到新的url。然后就有了第二段输出状态码200的成功连接。

复制代码
curl -L -I http://blog.csdn.net

HTTP/1.1 301 Moved Permanently
Date: Wed, 28 Aug 2024 05:06:51 GMT
Content-Type: text/html
Content-Length: 160
Connection: close
Set-Cookie: ...;Expires=...; Path=/; HttpOnly
Location: https://blog.csdn.net:443/
X-Request-Id: ...
Server: WAF

HTTP/1.1 200 OK
Date: Wed, 28 Aug 2024 05:06:51 GMT
Content-Type: text/html; charset=utf-8
Connection: close
Set-Cookie: https_waf_cookie=...; Expires=...; Path=/; Secure; HttpOnly
Server: WAF
Vary: Accept-Encoding
Vary: Origin
X-Response-Time: 197
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-download-options: noopen
x-readtime: 198
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: ...
Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS
Strict-Transport-Security: max-age=0; preload
X-Request-Id: ...
Set-Cookie: ...

curl -L -I http://www.bilibili.com/

HTTP/1.1 301 Moved Permanently
Server: Tengine
Date: Wed, 28 Aug 2024 05:30:47 GMT
Content-Type: text/html
Content-Length: 239
Connection: keep-alive
Location: https://www.bilibili.com/

HTTP/2 200 
date: Wed, 28 Aug 2024 05:30:48 GMT
content-type: text/html; charset=utf-8
support: nantianmen
cache-control: no-cache
expires: Wed, 28 Aug 2024 05:30:47 GMT
pragma: no-cache
vary: Origin,Accept-Encoding
x-cache-webcdn: MISS from blzone11
x-cache-time: 0
x-origin-time: no-store, no-cache, must-revalidate, private
x-save-date: Wed, 28 Aug 2024 05:30:48 GMT

curl抓取网页保存

下面是

复制代码
 curl -O https://www.baidu.com/index.html

还可以指定保存的名称:

复制代码
curl -o myhtml.html -O https://www.baidu.com/index.html

curl下载文件并且实现断点续传

还是curl -O而且比wget似乎更好用,能看到数据大小,已下载大小,总下载用时,已经用时,下载速度等等。中间可以按ctrl+c中断下载,接着继续执行该程序,会实现断点续传。注意使用参数-C。

复制代码
curl -o myiso.iso https://mirrors.iu13.net/centos-stream/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-dvd1.iso

下面是我在window本地尝试的结果,但是似乎和我想的不同,测试过服务器支持断点续传,不知道为什么总是从头开始,也许是我用ctrl+C有问题,我尝试断开网络。

使用官方用例仍然失败,只好暂且放弃。

curl限速2M下载

复制代码
curl --limit-rate 2M -O https://mirrors.cloud.tencent.com/tencentos/4.0/isos/x86_64/TencentOS-Server-4.0-everything-x86_64.iso

可以更改为对应速率,防止占满带宽。

scp命令

securecopy 用于将文件或者目录从一个linux系统复制到另外一个linux系统,使用的协议是ssh协议,保证了数据传输的安全性。格式为:

复制代码
scp remotename@remoteip:/etc/hisfile /var/myfile
scp /var/myupoadfile myfriend@hisip:/var/hisfile

分别是从远程下载和传送文件给远方服务器的命令例子注意文件路径是绝对路径。

这里我就不贴截图了,我经过尝试确实是可以的。

本地的a.txt上传到我们的服务器上啦!

如果要复制目录的话就要加上-r选项啦

复制代码
scp -r /mydir ubuntu@ip:/hisdir
scp -r ubuntu@ip:/hisdir /mydir 

ssh服务使用22端口,所以scp都是使用22端口,-P选项允许我们指定端口

复制代码
scp -P 2222 remotename@remoteip:/etc/hisfile /var/myfile

限速scp -l

复制代码
scp -l 10000 remotename@remoteip:/etc/hisfile /var/myfile

这里限速的单位是kbit,换算为KB要除以8.

动态路由追中及网络排障工具mtr命令

下载安装

复制代码
yum install mtr

ubuntu:

复制代码
apt-get install mtr

使用方法:mtr url(ip)

相关推荐
Nie_Xun34 分钟前
ubuntu网络共享
linux·运维·ubuntu
rannn_11138 分钟前
【MySQL学习|黑马笔记|Day7】触发器和锁(全局锁、表级锁、行级锁、)
笔记·后端·学习·mysql
花小璇学linux1 小时前
imx6ull-驱动开发篇22——Linux 时间管理和内核定时器
linux·运维·驱动开发
喜欢吃燃面1 小时前
C++算法竞赛:位运算
开发语言·c++·学习·算法
传奇开心果编程1 小时前
【传奇开心果系列】Flet框架实现的家庭记账本示例自定义模板
python·学习·ui·前端框架·自动化
草莓熊Lotso1 小时前
《详解 C++ Date 类的设计与实现:从运算符重载到功能测试》
开发语言·c++·经验分享·笔记·其他
你好,赵志伟3 小时前
Socket 编程 TCP
linux·服务器·tcp/ip
Liang_GaRy4 小时前
心路历程-三个了解敲开linux的大门
linux·运维·服务器
_Kayo_8 小时前
node.js 学习笔记3 HTTP
笔记·学习
一只栖枝8 小时前
华为 HCIE 大数据认证中 Linux 命令行的运用及价值
大数据·linux·运维·华为·华为认证·hcie·it