-
2.网络侦错与观察指令
-
2.1 两部主机两点沟通: ping
-
2.3 两主机间各节点分析: traceroute
-
2.3 察看本机的网络联机与后门: netstat
-
2.4 侦测主机名与 IP 对应: host, nslookup
-
-
Reference
2.网络侦错与观察指令
2.1 两部主机两点沟通: ping
ping 主要通过 ICMP 数据包 来进行整个网络的状况报告,最重要的就是那个 ICMP type 0, 8 这两个类型, 分别是要求回报与主动回报网络状态是否存在的特性。
要特别注意的是, ping 还是需要通过 IP 数据包来传送 ICMP 数据包的, 而 IP 数据包里面有个相当重要的 TTL 属性,这是很重要的一个路由特性
ping [选项与参数] IP
选项与参数:
-c 数值:后面接的是执行 ping 的次数,例如 -c 5 ;
-n :在输出数据时不进行 IP 与主机名的反查,直接使用 IP 输出(速度较快);
-s 数值:发送出去的 ICMP 数据包大小,预设为 56bytes,不过你可以放大此一数值;
-t 数值:TTL 的数值,预设是 255,每经过一个节点就会少一;
-W 数值:等待响应对方主机的秒数。
-M [do|dont] :主要在侦测网络的 MTU 数值大小,两个常见的项目是:
do :代表传送一个 DF (Don't Fragment) 旗标,让数据包不能重新拆包与打包;
dont:代表不要传送 DF 旗标,表示数据包可以在其他主机上拆包与打包
# 范例一:侦测一下 168.95.1.1 这部 DNS 主机是否存在?
(base) Randy@Jill:~$ ping -c 3 168.95.1.1
PING 168.95.1.1 (168.95.1.1) 56(84) bytes of data.
64 bytes from 168.95.1.1: icmp_seq=1 ttl=49 time=46.8 ms
64 bytes from 168.95.1.1: icmp_seq=2 ttl=49 time=41.2 ms
64 bytes from 168.95.1.1: icmp_seq=3 ttl=49 time=43.5 ms
--- 168.95.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 41.184/43.826/46.796/2.302 ms
ping 最简单的功能就是传送 ICMP 数据包去要求对方主机回应是否存在于网络环境中。
上面的响应消息当中,几个重要的项目是这样的:
-
64 bytes:表示这次传送的 ICMP 数据包大小为 64 bytes 这么大,这是默认值, 在某些特殊场合中,例如要搜索整个网络内最大的 MTU 时,可以使用
-s 2000
之类的数值来取代; -
icmp_seq=1:ICMP 所侦测进行的次数,第一次编号为 1 ;
-
ttl=49:TTL 与 IP 数据包内的 TTL 是相同的,每经过一个带有 MAC 的节点 (node) 时,例如 router, bridge 时, TTL 就会减少一,预设的 TTL 为 255 , 你可以通过
-t 150
之类的方法来重新设定预设 TTL 数值; -
time=46.8 ms:响应时间,单位有 ms(0.001秒)及 us(0.000001秒), 一般来说,越小的响应时间,表示两部主机之间的网络联机越良好
如果你忘记加上 -c 3
这样的规定侦测次数,那就得要使用 [ctrl]-c
将它结束掉。
例题:写一支脚本程序 ping.sh ,通过这支脚本程序,你可以用 ping 侦测整个网域的主机是否有响应。
此外,每部主机的侦测仅等待一秒钟,也仅侦测一次。
A:由于仅侦测一次且等待一秒,因此 ping 的选项为: -W1 -c1
,而位于本机所在的区网为 10.11.154.84/24 ,所以可以这样写 (vim /root/bin/ping.sh):
#!/bin/bash
for siteip in $(seq 1 254)
do
site="192.168.1.${siteip}"
ping -c1 -W1 ${site} &> /dev/null
if [ "$?" == "0" ]; then
echo "$site is UP"
else
echo "$site is DOWN"
fi
done
(base) Randy@Jill:~$ bash ping.sh
PING 10.11.154.1 (10.11.154.1) 56(84) bytes of data.
--- 10.11.154.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
ping.sh: line 5: /dev/null: Permission denied
10.11.154.1 is DOWN
PING 10.11.154.2 (10.11.154.2) 56(84) bytes of data.
--- 10.11.154.2 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
ping.sh: line 5: /dev/null: Permission denied
10.11.154.2 is DOWN
PING 10.11.154.3 (10.11.154.3) 56(84) bytes of data.
--- 10.11.154.3 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
ping.sh: line 5: /dev/null: Permission denied
10.11.154.3 is DOWN
PING 10.11.154.4 (10.11.154.4) 56(84) bytes of data.
64 bytes from 10.11.154.4: icmp_seq=1 ttl=64 time=453 ms
--- 10.11.154.4 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 453.365/453.365/453.365/0.000 ms
ping.sh: line 5: gt: command not found
ping.sh: line 5: /dev/null: Permission denied
10.11.154.4 is DOWN
PING 10.11.154.5 (10.11.154.5) 56(84) bytes of data.
--- 10.11.154.5 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
ping.sh: line 5: /dev/null: Permission denied
10.11.154.5 is DOWN
PING 10.11.154.6 (10.11.154.6) 56(84) bytes of data.
--- 10.11.154.6 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
ping.sh: line 5: /dev/null: Permission denied
10.11.154.6 is DOWN
PING 10.11.154.7 (10.11.154.7) 56(84) bytes of data.
--- 10.11.154.7 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
ping.sh: line 5: /dev/null: Permission denied
10.11.154.7 is DOWN
PING 10.11.154.8 (10.11.154.8) 56(84) bytes of data.
特别注意,如果你的主机与待侦测主机并不在同一个网域内, 那么 TTL 预设使用 255 ,如果是同一个网域内,那么 TTL 预设则使用 64。
用 ping 追踪路径中的最大 MTU 数值
加大帧大小 (frame) 时, 对于网络效能是有帮助的,因为数据包打包的次数会减少,加上如果整个传输的媒体都能够接受这个 frame 而不需要重新进行数据包的拆解与重组的话,那么效能当然会更好,那个修改 frame 大小的参数就是 MTU
追踪整个网络传输的最大 MTU 时,可以通过 ping 传送一个大数据包, 并且不许中继的路由器或 switch 将该数据包重组:
-
找出最大的 MTU 数值
(base) Randy@Jill:~$ ping -c 2 -s 1000 -M do 10.11.154.84
PING 10.11.154.84 (10.11.154.84) 1000(1028) bytes of data.
1008 bytes from 10.11.154.84: icmp_seq=1 ttl=64 time=0.055 ms
1008 bytes from 10.11.154.84: icmp_seq=2 ttl=64 time=0.066 ms
--- 10.11.154.84 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1023ms
rtt min/avg/max/mdev = 0.055/0.060/0.066/0.005 ms
# 如果有响应,那就是可以接受这个数据包,如果无响应,那就表示这个 MTU 太大了。
(base) Randy@Jill:~$ ping -c 2 -s 8000 -M do 10.11.152.0
PING 10.11.152.0 (10.11.152.0) 8000(8028) bytes of data.
ping: local error: message too long, mtu=1500
ping: local error: message too long, mtu=1500
--- 10.11.152.0 ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1010ms
# 这个错误信息是说,本地端的 MTU 才到 1500 而已,你要侦测 8000 的 MTU
# 根本就是无法达成的!那要如何是好?用前一小节介绍的 ip link 来进行 MTU 设定吧!
由于 IP 数据包表头 (不含 options) 就已经占用了 20 bytes ,再加上 ICMP 的表头有 8 bytes ,所以当然你在使用 -s size
的时候,那个数据包的大小就得要先扣除 (20+8=28) 的大小了。 因此如果要使用 MTU 为 1500 时,就得要下达『 ping -s 1472 -M do xx.yy.zz.ip
』才行。
另外,由于本地端的网络卡 MTU 也会影响到侦测,所以如果想要侦测整个传输媒体的 MTU 数值, 那么每个可以调整的主机就得要先使用 ifcofig 或 ip 先将 MTU 调大,然后再去进行侦测, 否则可能会出现错误信息!
-
常见的各种接口的 MTU 值分别为︰
网络接口 | MTU |
---|---|
Ethernet | 1500 |
PPPoE | 1492 |
Dial-up(Modem) | 576 |
2.3 两主机间各节点分析: traceroute
traceroute 可以追踪两部主机之间通过的各个节点 (node) 通讯状况的好坏
(base) Randy@Jill:~$ traceroute --help
Usage:
traceroute [ -46dFITnreAUDV ] [ -f first_ttl ] [ -g gate,... ] [ -i device ] [ -m max_ttl ] [ -N squeries ] [ -p port ] [ -t tos ] [ -l flow_label ] [ -w MAX,HERE,NEAR ] [ -q nqueries ] [ -s src_addr ] [ -z sendwait ] [ --fwmark=num ] host [ packetlen ]
Options:
-4 Use IPv4
-6 Use IPv6
-d --debug Enable socket level debugging
-F --dont-fragment Do not fragment packets
-f first_ttl --first=first_ttl
Start from the first_ttl hop (instead from 1)
-g gate,... --gateway=gate,...
Route packets through the specified gateway
(maximum 8 for IPv4 and 127 for IPv6)
-I --icmp Use ICMP ECHO for tracerouting
-T --tcp Use TCP SYN for tracerouting (default port is 80)
-i device --interface=device
Specify a network interface to operate with
-m max_ttl --max-hops=max_ttl
Set the max number of hops (max TTL to be
reached). Default is 30
-N squeries --sim-queries=squeries
Set the number of probes to be tried
simultaneously (default is 16)
-n Do not resolve IP addresses to their domain names
-p port --port=port Set the destination port to use. It is either
initial udp port value for "default" method
(incremented by each probe, default is 33434), or
initial seq for "icmp" (incremented as well,
default from 1), or some constant destination
port for other methods (with default of 80 for
"tcp", 53 for "udp", etc.)
-t tos --tos=tos Set the TOS (IPv4 type of service) or TC (IPv6
traffic class) value for outgoing packets
-l flow_label --flowlabel=flow_label
Use specified flow_label for IPv6 packets
-w MAX,HERE,NEAR --wait=MAX,HERE,NEAR
Wait for a probe no more than HERE (default 3)
times longer than a response from the same hop,
or no more than NEAR (default 10) times than some
next hop, or MAX (default 5.0) seconds (float
point values allowed too)
-q nqueries --queries=nqueries
Set the number of probes per each hop. Default is
3
-r Bypass the normal routing and send directly to a
host on an attached network
-s src_addr --source=src_addr
Use source src_addr for outgoing packets
-z sendwait --sendwait=sendwait
Minimal time interval between probes (default 0).
If the value is more than 10, then it specifies a
number in milliseconds, else it is a number of
seconds (float point values allowed too)
-e --extensions Show ICMP extensions (if present), including MPLS
-A --as-path-lookups Perform AS path lookups in routing registries and
print results directly after the corresponding
addresses
-M name --module=name Use specified module (either builtin or external)
for traceroute operations. Most methods have
their shortcuts (`-I' means `-M icmp' etc.)
-O OPTS,... --options=OPTS,...
Use module-specific option OPTS for the
traceroute module. Several OPTS allowed,
separated by comma. If OPTS is "help", print info
about available options
--sport=num Use source port num for outgoing packets. Implies
`-N 1'
--fwmark=num Set firewall mark for outgoing packets
-U --udp Use UDP to particular port for tracerouting
(instead of increasing the port per each probe),
default port is 53
-UL Use UDPLITE for tracerouting (default dest port
is 53)
-D --dccp Use DCCP Request for tracerouting (default port
is 33434)
-P prot --protocol=prot Use raw packet of protocol prot for tracerouting
--mtu Discover MTU along the path being traced. Implies
`-F -N 1'
--back Guess the number of hops in the backward path and
print if it differs
-V --version Print version info and exit
--help Read this help and exit
Arguments:
+ host The host to traceroute to
packetlen The full packet length (default is the length of an IP
header plus 40). Can be ignored or increased to a minimal
allowed value
-
安装
sudo apt install traceroute # version 1:2.1.0-2, or
sudo apt install inetutils-traceroute # version 2:1.9.4-11ubuntu0.2
-
侦测本机到 yahoo 去的各节点联机状态
(base) Randy@Jill:~$ traceroute -n www.baidu.com
traceroute to www.baidu.com (180.101.50.242), 30 hops max, 60 byte packets
1 10.251.1.1 2.121 ms 2.048 ms 2.033 ms
2 192.168.1.1 2.893 ms 2.879 ms 2.866 ms
3 * * *
4 * * *
5 * * *
6 58.213.95.54 9.389 ms 58.213.94.54 8.782 ms 58.213.94.222 8.669 ms
7 58.213.94.210 10.245 ms 11.357 ms 11.312 ms
8 58.213.96.66 10.445 ms 9.069 ms 10.764 ms
9 * * *
10 * * *
11 * * 10.165.1.153 8.223 ms
12 * * *
13 * * *
这个 traceroute 指令会针对欲连接的目的地之所有 node 进行 UDP 的超时等待。
例如上面的例子当中,由我的主机连接到 Baidu 时,它会经过 12 个节点以上,traceroute 会主动的对这 12 个节点做 UDP 的回声等待,并侦测回复的时间,每节点侦测三次,最终回传像上面显示的结果。 你可以发现每个节点其实回复的时间大约在 50 ms 以内,算是还可以的 Internet 环境了。
回传星号的,代表该 node 可能设有某些防护措施,让我们发送的数据包信息被丢弃所致。 因为我们是直接通过路由器转递数据包,并没有进入路由器去取得路由器的使用资源,所以某些路由器仅支持数据包转递, 并不会接受来自客户端的各项侦测。
由于目前 UDP/ICMP 的攻击层出不穷,因此很多路由器可能就此取消这两个数据包的响应功能。
所以我们可以使用 TCP 来侦测。通过等待时间 1 秒,以及 TCP 80 端口的情况下:
(base) Randy@Jill:~$ sudo traceroute -w 1 -n -T www.baidu.com
traceroute to www.baidu.com (180.101.50.242), 30 hops max, 60 byte packets
1 10.251.1.1 9.917 ms 11.681 ms 11.666 ms
2 192.168.1.1 13.686 ms 14.515 ms 13.660 ms
3 * * *
4 * * *
5 * * *
6 58.213.94.222 19.402 ms 58.213.95.54 9.737 ms *
7 58.213.94.206 7.679 ms 6.872 ms 6.824 ms
8 58.213.96.50 7.403 ms 58.213.96.66 8.903 ms 10.506 ms
9 * 10.166.50.25 7.809 ms *
10 10.166.112.0 10.061 ms * *
11 * * *
12 * * 180.101.50.242 9.986 ms
2.3 察看本机的网络联机与后门: netstat
果你觉得你的某个网络服务明明就启动了,但是就是无法造成联机的话,首先你应该要查询一下自己的网络接口所监听的端口 (port) 来看看是否真的有启动,因为有时候屏幕上面显示的 [OK] 并不一定是 OK。
(base) Randy@Jill:~$ netstat --help
usage: netstat [-vWeenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}
netstat [-vWnNcaeol] [<Socket> ...]
netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }
-r, --route 列出路由表(route table),功能如同 route 这个指令;
-i, --interfaces display interface table
-g, --groups display multicast group memberships
-s, --statistics display networking statistics (like SNMP)
-M, --masquerade display masqueraded connections
-v, --verbose be verbose
-W, --wide don't truncate IP addresses
-n, --numeric 不使用主机名与服务名称,使用 IP 与 port number ,如同 route -n 与网络接口有关的参数:
--numeric-hosts don't resolve host names
--numeric-ports don't resolve port names
--numeric-users don't resolve user names
-N, --symbolic resolve hardware names
-e, --extend display other/more information
-p, --programs 列出 PID 与 Program 的名字;
-o, --timers display timers
-c, --continuous 可以设定几秒钟后自动更新一次,例如 -c 5 每五秒更新一次网络状态的显示;
-l, --listening 仅列出有在 Listen (监听) 的服务之网络状态
-a, --all 列出所有的联机状态,包括 tcp/udp/unix socket 等;
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
-Z, --context display SELinux security context for sockets
<Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}
{-x|--unix} --ax25 --ipx --netrom
<AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
-
列出目前的路由表状态,且以
IP
及port number
显示:
(base) Randy@Jill:~$ netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.251.1.1 0.0.0.0 UG 0 0 0 wlp0s20f3
10.251.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlp0s20f3
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 wlp0s20f3
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
# 其实这个参数就跟 route -n 一模一样,对吧!这不是 netstat 的主要功能啦!
-
列出目前的所有网络联机状态,使用
IP
与port number
(base) Randy@Jill:~$ 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:5556 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
......
udp6 0 0 :::59890 :::*
udp6 0 0 :::111 :::*
udp6 0 0 fe80::7030:a886:e41:546 :::*
udp6 0 0 :::5353 :::*
raw6 0 0 :::58 :::* 7
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 45737 /tmp/fcitx-socket-:1
unix 2 [ ACC ] STREAM LISTENING 46867 @/tmp/.ICE-unix/2537
unix 2 [ ACC ] STREAM LISTENING 46100 /var/run/nvidia-persistenced/socket
unix 2 [ ACC ] STREAM LISTENING 53055 @/home/randy/.cache/ibus/dbus-fUjb6pNM
......
参数解释:
-
Proto
:该联机的数据包协议,主要为 TCP/UDP 等数据包; -
Recv-Q
:非由用户程序连接所复制而来的总 bytes 数; -
Send-Q
:由远程主机所传送而来,但不具有 ACK 标志的总 bytes 数, 意指主动联机 SYN 或其他标志的数据包所占的 bytes 数; -
Local Address
:本地端的地址,可以是 IP (-n 参数存在时), 也可以是完整的主机名。使用的格式是『 IP:port 』只是 IP 的格式有 IPv4 及 IPv6 的差异。 如上所示,在 port 22 的接口中,使用的:::59890
就是针对 IPv6 的显示,事实上他就相同于 0.0.0.0:59890 的意思。 至于 port 631 仅针对 lo 接口开放,意指 Internet 基本上是无法连接到我本机的 631 端口。 -
Foreign Address:远程的主机 IP 与 port number
-
stat:状态栏,主要的状态含有:
-
ESTABLISED:已建立联机的状态;
-
SYN_SENT:发出主动联机 (SYN 标志) 的联机数据包;
-
SYN_RECV:接收到一个要求联机的主动联机数据包;
-
FIN_WAIT1:该插槽服务(socket)已中断,该联机正在断线当中;
-
FIN_WAIT2:该联机已挂断,但正在等待对方主机响应断线确认的数据包;
-
TIME_WAIT:该联机已挂断,但 socket 还在网络上等待结束;
-
LISTEN:通常用在服务的监听 port !可使用『 -l 』参数查阅。
-
netstat 的输出主要分为2大部分,分别是 TCP/IP 的网络接口部分,以及传统的 Unix socket 部分。
Tips: 通常建议加上『 -n 』这个参数的,因为可以避过主机名与服务名称的反查,直接以 IP 及端口号码 (port number) 来显示,显示的速度上会快很多
-
秀出目前已经启动的网络服务
可以观察『我目前开了多少的 port 在等待客户端的联机』以及 『目前我的网络联机状态中,有多少联机已建立或产生问题』
(base) Randy@Jill:~$ netstat -tulnp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp6 0 0 :::111 :::* LISTEN -
tcp6 0 0 ::1:631 :::* LISTEN -
udp 0 0 127.0.0.53:53 0.0.0.0:* -
udp 0 0 0.0.0.0:111 0.0.0.0:* -
udp 0 0 0.0.0.0:631 0.0.0.0:* -
udp 0 0 0.0.0.0:50272 0.0.0.0:* 4796/chrome --type=
udp 0 0 0.0.0.0:38037 0.0.0.0:* 4796/chrome --type=
udp 0 0 224.0.0.251:5353 0.0.0.0:* 4796/chrome --type=
udp 0 0 224.0.0.251:5353 0.0.0.0:* 4752/chrome
udp 0 0 0.0.0.0:5353 0.0.0.0:* -
udp 0 0 0.0.0.0:56518 0.0.0.0:* 4796/chrome --type=
udp 0 0 0.0.0.0:57301 0.0.0.0:* -
udp 0 0 0.0.0.0:42003 0.0.0.0:* 4796/chrome --type=
udp6 0 0 :::111 :::* -
udp6 0 0 :::33280 :::* 4796/chrome --type=
udp6 0 0 fe80::7030:a886:e41:546 :::* -
udp6 0 0 :::34835 :::* 4796/chrome --type=
udp6 0 0 :::35257 :::* 4796/chrome --type=
udp6 0 0 :::5353 :::* -
udp6 0 0 :::57474 :::* 4796/chrome --type=
udp6 0 0 :::43926 :::* -
可以发现很多的网络服务其实仅针对本机的 lo 开放而已,因特网是连接不到该端口与服务的。
而由上述的数据我们也可以看到,启动 port 4752 的,其实就是 chrome浏览器,且仅开了1个标签页;而有多个 port 4796 是因为该浏览器开了多个标签页,那如果想要关闭这个端口, 你可以使用 kill 删除 PID 4752,也可以使用 killall 删除 chrome 这个程序即可。
-
观察本机上头所有的网络联机状态
(base) Randy@Jill:~$ netstat -atunp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp 0 1 10.251.1.74:54062 142.251.42.234:443 SYN_SENT 10849/chrome --type
tcp 0 1 10.251.1.74:58150 172.217.160.78:443 SYN_SENT 10849/chrome --type
tcp 0 1 10.251.1.74:37508 142.251.42.234:443 SYN_SENT 10849/chrome --type
tcp 0 1 10.251.1.74:53882 172.217.163.46:443 SYN_SENT 10849/chrome --type
tcp 0 1 10.251.1.74:48368 172.217.160.74:443 SYN_SENT 10849/chrome --type
tcp 0 0 10.251.1.74:50938 140.82.112.25:443 ESTABLISHED 10849/chrome --type
。。。。。。
省略号上面最后一条消息是说明:由远程主机 140.82.112.25 启动一个小于 1024 的端口向本地端主机 10.251.1.74 的 port 50938 进行的一条联机
而『Client 端是随机取一个大于 1024 以上的 port 进行联机』,此外『只有 root 可以启动小于 1024 以下的 port 』
通常,在 TCP/IP 协议族中,小于 1024 的端口号被称为“知名端口”或“特权端口”,因为这些端口号被系统保留给特定的服务使用。例如,HTTP 服务通常使用 80 端口,HTTPS 服务使用 443 端口,SSH 服务使用 22 端口等。所以此处chrome程序所连接的主机启动的端口为443
2.4 侦测主机名与 IP 对应: host, nslookup
关于主机名与 IP 的对应中,我们主要介绍的是 DNS 客户端功能的 dig 这个指令。
不过除了这个指令之外, 其实还有两个更简单的指令,那就是 host 与 nslookup
host
这个指令可以用来查出某个主机名的 IP 。
举例来说,我们想要知道 www.baidu.com 的 IP 时,可以这样做:
[root@RandyJill]# host [-a] hostname [server]
Usage: host [-aCdilrTvVw] [-c class] [-N ndots] [-t type] [-W time]
[-R number] [-m flag] [-p port] hostname [server]
-a is equivalent to -v -t ANY 列出该主机详细的各项主机名设定数据
-A is like -a but omits RRSIG, NSEC, NSEC3
-c specifies query class for non-IN data
-C compares SOA records on authoritative nameservers
-d is equivalent to -v
-l lists all hosts in a domain, using AXFR
-m set memory debugging flag (trace|record|usage)
-N changes the number of dots allowed before root lookup is done
-p specifies the port on the server to query
-r disables recursive processing
-R specifies number of retries for UDP packets
-s a SERVFAIL response should stop query
-t specifies the query type
-T enables TCP/IP mode
-U enables UDP mode
-v enables verbose output
-V print version number and exit
-w specifies to wait forever for a reply
-W specifies how long to wait for a reply
-4 use IPv4 query transport only
-6 use IPv6 query transport only
[server] :可以使用非为 /etc/resolv.conf 的 DNS 服务器 IP 来查询。
-
列出 www.baidu.com 的 IP:
(base) Randy@Jill:~$ host www.baidu.com
www.baidu.com is an alias for www.a.shifen.com.
www.a.shifen.com has address 180.101.50.188
www.a.shifen.com has address 180.101.50.242
www.a.shifen.com has IPv6 address 240e:e9:6002:15a:0:ff:b05c:1278
www.a.shifen.com has IPv6 address 240e:e9:6002:15c:0:ff:b015:146f
IP 是 180.101.50.188 或 180.101.50.242。
那么这个 IP 是向谁查询的呢?其实就是写在 /etc/resolv.conf 那个文件内的 DNS 服务器 IP 。
如果不想要使用该文件内的主机来查询,也可以这样做:
[root@RandyJill]# host www.baidu.com 168.95.1.2
Using domain server:
Name: 168.95.1.2
Address: 168.95.1.2#53
Aliases:......
nslookup
用途与 host 基本上是一样的,就是用来作为 IP 与主机名对应的检查, 同样是使用 /etc/resolv.conf 这个文件来作为 DNS 服务器的来源选择。
[root@RandyJill]# nslookup [-query=[type]] [hostname|IP]
选项与参数:
-query=type:查询的类型,除了传统的 IP 与主机名对应外,DNS 还有很多信息,
所以我们可以查询很多不同的信息,包括 mx, cname 等等,
例如: -query=mx 的查询方法!
-
找出 www.google.com 的 IP
(base) Randy@Jill:~$ nslookup www.google.com
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: www.google.com
Address: 108.160.169.186
Name: www.google.com
Address: 2a03:2880:f134:183:face:b00c:0:25de
-
找出 168.95.1.1 的主机名
[root@RandyJill]# nslookup 168.95.1.1
Server: 168.95.1.1
Address: 168.95.1.1#53
1.1.95.168.in-addr.arpa name = dns.hinet.net.
Reference
-
http://cn.linux.vbird.org/linux_server/0140networkcommand.php
linux3
linux · 目录
上一篇Linux 常用网络指令1
阅读 84
三戒纪元
分享收藏在看赞
分享此内容的人还喜欢
Wireshark 查看包和时间等图示
我关注的号
三戒纪元
不喜欢
不看的原因
确定
- 内容低质
- 不看此公众号内容
Linux网络共享在fstab延迟挂载
魔趣典藏目录
不喜欢
不看的原因
确定
- 内容低质
- 不看此公众号内容
为了帮助大家更好的学习黑客网络安全,我给大家准备了一份黑客网络安全入门/进阶学习资料,里面的内容都是适合零基础小白的笔记和资料,不懂编程也能听懂、看懂这些资料!
因篇幅有限,仅展示部分资料,需要点击下方链接即可前往获取
[2024最新CSDN大礼包:《黑客&网络安全入门&进阶学习资源包》免费分享]
因篇幅有限,仅展示部分资料,需要点击下方链接即可前往获取
[2024最新CSDN大礼包:《黑客&网络安全入门&进阶学习资源包》免费分享]
Markdown 19906 字数 668 行数 当前行 1, 当前列 0
HTML 17198 字数 131 段落