前言

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

快速上手Linux核心命令(八):网络相关命令-LMLPHP

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

1、简介

2、语法格式

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

3、参数说明

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

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、简介

2、语法格式

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

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

3、 参数说明

4、实践操作

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

[root@xiezhr ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.4  netmask 255.255.240.0  broadcast 172.17.15.255
        inet6 fe80::5054:ff:fe19:f6d0  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:19:f6:d0  txqueuelen 1000  (Ethernet)
        RX packets 254776100  bytes 26271134342 (24.4 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 331164543  bytes 72224346549 (67.2 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 143816  bytes 10756556 (10.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 143816  bytes 10756556 (10.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • eth0表示第一块网卡、第二块为eth1,依次类推;lo表示回环接口

②显示指定网卡eth0信息

[root@xiezhr ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.4  netmask 255.255.240.0  broadcast 172.17.15.255
        inet6 fe80::5054:ff:fe19:f6d0  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:19:f6:d0  txqueuelen 1000  (Ethernet)
        RX packets 254778009  bytes 26271295935 (24.4 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 331166449  bytes 72224671528 (67.2 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

③ 启动关闭网卡

# 关闭网卡
[root@xiezhr ~]# ifconfig eth0 down
# 启动网卡
[root@xiezhr ~]# ifconfig eth0 up

④ 设置网卡IP

[root@xiezhr ~] ifconfig eth0 192.168.205.98 

route 显示或管理路由表

1、简介

2、路由小科普

说到路由,不得不简单做下科普。这里只是简单通俗介绍一下,如果需要了解更多请查阅相关资料哈

路由表与生活中的路标指示牌类似,指示牌指引着我们该往什么地方走;而路由表则指引着数据包该去向何方。

快速上手Linux核心命令(八):网络相关命令-LMLPHP

不得不说技术源于生活,又服务于生活。

那么,两台计算机之间是怎么传输数据的呢?

  • 数据的传输必须要又网络来完成,而网络是由两台计算机之间一个或多个节点构成的
  • 数据传输由一台计算机传送到第一个网络节点,然后这个网络节点会根据“约定”将数据传宋到另一个网络节点,另一个网络节点再根据“约定”将数据传输到下一个节点,直到把数据传输到另一台计算机。 这里的“约定”就是我们上面说的路由表
  • 路由表说白了就是指定了一些规则,标明数据报文该何去何从
  • 路由分为静态路由和动态路由。
  • 我们通过route命令手动加入的路由属于静态路由;动态路由时无需手动加入的,其路由规则时不同计算机彼此相互交换路由规则而来的

3、语法格式

route [参数选项]

4、参数说明

5、实践操作

① 查看当前系统路由表信息

[root@xiezhr ~]# route 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 eth0
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.17.0.0      0.0.0.0         255.255.240.0   U     0      0        0 eth0
  • Destination :网络号,也就是network的意思
  • Gateway:连出网关地址,也就是说该网络时通过该IP连接出去的,0.0.0.0,则表示该路由直接由本机传送出去。如果由具体IP,表示本条路由必须经过该IP转接才能连接出去
  • Genmask:表示子网掩码
  • Flags:路由标记信息
    • U :表示此路由当前为启动状态
    • H:目标路由是一个主机(IP)而非网络
    • R:使用动态路由时,恢复路由信息标识
    • G:表示他需要通过外部的注解来转接传递数据
    • M:表示路由已经被修改
    • D:已经由服务设定为动态路由
  • Metric :表示需要经过几个网络节点才能到达路由的目标网络地址
  • Ref:参考到此路由规则的数目
  • Use:有几个转送数据包参考到了此路由规则
  • Iface:路由对应的网络设备接口

② 添加或删除路由

# 删除默认网关方法1
[root@xiezhr ~]# route del default
# 删除默认网关方法2
[root@xiezhr ~]# route del default gw 10.0.0.2
# 添加网关
[root@xiezhr ~]# route add default gw 10.0.0.2 dev eth0

netstat 查看网络状况

1、简介

2、语法格式

netstat [参数选项]

3、参数说明

4、实践操作

① 显示详细的所有连接信息

[root@xiezhr ~]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp        0      0 172.17.0.4:80           103.127.81.10:33832     SYN_RECV   
tcp        0      0 172.17.0.4:80           154.221.22.70:44617     SYN_RECV   
tcp        0      0 172.17.0.4:80           103.195.150.7:31982     SYN_RECV 
。。。
udp        0      0 0.0.0.0:68              0.0.0.0:*                          
udp        0      0 172.17.0.4:123          0.0.0.0:*                          
udp        0      0 127.0.0.1:123           0.0.0.0:*                          
udp6       0      0 fe80::5054:ff:fe19::123 :::*                               
udp6       0      0 ::1:123                 :::*                               
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     12804    /var/run/lsm/ipc/simc
unix  2      [ ACC ]     STREAM     LISTENING     12810    /var/run/lsm/ipc/sim

简单说明下上面显示内容的含义

② 显示所有TCP、UDP正在监听的连接信息

[root@xiezhr ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2812/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      980/sshd            
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      2812/nginx: master  
tcp        0      0 0.0.0.0:65535           0.0.0.0:*               LISTEN      17087/./proc        
tcp6       0      0 :::80                   :::*                    LISTEN      2812/nginx: master  
tcp6       0      0 :::3000                 :::*                    LISTEN      27339/PM2 v4.5.1: G 
tcp6       0      0 :::443                  :::*                    LISTEN      2812/nginx: master  
udp        0      0 0.0.0.0:68              0.0.0.0:*                           809/dhclient        
udp        0      0 172.17.0.4:123          0.0.0.0:*                           546/ntpd            
udp        0      0 127.0.0.1:123           0.0.0.0:*                           546/ntpd            
udp6       0      0 fe80::5054:ff:fe19::123 :::*                                546/ntpd            
udp6       0      0 ::1:123                 :::*                                546/ntpd 

③ 显示当前系统的路由表

[root@xiezhr ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         172.17.0.1      0.0.0.0         UG        0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
172.17.0.0      0.0.0.0         255.255.240.0   U         0 0          0 eth0

④ 显示网络的接口状况

[root@xiezhr ~]# netstat -i
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0             1500 257171559      0      0 0      334662383      0      0      0 BMRU
lo              65536   144476      0      0 0        144476      0      0      0 LRU

telnet 远程登录主机

1、简介

2、语法格式

telnet [参数选项] [主机名或IP] [端口]

3、实际操作

①测试端口是否开放

[root@xiezhr ~]# telnet 112.112.17.172 31189

ssh 安全的远程登录主机

1、简介

2、语法格式

ssh [参数选项] [用户名@] [主机名或IP地址] [远程执行的名]

3、参数说明

4、实践操作

① 远程登录服务器

[root@xiezhr ~]# ssh 220.165.5.45

②远程执行命令

[root@xiezhr ~]# ssh 10.0.0.26 "free -m"

wget 命令行下载工具

1、简介

  • 支持断点下载
  • 支持ftp和http下载方式
  • 支持代理服务器
  • 非常稳定。如果由于网络原因下载失败,wget 会不断尝试,直到整个文件下载完毕。如果服务器打断了下载过程,当再次连接服务器时,会从停止的地方继续下载。【这对下载大文件非常有用】

2、语法格式

wget [参数选项] [下载地址]

3、参数说明

4、实践操作

① wget下载单个文件

[root@xiezhr /]# wget https://xiezhrspace.cn/medias/logo.png
--2022-05-30 23:08:24--  https://xiezhrspace.cn/medias/logo.png
Resolving xiezhrspace.cn (xiezhrspace.cn)... ::1, ::1
Connecting to xiezhrspace.cn (xiezhrspace.cn)|::1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 112674 (110K) [image/png]
Saving to: ‘logo.png’

100%[========================================================================================================================================================================>] 112,674     --.-K/s   in 0s      

2022-05-30 23:08:24 (433 MB/s) - ‘logo.png’ saved [112674/112674]

②使用-O参数,指定下载文件的保存文件名

[root@xiezhr test]# wget -O /home/test/logo.png https://www.xiezhrspace.cn/medias/logo.png
--2022-05-30 23:14:03--  https://www.xiezhrspace.cn/medias/logo.png
Resolving www.xiezhrspace.cn (www.xiezhrspace.cn)... 42.192.46.248
Connecting to www.xiezhrspace.cn (www.xiezhrspace.cn)|42.192.46.248|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 112674 (110K) [image/png]
Saving to: ‘/home/test/logo.png’

100%[========================================================================================================================================================================>] 112,674     --.-K/s   in 0.01s   

2022-05-30 23:14:03 (9.78 MB/s) - ‘/home/test/logo.png’ saved [112674/112674]

[root@xiezhr test]# cd /home/test/
[root@xiezhr test]# ll
total 208
-rw-r--r-- 1 root   root   112674 Nov 29  2020 logo.png

③ 限速3kb/s下载

[root@xiezhr test]# wget --limit-rate=3k https://www.xiezhrspace.cn/medias/logo.png
--2022-05-30 23:15:57--  https://www.xiezhrspace.cn/medias/logo.png
Resolving www.xiezhrspace.cn (www.xiezhrspace.cn)... 42.192.46.248
Connecting to www.xiezhrspace.cn (www.xiezhrspace.cn)|42.192.46.248|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 112674 (110K) [image/png]
Saving to: ‘logo.png.1’

100%[========================================================================================================================================================================>] 112,674     3.00KB/s   in 37s    

2022-05-30 23:16:34 (3.00 KB/s) - ‘logo.png.1’ saved [112674/112674]

④ 断点续传下载大文件

[root@xiezhr test]# wget -c https://mirrors.aliyun.com/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1611.iso

⑤后台下载文件

[root@xiezhr test]# wget -b https://www.xiezhrspace.cn/medias/logo.png
Continuing in background, pid 4526.
Output will be written to ‘wget-log’.

⑥ 有些网站会根据判断代理名称是不是浏览器而拒绝你的下载请求,这时候就可以伪装代理下载

[root@xiezhr test]# wget -b https://www.xiezhrspace.cn/medias/logo.png
Continuing in background, pid 4526.
Output will be written to ‘wget-log’.
[root@xiezhr test]# clear
[root@xiezhr test]# wget --user-agent="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36" https://www.xiezhrspace.cn/medias/logo.png
--2022-05-30 23:29:27--  https://www.xiezhrspace.cn/medias/logo.png
Resolving www.xiezhrspace.cn (www.xiezhrspace.cn)... 42.192.46.248
Connecting to www.xiezhrspace.cn (www.xiezhrspace.cn)|42.192.46.248|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 112674 (110K) [image/png]
Saving to: ‘logo.png.3’

100%[========================================================================================================================================================================>] 112,674     --.-K/s   in 0.01s   

2022-05-30 23:29:27 (9.85 MB/s) - ‘logo.png.3’ saved [112674/112674]

⑦ 监控网站URL是否正常

# 采用静默方式访问网站,3秒超时,重试1次,模拟爬虫方式进行访问
[root@xiezhr test]# wget -q -T 3 --tries=1 --spider www.xiezhrspace.cn
# 返回0表示正常
[root@xiezhr test]# echo $?
0

ip网络配置工具

1、简介

2、语法格式

ip [参数选项] [网络对象] [操作命令]

3、参数说明

3、网络对象及对应操作命令

4、实践操作

ip link show                     # 显示网络接口信息
ip link set eth0 up             # 开启网卡
ip link set eth0 down            # 关闭网卡
ip link set eth0 promisc on      # 开启网卡的混合模式
ip link set eth0 promisc offi    # 关闭网卡的混个模式
ip link set eth0 txqueuelen 1200 # 设置网卡队列长度
ip link set eth0 mtu 1400        # 设置网卡最大传输单元
ip addr show     # 显示网卡IP信息
ip addr add 192.168.0.1/24 dev eth0 # 设置eth0网卡IP地址192.168.0.1
ip addr del 192.168.0.1/24 dev eth0 # 删除eth0网卡IP地址

ip route show # 显示系统路由
ip route add default via 192.168.1.254   # 设置系统默认路由
ip route list                 # 查看路由信息
ip route add 192.168.4.0/24  via  192.168.0.254 dev eth0 # 设置192.168.4.0网段的网关为192.168.0.254,数据走eth0接口
ip route add default via  192.168.0.254  dev eth0        # 设置默认网关为192.168.0.254
ip route del 192.168.4.0/24   # 删除192.168.4.0网段的网关
ip route del default          # 删除默认路由
ip route delete 192.168.1.0/24 dev eth0 # 删除路由

tcpdump 监听网络流量

1、简介

2、语法格式

tcpdump [参数选项] [表达式]

3、参数说明

4、实践操作

① 不带参数监听网络

[root@xiezhr ~]# tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
21:49:34.194426 IP xiezhr.ssh > 39.130.60.147.54868: Flags [P.], seq 2354337386:2354337582, ack 602321997, win 255, length 196
21:49:34.194837 IP xiezhr.55410 > 183.60.82.98.domain: 13037+ PTR? 147.60.130.39.in-addr.arpa. (44)
21:49:34.241013 IP 39.130.60.147.54868 > xiezhr.ssh: Flags [.], ack 0, win 511, length 0
21:49:34.260399 IP 183.60.82.98.domain > xiezhr.55410: 13037 NXDomain 0/1/0 (93)
21:49:34.261639 IP xiezhr.44621 > 183.60.83.19.domain: 25778+ PTR? 4.0.17.172.in-addr.arpa. (41)
21:49:34.262436 IP 183.60.83.19.domain > xiezhr.44621: 25778 NXDomain 0/1/0 (100)

② 精简输出信息

[root@xiezhr ~]# tcpdump -q
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
21:51:39.084015 IP xiezhr.ssh > 39.130.60.147.54868: tcp 196
21:51:39.084415 IP xiezhr.54183 > 183.60.83.19.domain: UDP, length 44
21:51:39.084690 IP 183.60.83.19.domain > xiezhr.54183: UDP, length 93
21:51:39.095563 IP xiezhr.37447 > 183.60.82.98.domain: UDP, length 41
21:51:39.095795 IP 183.60.82.98.domain > xiezhr.37447: UDP, length 100
21:51:39.107963 IP xiezhr.57539 > 183.60.83.19.domain: UDP, length 43
21:51:39.108025 IP xiezhr.ssh > 39.130.60.147.54868: tcp 100
21:51:39.108749 IP 183.60.83.19.domain > xiezhr.57539: UDP, length 107
21:51:39.118945 IP xiezhr.51494 > 183.60.82.98.domain: UDP, length 43
21:51:39.119024 IP xiezhr.ssh > 39.130.60.147.54868: tcp 180
21:51:39.119165 IP 183.60.82.98.domain > xiezhr.51494: UDP, length 107
21:51:39.130005 IP xiezhr.ssh > 39.130.60.147.54868: tcp 596
21:51:39.130036 IP xiezhr.ssh > 39.130.60.147.54868: tcp 100

③监听指定网卡收到的数据包

[root@xiezhr ~]# tcpdump -i eth0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
21:52:41.482275 IP 169.254.0.4.http > xiezhr.45330: Flags [.], ack 31739111, win 136, length 0
21:52:41.486536 IP xiezhr.48369 > 183.60.82.98.domain: 56337+ PTR? 4.0.17.172.in-addr.arpa. (41)
^C21:52:41.487054 IP xiezhr.ssh > 39.130.60.147.54868: Flags [P.], seq 2354686734:2354686930, ack 602325169, win 255, length 196

④ 监听指定主机数据包

[root@xiezhr ~]# tcpdump -n host 220.165.5.50 
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes

⑤ 监听指定端口数据包

[root@xiezhr ~]# tcpdump -nn port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
21:54:39.961652 IP 172.17.0.4.22 > 39.130.60.147.54868: Flags [P.], seq 2354867994:2354868190, ack 602329953, win 255, length 196
21:54:39.961828 IP 172.17.0.4.22 > 39.130.60.147.54868: Flags [P.], seq 196:376, ack 1, win 255, length 180
21:54:39.961860 IP 172.17.0.4.22 > 39.130.60.147.54868: Flags [P.], seq 376:524, ack 1, win 255, length 148
21:54:39.961888 IP 172.17.0.4.22 > 39.130.60.147.54868: Flags [P.], seq 524:672, ack 1, win 255, length 148
21:54:39.961916 IP 172.17.0.4.22 > 39.130.60.147.54868: Flags [P.], seq 672:820, ack 1, win 255, length 148
21:54:39.961943 IP 172.17.0.4.22 > 39.130.60.147.54868: Flags [P.], seq 820:968, ack 1, win 255, length 148
21:54:39.961971 IP 172.17.0.4.22 > 39.130.60.147.54868: Flags [P.], seq 968:1116, ack 1, win 255, length 148
21:54:39.961998 IP 172.17.0.4.22 > 39.130.60.147.54868: Flags [P.], seq 1116:1264, ack 1, win 255, length 148

nmap 网络探测工具和安全/端口扫描器

1、简介

如果系统没有nmap命令,可通过一下命令安装

yum -y install nmap

2、语法格式

nmap [扫描类型] [通用选项] [扫描目标]

3、参数说明

4、实践操作

① 查看主机当前开放的端口

[root@xiezhr ~]# nmap 127.0.0.1 

②扫描主机的指定端口

[root@xiezhr ~]#  nmap -p 1024-65535 127.0.0.1

③扫描局域网内所有IP

[root@xiezhr ~]# nmap 10.0.0.0/24

ifup 激活网络接口

1、简介

2、语法格式

ifup [网络接口]

3、实践操作

激活网络接口

[root@xiezhr ~]# ifup eht0

ifdown 禁用网络接口

1、简介

2、语法格式

ifdown [网络接口]

3、实践操作

禁用网络接口

[root@xiezhr ~]# ifdown eht1

arp 管理系统的arp缓存

1、简介

2、语法格式

arp [参数选项]

3、参数说明

4、实践操作

① 显示arp缓存区的所有条目

[root@xiezhr ~]# arp
Address                  HWtype  HWaddress           Flags Mask            Iface
169.254.0.79             ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.128.6            ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.0.4              ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.128.4            ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.0.2              ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.0.15             ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.0.55             ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.0.81             ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.0.82             ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.0.83             ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.0.80             ether   fe:ee:00:2e:16:9a   C                     eth0
172.17.0.5               ether   fe:ee:00:2e:16:9a   C                     eth0
gateway                  ether   fe:ee:00:2e:16:9a   C                     eth0
169.254.0.23             ether   fe:ee:00:2e:16:9a   C                     eth0

② 查询指定主机的arp条目

[root@xiezhr ~]# arp -n 42.192.46.248
42.192.46.248 (42.192.46.248) -- no entrys

③ 静态绑定IP地址与MAC地址

[root@xiezhr ~]#  arp -s 10.0.0.100 00:0c:29:c0:5e:df

ss 查看网络状况

1、简介

如果系统没有该命令,需要自己安装一下

yum -y install iproute

2、语法格式

ss [参数选项] [过滤器]

3、参数说明

4、实践操作

① 显示所有的socket连接

  [root@xiezhr ~]# ss -an
Netid  State      Recv-Q Send-Q        Local Address:Port       Peer Address:Port              
nl     UNCONN     0      0                         0:0                      *                   
nl     UNCONN     0      0                         0:546                    *                   
nl     UNCONN     0      0                         0:546                    *                   
nl     UNCONN     4352   0                         4:30221                  *                   
nl     UNCONN     768    0                         4:0                      *                   
nl     UNCONN     0      0                         6:0                          

② 显示所有正在监听的TCP和UDP连接

Netid  State   Recv-Q  Send-Q  Local                               Address:Port  Peer                                                      Address:Port
udp    UNCONN  0       0       *:68                                *:*           users:(("dhclient",pid=809,fd=6))
udp    UNCONN  0       0       172.17.0.4:123                      *:*           users:(("ntpd",pid=546,fd=19))
udp    UNCONN  0       0       127.0.0.1:123                       *:*           users:(("ntpd",pid=546,fd=16))
udp    UNCONN  0       0       [fe80::5054:ff:fe19:f6d0]%eth0:123  [::]:*        users:(("ntpd",pid=546,fd=20))
udp    UNCONN  0       0       [::1]:123                           [::]:*        users:(("ntpd",pid=546,fd=17))
tcp    LISTEN  0       128     *:80                                *:*           users:(("nginx",pid=26238,fd=6),("nginx",pid=2812,fd=6))
tcp    LISTEN  0       128     *:22                                *:*           users:(("sshd",pid=980,fd=3))
tcp    LISTEN  0       128     *:443                               *:*           users:(("nginx",pid=26238,fd=8),("nginx",pid=2812,fd=8))
tcp    LISTEN  0       1       *:65535                             *:*           users:(("proc",pid=17087,fd=3))
tcp    LISTEN  0       128     [::]:80                             [::]:*        users:(("nginx",pid=26238,fd=7),("nginx",pid=2812,fd=7))
tcp    LISTEN  0       128     [::]:3000                           [::]:*        users:(("PM2                                              v4.5.1:       God",pid=27339,fd=20))
tcp    LISTEN  0       128     [::]:443                            [::]:*        users:(("nginx",pid=26238,fd=9),("nginx",pid=2812,fd=9))

nc 多功能网络工具

1、简介

如果系统没有nc命令,可以通过一下命令手动安装

yum -y install nc

2、语法格式

nc [参数选项]

3、参数说明

4、实践操作

①TCP端口扫描

[root@xiezhr ]# nc -v -z -w2 192.168.0.3 1-100 
192.168.0.3: inverse host lookup failed: Unknown host
(UNKNOWN) [192.168.0.3] 80 (http) open
(UNKNOWN) [192.168.0.3] 23 (telnet) open
(UNKNOWN) [192.168.0.3] 22 (ssh) open

②扫描指定端口

[root@xiezhr ~]# nc -nvv 192.168.0.1 80 //扫描 80端口
(UNKNOWN) [192.168.0.1] 80 (?) open
y  //用户输入

mail 发送和接收文件

1、简介

2、语法格式

mail [参数选项]

3、参数说明

nslookup 域名查询工具

1、简介

如果系统没有该命令,需要按照以下方式自己安装下

yum -y install bind-utils

2、语法格式

nslookup [参数选项] [域名/IP] [DNS服务器]

3、参数说明

dig 域名查询工具

1、简介

2、语法格式

dig [参数选项]

3、参数说明

4、实践操作

① 查询指定域名的IP地址

[root@xiezhr init.d]# dig www.xiezhrspace.cn

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-16.P2.el7_8.6 <<>> www.xiezhrspace.cn
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43520
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.xiezhrspace.cn.            IN      A

;; ANSWER SECTION:
www.xiezhrspace.cn.     600     IN      A       42.192.46.248

;; Query time: 76 msec
;; SERVER: 183.60.82.98#53(183.60.82.98)
;; WHEN: Fri Jun 03 09:28:46 CST 2022
;; MSG SIZE  rcvd: 52

② 查询MX类型的域名信息

[root@xiezhr init.d]# dig -t MX www.xiezhrspce.cn

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-16.P2.el7_8.6 <<>> -t MX www.xiezhrspce.cn
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 62926
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;www.xiezhrspce.cn.             IN      MX

;; AUTHORITY SECTION:
cn.                     594     IN      SOA     a.dns.cn. root.cnnic.cn. 2029763095 7200 3600 2419200 21600

;; Query time: 76 msec
;; SERVER: 183.60.82.98#53(183.60.82.98)
;; WHEN: Fri Jun 03 09:29:54 CST 2022
;; MSG SIZE  rcvd: 88

③ 显示完整DNS解析过程

[root@xiezhr init.d]# dig @223.5.5.5 www.xiezhrspace.cn +trace

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-16.P2.el7_8.6 <<>> @223.5.5.5 www.xiezhrspace.cn +trace
; (1 server found)
;; global options: +cmd
.                       3323    IN      NS      k.root-servers.net.
.                       3323    IN      NS      g.root-servers.net.
.                       3323    IN      NS      m.root-servers.net.
.                       3323    IN      NS      f.root-servers.net.
.                       3323    IN      NS      c.root-servers.net.
.                       3323    IN      NS      e.root-servers.net.
.                       3323    IN      NS      d.root-servers.net.
.                       3323    IN      NS      l.root-servers.net.
.                       3323    IN      NS      i.root-servers.net.
...

host 域名查询工具

1、简介

2、语法格式

host [参数选项]

3、参数说明

4、实践操作

① DNS查询

[root@xiezhr init.d]# host www.xiezhrspace.cn
www.xiezhrspace.cn has address 42.192.46.248

② 查询详细信息

[root@xiezhr init.d]# host -a www.xiezhrspace.cn
Trying "www.xiezhrspace.cn"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41474
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.xiezhrspace.cn.            IN      ANY

;; ANSWER SECTION:
www.xiezhrspace.cn.     600     IN      A       42.192.46.248

Received 52 bytes from 183.60.82.98#53 in 65 ms

这期主要是说了Linux系统网络相关命令,大概内容就这些了。下期根据思维导图就到了文件备份与压缩相关的命令了。这些命令呢比较基础,但也是比较重要的

涉及到的命令有: tar、gzip、zip、unzip、scp、rsync等等

敬请期待哦(●’◡’●)

专栏目录:快速上手Linux核心命令专栏目录

上一篇:快速上手Linux核心命令(七):Linux系统信息相关命令x
下一篇:快速上手Linux核心命令(九):文件备份与压缩命令(博主正在玩命更新中)

05-08 12:27