设为首页 加入收藏

TOP

快速上手Linux核心命令(八):网络相关命令(一)
2023-07-23 13:32:58 】 浏览:110
Tags:Linux 相关命

前言

这期呢主要说一说Linux中与网络相关命令,一共包含19个命令

测试主机之间网络是否联通

1、简介

ping 命令不管是在Windows还是Linux都是比较常用的命令。命令用于测试主机之间的网络连通性

2、语法格式

ping [参数选项] [目标主机]

3、参数说明

参数 参数说明
-c 指定报文次数,若不指定,ping命令将一直发送报文
-i 相邻两次发送报文的时间间隔,默认时间间隔是1s
-s 设置发送数据包大小,默认为56字节,加上8字节ICMP头,共64字节数据包

还有其他的参数,这里就不一一列举了。。。。

4、实践操作

①测试与目标主机的网络连通性

# 网络正常情况
[root@xiezhr ~]# ping www.xiezhrspace.cn
PING www.xiezhrspace.cn (42.192.46.248) 56(84) bytes of data.
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=1 ttl=63 time=0.233 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=2 ttl=63 time=0.215 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=3 ttl=63 time=0.230 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=4 ttl=63 time=0.235 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=5 ttl=63 time=0.235 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=6 ttl=63 time=0.246 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=7 ttl=63 time=0.243 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=8 ttl=63 time=0.215 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=9 ttl=63 time=0.227 ms

# 网络不正常
[root@xiezhr ~]# ping 10.10.114.56
PING 10.10.114.56 (10.10.114.56) 56(84) bytes of data.

上面命令执行后会一直发送报文,相当于windows中的ping www.baidu.com -t

② 指定发送报文的次数

# 发送报文4次后自动退出
[root@xiezhr ~]# ping -c 4 www.xiezhrspace.cn
PING www.xiezhrspace.cn (42.192.46.248) 56(84) bytes of data.
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=1 ttl=63 time=0.230 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=2 ttl=63 time=0.248 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=3 ttl=63 time=0.226 ms
64 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=4 ttl=63 time=0.214 ms

--- www.xiezhrspace.cn ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3021ms
rtt min/avg/max/mdev = 0.214/0.229/0.248/0.019 ms

③ 多参数使用情况

[root@xiezhr ~]# ping -c 4 -i 3 -s 1024 -t 255 www.xiezhrspace.cn
PING www.xiezhrspace.cn (42.192.46.248) 1024(1052) bytes of data.
1032 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=1 ttl=63 time=0.214 ms
1032 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=2 ttl=63 time=0.250 ms
1032 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=3 ttl=63 time=0.226 ms
1032 bytes from 42.192.46.248 (42.192.46.248): icmp_seq=4 ttl=63 time=0.261 ms

--- www.xiezhrspace.cn ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 9027ms
rtt min/avg/max/mdev = 0.214/0.237/0.261/0.026 ms

上面列子中参数解释

  • -c 4 : 发送4次报文
  • -i 3:每隔3s发送一次报文
  • -s 1024: 每次发送数据报文大小为1024字节
  • -t 255: **发送数据包的ttl值为255 **

ifconfig 配置或显示网络信息

1、简介

ifconfig 命令类似于Windows 下的ipconfig 。不知道大家会不会混淆在一起,反正我是经常混淆了在一起(●'?'●)。命令用于显示网卡IP地址等参数信息

2、语法格式

ifconfig [网路接口] [参数选项]

网络接口指的是:eth0、eth1和lo 分别表示第一块网卡、第二块网卡和回环接口。该选项是非必填项

3、 参数说明

参数 参数说明
-a 显示所有网络接口信息,包括活动的和非活动的
-up 激活指定网络接口
-down 关闭指定网络接口
hw 设置网络接口的物理地址(MAC地址)

4、实践操作

①显示当前系统开启的所有网络接口信息

[root@xiezhr ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 150
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 1/8/8
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇RPM常用命令以及组合使用场景 下一篇Linux 内存管理 pt.1

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目