1. 查看本机公网IP 1.1 curl ifconfig.me 1.2 ipinfo.io 1.3 test-ipv6.com 1.4 more 2. 查看本机IP,host 2.1 hostname 2.2 查看本机IP:ip 2.3 查看无线网连接信息:iw 2.4 实时查看网路连接信息:iftop 2.5 分类查看网络连接信息:ss 3. 测试与外部的连通 3.1 telnet {host} {port} 3.2 nc -vz {host} {port} 3.3 nmap -p {port} {host} 3.4 sudo nping --tcp -p {port} {host} 3.5 wget www.baidu.com 3.6 curl 4. speedtest 5. more
1. 查看本机公网IP
1.1 curl ifconfig.me
https://ifconfig.me/
Command Line Interface
- $ curl ifconfig.me ⇒ 112.20.121.81
- $ curl ifconfig.me/ip ⇒ 112.20.121.81
- $ curl ifconfig.me/host ⇒ unavailable
- $ curl ifconfig.me/ua ⇒ Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36
- $ curl ifconfig.me/port ⇒ 43344
- $ curl ifconfig.me/lang ⇒ en,zh;q=0.9,en-US;q=0.8,zh-CN;q=0.7,zh-TW;q=0.6,zh-HK;q=0.5
- $ curl ifconfig.me/keepalive ⇒
- $ curl ifconfig.me/connection ⇒
- $ curl ifconfig.me/encoding ⇒ gzip, deflate, br
- $ curl ifconfig.me/mime ⇒ text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
- $ curl ifconfig.me/charset ⇒
- $ curl ifconfig.me/via ⇒ 1.1 google
- $ curl ifconfig.me/forwarded ⇒ 112.20.121.81, 216.239.38.21
or
- $ curl ifconfig.me/all
- $ curl ifconfig.me/all.xml
- $ curl ifconfig.me/all.json
1.2 ipinfo.io
https://ipinfo.io/
ip: "112.20.121.81"
city: "Suzhou"
region: "Jiangsu"
country: "CN"
loc: "31.3041,120.5954"
timezone: "Asia/Shanghai"
asn: Object
asn: "AS56046"
name: "China Mobile communications corporation"
domain: "chinamobile.com"
route: "112.20.96.0/19"
type: "isp"
company: Object
privacy: Object
vpn: false
proxy: false
tor: false
hosting: false
abuse: Object
address: "China Mobile Communications Corporation, 29, Jinrong Ave., Xicheng District, Beijing, 100032"
country: "CN"
email: "abuse@chinamobile.com"
name: "haijun li"
network: "112.0.0.0/10"
phone: "+86 1052686688"
1.3 test-ipv6.com
江苏 苏州 移动 | = 项目 = | (翻-) 日本 |
Your IPv4 address on the public Internet appears to be 112.20.121.81 | 公网 IPv4 地址 | 你的公网 IPv4 地址是 139.162.*.* |
公网 IPv6 地址 | 你的公网 IPv6 地址是 2400:8902::f03c:92ff:*:* | |
Your Internet Service Provider (ISP) appears to be CMNET-JIANGSU-AP China Mobile communications corporation | 运营商(ISP) | 你的运营商(ISP)是 LINODE-AP Linode, LLC |
Tests using this web site are unreliable from your location. 从您所在的位置使用该网站进行的测试不可靠。 |
||
No IPv6 address detected | 检测IPv6地址 ? | 你已接入 IPv6,因此我们增加了一个标签页,显示你能否访问其他 IPv6 网站。 |
You appear to be able to browse the IPv4 Internet only. You will not be able to reach IPv6-only sites. |
||
To ensure the best Internet performance and connectivity, ask your ISP about native IPv6. | ||
We are sometimes unable to detect Teredo and 6to4 when using HTTPS. | ||
HTTPS support on this web site is in beta. | HTTPS支持 | 本站的 HTTPS 功能正在开放测试。 |
Your DNS server (possibly run by your ISP) appears to have IPv6 Internet access. | DNS服务器 的 IPv6 状态 |
你的 DNS 服务器(可能由运营商提供)没有接入或没有配置 IPv6,将来这可能会妨碍你访问纯 IPv6 网站。 |
‘ 0/10 | IPv6 状况评分 | ‘ 9/10 |
https://test-ipv6.com/index.html.zh_CN
https://test-ipv6.com/index.html.en_US
右上角的翻译图标可以选择语言
https://test-ipv6.com/locale.html.zh_CN
https://test-ipv6.com/locale.html.en_US
1.4 more
https://www.whatismyip.com/
http://www.ip138.com/
2. 查看本机IP,host
2.1 hostname
$ hostname --h
-i, --ip-addresses addresses for the host name
-s, --short short host name
$ hostname -i
192.168.31.177
$ hostname -s
tompc
$ hostnamectl
Static hostname: tompc
Icon name: computer-laptop
Chassis: laptop
Machine ID: 213df5b115df44afa70277ddc24726ef
Boot ID: b23409079ab346719ec9f813d597e0dd
Operating System: Arch Linux
Kernel: Linux 5.5.4-arch1-1
Architecture: x86-64
2.2 查看本机IP:ip
ip address
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
...
2: enp0s25: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
...
3: wlp16s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
...
inet 192.168.31.177/24 brd 192.168.31.255 scope global dynamic noprefixroute wlp16s0
...
$ ip route get 8.8.8.8
8.8.8.8 via 192.168.31.1 dev wlp16s0 src 192.168.31.177 uid 1001
cache
2.3 查看无线网连接信息:iw
$ iw dev wlp16s0 link
Connected to 28:6c:07:42:39:c5 (on wlp16s0)
SSID: China-cHen
freq: 2457
RX: 1157552869 bytes (1181154 packets)
TX: 433099068 bytes (972681 packets)
signal: -52 dBm
rx bitrate: 24.0 MBit/s
tx bitrate: 48.0 MBit/s
bss flags: short-slot-time
dtim period: 1
beacon int: 100
$ iw dev wlp16s0 info
Interface wlp16s0
ifindex 3
wdev 0x1
addr 00:1c:bf:3e:5c:8c
ssid China-cHen
type managed
wiphy 0
channel 10 (2457 MHz), width: 20 MHz (no HT), center1: 2457 MHz
txpower 13.00 dBm
2.4 实时查看网路连接信息:iftop
$ sudo iftop -P -N -p -i wlp16s0 -m 100m
2.5 分类查看网络连接信息:ss
https://www.cnblogs.com/sztom/p/10810508.html#335
查看主机监听的端口,本地IP地址及tcp数字端口号(t:tcp; n:数字显示;l监听)
$ ss -tnl
显示名称,比如上面的127.0.0.1:53显示为tigger:domain; 端口22显示为ssh等。
$ ss -tlr
加上p,显示pid
$ ss -tlrp
所有的tcp连接
ss -tan
查看所有tcp,udp,数字显示,显示pid
$ ss -tuanp
查看所有tcp,udp,名称显示,显示pid
$ ss -tuarp
不推荐使用的Linux网络命令及其替代品 (iproute2 替代 net-tools)
https://www.cnblogs.com/sztom/articles/10764994.html
3. 测试与外部的连通
$ ping www.google.com
$ tracepath www.google.com
$ traceroute www.google.com
3.1 telnet {host} {port}
曾经广泛使用的命令之一,逐渐淘汰中。用于测试服务器之间的基本连接,即服务器与另一台网络设备的IP。
$ telnet www.baidu.com 80
3.2 nc -vz {host} {port}
Ncat(又名nc)是一个功能强大的网络实用程序,具有许多功能,例如绑定和接受连接,远程执行命令,写入和读取数据等。它同时适用于IPv4和IPv6。
$ nc -vz www.baidu.com 80
www.baidu.com [183.232.231.172] 80 (http) open
还可以使用nc绑定连接来侦听特定端口。当您没有正在运行的实际服务但要确保存在连接时,这可能很方便。
要开始监听端口: nc -l $PORTNUMBER
3.3 nmap -p {port} {host}
具有数百种功能的流行工具。通常,这被视为安全工具。nmap可让您测试单个IP /端口或该范围内的IP。
nmap -PNp {port} {host}
$ nmap -p 443 www.baidu.com
PORT STATE SERVICE
443/tcp open https
3.4 sudo nping --tcp -p {port} {host}
nping是用于网络数据包生成,响应分析和响应时间测量的开源工具。
nping允许用户生成各种协议的网络数据包,从而使他们可以通过虚拟方式调整协议头的任何字段。
nping可以用作检测活动主机的简单ping实用程序,但也可以用作原始数据包生成器。
$ sudo nping --tcp -p 80 www.baidu.com
$ sudo nping --tcp -p 8000 www.baidu.com
3.5 wget www.baidu.com
wget是用于下载/测试HTTP,HTTPS和FTP的有用命令。使用wget进行测试非常简单。
$ wget www.baidu.com
3.6 curl
URL检索实用程序和库. 可以使用curl远程登录到端口: curl -v telnet://$IP:$PORT
也可以使用curl下载数据。它支持多种协议-HTTP,HTTPS,FTP,IMAP,LDAP,POP3,SCP,SFTP,GOPHER等。
$ curl -v telnet://www.baidu.com:443
* Trying 183.232.231.174:443...
* TCP_NODELAY set
* Connected to www.baidu.com (183.232.231.174) port 443 (#0)
$ curl -v telnet://www.baidu.com:8000
* Trying 183.232.231.172:8000...
* TCP_NODELAY set
$ curl 网址 //返回网页源码
如果要把这个网页保存下来,可以使用`-o`参数,这就相当于使用wget命令了。
$ curl -o [文件名] www.sina.com
4. speedtest
$ speedtest-cli
Retrieving speedtest.net configuration...
Testing from China Mobile Guangdong (112.20.121.81)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by China Mobile 5G (Wuxi) [40.47 km]: 19.538 ms
Testing download speed................................
Download: 16.30 Mbit/s
Testing upload speed..................................
Upload: 5.10 Mbit/s
Chrome 浏览器
https://www.speedtest.net/
https://www.speedtest.cn/
https://fast.com/zh/cn/
5. more
如何从Linux或Unix命令行ping和测试特定端口
https://www.cyberciti.biz/faq/ping-test-a-specific-port-of-machine-ip-address-using-linux-unix/
Linux实用程序,用于测试网络连接
https://geekflare.com/linux-test-network-connectivity/
https://www.whatismyip.com/linux-ip-commands/
nmap
https://www.cnblogs.com/sztom/p/10970772.html
wget,curl,aria2
https://www.cnblogs.com/sztom/p/10765319.html
Linux系统使用ss命令查看端口状态
https://www.cnblogs.com/sztom/p/10810508.html
Wireshark用户指南
https://www.cnblogs.com/sztom/articles/10977415.html
故障网络连接故障排除,第2部分:基本网络命令(2011)
https://www.cnblogs.com/sztom/articles/10813032.html
有用的基于Web的工具(from dougvitale.wordpress.com)
https://www.cnblogs.com/sztom/articles/10812699.html
来源:https://www.cnblogs.com/sztom/p/12348314.html