Linux—MISC(中)
网络请求和下载
ping命令

btc@btc:~$ ping baidu.com
PING baidu.com (111.63.65.247) 56(84) bytes of data.
64 bytes from 111.63.65.247: icmp_seq=1 ttl=128 time=16.7 ms
64 bytes from 111.63.65.247: icmp_seq=2 ttl=128 time=16.8 ms
64 bytes from 111.63.65.247: icmp_seq=3 ttl=128 time=16.8 ms
64 bytes from 111.63.65.247: icmp_seq=4 ttl=128 time=16.7 ms
64 bytes from 111.63.65.247: icmp_seq=5 ttl=128 time=16.5 ms
64 bytes from 111.63.65.247: icmp_seq=6 ttl=128 time=16.7 ms
64 bytes from 111.63.65.247: icmp_seq=7 ttl=128 time=16.6 ms
64 bytes from 111.63.65.247: icmp_seq=8 ttl=128 time=16.9 ms
64 bytes from 111.63.65.247: icmp_seq=9 ttl=128 time=16.4 ms
64 bytes from 111.63.65.247: icmp_seq=10 ttl=128 time=16.6 ms
64 bytes from 111.63.65.247: icmp_seq=11 ttl=128 time=16.8 ms
64 bytes from 111.63.65.247: icmp_seq=12 ttl=128 time=16.7 ms
64 bytes from 111.63.65.247: icmp_seq=13 ttl=128 time=16.9 ms
64 bytes from 111.63.65.247: icmp_seq=14 ttl=128 time=16.7 ms
64 bytes from 111.63.65.247: icmp_seq=15 ttl=128 time=16.8 ms
^C
--- baidu.com ping statistics ---
15 packets transmitted, 15 received, 0% packet loss, time 14022ms
rtt min/avg/max/mdev = 16.434/16.706/16.876/0.118 ms
#说明我们与baidu.com是联通的
#添加次数选项参数
btc@btc:~$ ping -c 3 baidu.com
PING baidu.com (110.242.74.102) 56(84) bytes of data.
64 bytes from 110.242.74.102: icmp_seq=1 ttl=128 time=28.5 ms
64 bytes from 110.242.74.102: icmp_seq=2 ttl=128 time=29.7 ms
--- baidu.com ping statistics ---
3 packets transmitted, 2 received, 33.3333% packet loss, time 2004ms
rtt min/avg/max/mdev = 28.533/29.092/29.651/0.559 ms
wget命令

btc@btc:~$ wget http://archive.apache.org/dist/hadoop/common/hadoop-3.3.0/hadoop-3.3.0.tar.gz
--2026-01-21 19:50:05-- http://archive.apache.org/dist/hadoop/common/hadoop-3.3.0/hadoop-3.3.0.tar.gz
正在解析主机 archive.apache.org (archive.apache.org)... 65.108.204.189, 2a01:4f9:1a:a084::2
正在连接 archive.apache.org (archive.apache.org)|65.108.204.189|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 500749234 (478M) [application/x-gzip]
正在保存至: ‘hadoop-3.3.0.tar.gz’
hadoop-3.3.0.tar.gz 0%[ ] 4.32M 146KB/s 剩余 65m 22s^C
btc@btc:~$ ls
1.txt 公共 模板 视频 图片 文档 下载 音乐 桌面 hadoop-3.3.0.tar.gz snap
btc@btc:~$ rm -f hadoop-3.3.0.tar.gz
btc@btc:~$ ls
1.txt 公共 模板 视频 图片 文档 下载 音乐 桌面 snap
curl命令


btc@btc:~$ curl baidu.com
Caution: You are using the Snap version of curl.
Due to Snap's sandbox nature, this version has some limitations.
For example, it may not be able to access hidden folders in your home directory
or other restricted areas of the os.
Which means you may encounter errors when using snap curl to download and execute some script.
For those cases, you might want to use the native curl package.
For details, see: https://github.com/boukendesho/curl-snap/issues/1
To stop seeing this message, run the following command:
$ curl.snap-acked
<a href="http://www.baidu.com/">Moved Permanently</a>.
#向cip.cc发送请求获取公网IP地址
btc@btc:~$ curl cip.cc
Caution: You are using the Snap version of curl.
Due to Snap's sandbox nature, this version has some limitations.
For example, it may not be able to access hidden folders in your home directory
or other restricted areas of the os.
Which means you may encounter errors when using snap curl to download and execute some script.
For those cases, you might want to use the native curl package.
For details, see: https://github.com/boukendesho/curl-snap/issues/1
To stop seeing this message, run the following command:
$ curl.snap-acked
IP : 111.16.56.104
地址 : 中国 山东 临沂
运营商 : 移动
数据二 : 中国山东临沂 | 移动
数据三 : 中国山东省临沂市 | 移动
URL : http://www.cip.cc/111.16.56.104
小结:

网络传输
端口

虚拟端口

计算机可以通过IP地址找到对应的主机,但是无法锁定具体的程序,这便是端口发挥作用的地方
IP地址相当于小区地址,在小区之间可以有许多住户(程序)而门牌号(端口)就是各个住户(程序)的联系地址

查看端口占用

root@btc:~# nmap 127.0.0.1
Starting Nmap 7.94SVN ( https://nmap.org ) at 2026-01-21 23:22 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000020s latency).
Not shown: 998 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
631/tcp open ipp
Nmap done: 1 IP address (1 host up) scanned in 0.21 seconds
可以看到,本机(127.0.0.1)上有2个端口现在被程序占用了

root@btc:~# netstat -anp | grep 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1/init
tcp 0 0 192.168.238.128:22 192.168.238.1:58919 ESTABLISHED 25401/sshd: btc [pr
tcp6 0 0 :::22 :::* LISTEN 1/init
unix 3 [ ] 流 已连接 10222 1/init /run/systemd/journal/stdout
unix 3 [ ] 流 已连接 85424 2299/Xwayland @/tmp/.X11-unix/X0
unix 3 [ ] 流 已连接 17634 2299/Xwayland @/tmp/.X11-unix/X0
...
unix 3 [ ] 流 已连接 15922 1594/pipewire
unix 3 [ ] 流 已连接 9177 1122/rsyslogd
unix 2 [ ACC ] 流 LISTENING 16213 2299/Xwayland @/tmp/.X11-unix/X0
unix 2 [ ACC ] 流 LISTENING 16215 2299/Xwayland @/tmp/.X11-unix/X1
**除了查看指定端口的占用情况,还可以查看指定名称占用端口的情况 **
root@btc:~# netstat -anp | grep socket
unix 3 [ ] 流 已连接 16716 1081/snapd /run/snapd-snap.socket
unix 3 [ ] 流 已连接 11293 1049/@dbus-daemon /run/dbus/system_bus_socket
unix 3 [ ] 流 已连接 17708 1049/@dbus-daemon /run/dbus/system_bus_socket
...
unix 3 [ ] 流 已连接 15980 1049/@dbus-daemon /run/dbus/system_bus_socket
unix 3 [ ] 流 已连接 16452 1049/@dbus-daemon /run/dbus/system_bus_socket
unix 3 [ ] 流 已连接 9127 1049/@dbus-daemon /run/dbus/system_bus_socket
unix 3 [ ] 流 已连接 13174 1049/@dbus-daemon /run/dbus/system_bus_socket
unix 3 [ ] 流 已连接 17615 1049/@dbus-daemon /run/dbus/system_bus_socket
root@btc:~#
小结:


浙公网安备 33010602011771号