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 小时前
29.4k!使用 1Panel 来管理你的服务器吧
linux·运维
静心问道1 小时前
XLSR-Wav2Vec2:用于语音识别的无监督跨语言表示学习
人工智能·学习·语音识别
帽儿山的枪手1 小时前
为什么Linux需要3种NAT地址转换?一探究竟
linux·网络协议·安全
shadon1789 天前
回答 如何通过inode client的SSLVPN登录之后,访问需要通过域名才能打开的服务
linux
小米里的大麦9 天前
014 Linux 2.6内核进程调度队列(了解)
linux·运维·驱动开发
算法练习生9 天前
Linux文件元信息完全指南:权限、链接与时间属性
linux·运维·服务器
忘了ʷºᵇₐ9 天前
Linux系统能ping通ip但无法ping通域名的解决方法
linux·服务器·tcp/ip
浩浩测试一下9 天前
渗透测试指南(CS&&MSF):Windows 与 Linux 系统中的日志与文件痕迹清理
linux·运维·windows·安全·web安全·网络安全·系统安全
敏叔V5879 天前
大模型Text2SQL之在CentOS上使用yum安装与使用MySQL
linux·mysql·centos
懒惰的bit9 天前
STM32F103C8T6 学习笔记摘要(四)
笔记·stm32·学习