TCPIP-学习笔记

On a Linux system, use the route command with the -n option to display the routing
table.* The -n option prevents route from converting IP addresses to hostnames,
which gives a clearer display. Here is a routing table from a sample Red Hat system:

route -n

Destination 要访问的目标地址
gateway 要到达目标地址 需要中转的地址

mac :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
netstat -nr

Routing tables

Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.1.1 UGSc 73 0 en7
127 127.0.0.1 UCS 0 0 lo0
127.0.0.1 127.0.0.1 UH 14 6969684 lo0
169.254 link#19 UCS 1 0 en7 !
192.168.1 link#19 UCS 2 0 en7 !
192.168.1.1/32 link#19 UCS 1 0 en7 !
192.168.1.1 38:ad:be:c2:56:fa UHLWIir 9 0 en7 1200
192.168.1.3/32 link#19 UCS 0 0 en7 !
192.168.1.7 98:5a:eb:d8:5f:af UHLWI 0 0 en7 911
192.168.1.25 e8:6a:64:9:4f:5e UHLWI 0 0 en7 698
224.0.0/4 link#19 UmCS 2 0 en7 !
224.0.0.251 1:0:5e:0:0:fb UHmLWI 0 7 en7
239.255.255.250 1:0:5e:7f:ff:fa UHmLWI 0 96 en7
255.255.255.255/32 link#19 UCS 0 0 en7 !

route cache

IP uses the information from the routing table (the forwarding table) to construct the
routes used for active connections. The routes associated with active connections are
stored in the routing cache. On Linux systems, the routing cache can be examined by
adding the -C argument to the route command line:

The routing cache is different from the routing table because the cache shows established
routes. The routing table is used to make routing decisions; the routing cache
is used after the decision is made. The routing cache shows the source and destination
of a network connection and the gateway and interface used to make that connection.

1
route -Cn

Phys Addr

arp -a

1
2
3
4
5
6
7
8
9
(172.24.0.4) at 02:42:ac:18:00:04 [ether] on br-0e67b8dd25a6
? (172.22.0.2) at 02:42:ac:16:00:02 [ether] on br-56ca89db6d16
? (192.168.16.2) at 02:42:c0:a8:10:02 [ether] on br-28e79d560103
? (192.168.8.11) at 00:0c:29:74:4e:c9 [ether] on eth0
? (192.168.8.14) at 00:0c:29:00:b3:7f [ether] on eth0
? (192.168.8.13) at 00:0c:29:d6:b7:bf [ether] on eth0
? (192.168.8.9) at 00:0c:29:1b:54:94 [ether] on eth0
? (192.168.8.34) at 00:0c:29:2b:ba:43 [ether] on eth0
? (192.168.8.12) at 00:0c:29:d2:41:d7 [ether] on eth0

protocols

处理如何解析数据。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
$ cat /etc/protocols


#
# Internet protocols
#
# $FreeBSD$
# from: @(#)protocols 5.1 (Berkeley) 4/17/89
#
# See also http://www.iana.org/assignments/protocol-numbers
#
ip 0 IP # internet protocol, pseudo protocol number
#hopopt 0 HOPOPT # hop-by-hop options for ipv6
icmp 1 ICMP # internet control message protocol
igmp 2 IGMP # internet group management protocol
ggp 3 GGP # gateway-gateway protocol
ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'')
st2 5 ST2 # ST2 datagram mode (RFC 1819) (officially ``ST'')
tcp 6 TCP # transmission control protocol
cbt 7 CBT # CBT, Tony Ballardie <A.Ballardie@cs.ucl.ac.uk>
egp 8 EGP # exterior gateway protocol
igp 9 IGP # any private interior gateway (Cisco: for IGRP)
bbn-rcc 10 BBN-RCC-MON # BBN RCC Monitoring
nvp 11 NVP-II # Network Voice Protocol
pup 12 PUP # PARC universal packet protocol
argus 13 ARGUS # ARGUS
emcon 14 EMCON # EMCON
xnet 15 XNET # Cross Net Debugger
chaos 16 CHAOS # Chaos
udp 17 UDP # user datagram protocol
mux 18 MUX # Multiplexing protocol
dcn 19 DCN-MEAS # DCN Measurement Subsystems
hmp 20 HMP # host monitoring protocol
prm 21 PRM # packet radio measurement protocol
xns-idp 22 XNS-IDP # Xerox NS IDP
trunk-1 23 TRUNK-1 # Trunk-1
trunk-2 24 TRUNK-2 # Trunk-2
leaf-1 25 LEAF-1 # Leaf-1
leaf-2 26 LEAF-2 # Leaf-2
rdp 27 RDP # "reliable datagram" protocol
irtp 28 IRTP # Internet Reliable Transaction Protocol
iso-tp4 29 ISO-TP4 # ISO Transport Protocol Class 4
netblt 30 NETBLT # Bulk Data Transfer Protocol
mfe-nsp 31 MFE-NSP # MFE Network Services Protocol
merit-inp 32 MERIT-INP # MERIT Internodal Protocol
dccp 33 DCCP # Datagram Congestion Control Protocol
3pc 34 3PC # Third Party Connect Protocol
idpr 35 IDPR # Inter-Domain Policy Routing Protocol
xtp 36 XTP # Xpress Tranfer Protocol
ddp 37 DDP # Datagram Delivery Protocol
idpr-cmtp 38 IDPR-CMTP # IDPR Control Message Transport Proto
tp++ 39 TP++ # TP++ Transport Protocol
il 40 IL # IL Transport Protocol
ipv6 41 IPV6 # ipv6
sdrp 42 SDRP # Source Demand Routing Protocol
ipv6-route 43 IPV6-ROUTE # routing header for ipv6
ipv6-frag 44 IPV6-FRAG # fragment header for ipv6
idrp 45 IDRP # Inter-Domain Routing Protocol
rsvp 46 RSVP # Resource ReSerVation Protocol
gre 47 GRE # Generic Routing Encapsulation
dsr 48 DSR # Dynamic Source Routing Protocol
bna 49 BNA # BNA
esp 50 ESP # encapsulating security payload
ah 51 AH # authentication header
i-nlsp 52 I-NLSP # Integrated Net Layer Security TUBA
swipe 53 SWIPE # IP with Encryption
narp 54 NARP # NBMA Address Resolution Protocol
mobile 55 MOBILE # IP Mobility
tlsp 56 TLSP # Transport Layer Security Protocol
skip 57 SKIP # SKIP
ipv6-icmp 58 IPV6-ICMP icmp6 # ICMP for IPv6
ipv6-nonxt 59 IPV6-NONXT # no next header for ipv6
ipv6-opts 60 IPV6-OPTS # destination options for ipv6
# 61 # any host internal protocol
cftp 62 CFTP # CFTP
# 63 # any local network
sat-expak 64 SAT-EXPAK # SATNET and Backroom EXPAK
kryptolan 65 KRYPTOLAN # Kryptolan
rvd 66 RVD # MIT Remote Virtual Disk Protocol
ippc 67 IPPC # Internet Pluribus Packet Core
# 68 # any distributed filesystem
sat-mon 69 SAT-MON # SATNET Monitoring
visa 70 VISA # VISA Protocol
ipcv 71 IPCV # Internet Packet Core Utility
cpnx 72 CPNX # Computer Protocol Network Executive
cphb 73 CPHB # Computer Protocol Heart Beat
wsn 74 WSN # Wang Span Network
pvp 75 PVP # Packet Video Protocol
br-sat-mon 76 BR-SAT-MON # Backroom SATNET Monitoring
sun-nd 77 SUN-ND # SUN ND PROTOCOL-Temporary
wb-mon 78 WB-MON # WIDEBAND Monitoring
wb-expak 79 WB-EXPAK # WIDEBAND EXPAK
iso-ip 80 ISO-IP # ISO Internet Protocol
vmtp 81 VMTP # Versatile Message Transport
secure-vmtp 82 SECURE-VMTP # SECURE-VMTP
vines 83 VINES # VINES
ttp 84 TTP # TTP
#iptm 84 IPTM # Protocol Internet Protocol Traffic
nsfnet-igp 85 NSFNET-IGP # NSFNET-IGP
dgp 86 DGP # Dissimilar Gateway Protocol
tcf 87 TCF # TCF
eigrp 88 EIGRP # Enhanced Interior Routing Protocol (Cisco)
ospf 89 OSPFIGP # Open Shortest Path First IGP
sprite-rpc 90 Sprite-RPC # Sprite RPC Protocol
larp 91 LARP # Locus Address Resolution Protocol
mtp 92 MTP # Multicast Transport Protocol
ax.25 93 AX.25 # AX.25 Frames
ipip 94 IPIP # Yet Another IP encapsulation
micp 95 MICP # Mobile Internetworking Control Pro.
scc-sp 96 SCC-SP # Semaphore Communications Sec. Pro.
etherip 97 ETHERIP # Ethernet-within-IP Encapsulation
encap 98 ENCAP # Yet Another IP encapsulation
# 99 # any private encryption scheme
gmtp 100 GMTP # GMTP
ifmp 101 IFMP # Ipsilon Flow Management Protocol
pnni 102 PNNI # PNNI over IP
pim 103 PIM # Protocol Independent Multicast
aris 104 ARIS # ARIS
scps 105 SCPS # SCPS
qnx 106 QNX # QNX
a/n 107 A/N # Active Networks
ipcomp 108 IPComp # IP Payload Compression Protocol
snp 109 SNP # Sitara Networks Protocol
compaq-peer 110 Compaq-Peer # Compaq Peer Protocol
ipx-in-ip 111 IPX-in-IP # IPX in IP
carp 112 CARP vrrp # Common Address Redundancy Protocol
pgm 113 PGM # PGM Reliable Transport Protocol
# 114 # any 0-hop protocol
l2tp 115 L2TP # Layer Two Tunneling Protocol
ddx 116 DDX # D-II Data Exchange
iatp 117 IATP # Interactive Agent Transfer Protocol
stp 118 STP # Schedule Transfer Protocol
srp 119 SRP # SpectraLink Radio Protocol
uti 120 UTI # UTI
smp 121 SMP # Simple Message Protocol
sm 122 SM # SM
ptp 123 PTP # Performance Transparency Protocol
isis 124 ISIS # ISIS over IPv4
fire 125 FIRE
crtp 126 CRTP # Combat Radio Transport Protocol
crudp 127 CRUDP # Combat Radio User Datagram
sscopmce 128 SSCOPMCE
iplt 129 IPLT
sps 130 SPS # Secure Packet Shield
pipe 131 PIPE # Private IP Encapsulation within IP
sctp 132 SCTP # Stream Control Transmission Protocol
fc 133 FC # Fibre Channel
rsvp-e2e-ignore 134 RSVP-E2E-IGNORE # Aggregation of RSVP for IP reservations
mobility-header 135 Mobility-Header # Mobility Support in IPv6
udplite 136 UDPLite # The UDP-Lite Protocol
mpls-in-ip 137 MPLS-IN-IP # Encapsulating MPLS in IP
manet 138 MANET # MANET Protocols (RFC5498)
hip 139 HIP # Host Identity Protocol (RFC5201)
shim6 140 SHIM6 # Shim6 Protocol (RFC5533)
wesp 141 WESP # Wrapped Encapsulating Security Payload (RFC5840)
rohc 142 ROHC # Robust Header Compression (RFC5858)
# 138-254 # Unassigned
pfsync 240 PFSYNC # PF Synchronization
# 253-254 # Use for experimentation and testing (RFC3692)
# 255 # Reserved
divert 258 DIVERT # Divert pseudo-protocol [non IANA]

port

为知名的程序保留了端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# head -22 /etc/services
# Network services, Internet style
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, officially ports have two entries
# even if the protocol doesn't support UDP operations.
#
# Updated from http://www.iana.org/assignments/port-numbers and other
# sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services .
# New ports will be added on request if they have been officially assigned
# by IANA and used in the real-world or are needed by a debian package.
# If you need a huge list of used numbers please install the nmap package.

tcpmux 1/tcp # TCP port service multiplexer
echo 7/tcp
echo 7/udp
discard 9/tcp sink null
discard 9/udp sink null
systat 11/tcp users
daytime 13/tcp
daytime 13/udp
netstat 15/tcp
qotd 17/tcp quote

The Host Table

The host table is a simple text file that associates IP addresses with hostnames. On
most Unix systems, the table is in the file /etc/hosts. Each table entry in /etc/hosts contains
an IP address separated by whitespace from a list of hostnames associated with
that address. Comments begin with #.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
head -22 /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
# 0.0.0.0 account.jetbrains.com
# 0.0.0.0 www.jetbrains.com
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

DNS

overcomes both major weaknesses of the host table:
• DNSscales well. It doesn’t rely on a single large table; it is a distributed database
system that doesn’t bog down as the database grows. DNScurrently provides
information on approximately 100,000,000 hosts, while fewer than 10,000
were listed in the host table.
• DNSguarantees that new host information will be disseminated to the rest of the
network as it is needed.
DNSis a distributed hierarchical system for resolving hostnames into IP addresses.
Under DNS, there is no central database with all of the Internet host information.
The information is distributed among thousands of name servers organized into a
hierarchy similar to the hierarchy of the Unix filesystem. DNShas a root domain at
the top of the domain hierarchy that is served by a group of name servers called the
root servers.