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)

相关推荐
板栗妖怪1 小时前
内网穿透之EW使用、判断服务器是否出网
学习·内网渗透
Hadoop_Liang2 小时前
xshell密钥方式连接阿里云Linux
linux·阿里云·云计算
ersaijun3 小时前
【Obsidian】当笔记接入AI,Copilot插件推荐
人工智能·笔记·copilot
CS_素锦少年4 小时前
Linux_kernel驱动开发11
linux·运维·驱动开发
纪伊路上盛名在5 小时前
商务办公tips2:如何获取网页内嵌pdf文件
学习·搜索引擎·pdf·学习方法·everything
结衣结衣.5 小时前
Linux——进程状态
linux·运维·服务器·c语言·笔记·学习
好奇龙猫5 小时前
【诉讼流程-健身房-违约认定-私教课-诉讼书前提材料整理-民事诉讼-自我学习-铺平通往法律的阶梯-讲解(2)】
学习·其他
云边有个稻草人5 小时前
【刷题】Day4--密码检查
开发语言·数据结构·笔记·算法
li星野5 小时前
面试问题001
linux·开发语言·面试
blaizeer5 小时前
Linux 入门:简单的基础操作
linux·运维·服务器