DEV Community

Cover image for Structure of an IP protocol
Israel-Lopes
Israel-Lopes

Posted on • Updated on

Structure of an IP protocol

Network protocols are a set of literal rules that establish a pattern of communication and behavior.

Image description

  • Network protocols, when implemented, have a basic structure formed by a header and payload.

Protocol IP

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| IHL | Type of Service |         Total Length      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|       Identification          |Flags|   Fragment Offset   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time to Live |    Protocol    |       Header Checksum     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Source Address                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     Destination Address                   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               Option                     |    Padding     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
Enter fullscreen mode Exit fullscreen mode
  • IP protocol and formed by 32Bits.
  • [Version]: the first 4 bytes refer to the version.
  • [IHL]: internet header length: internet header length.
  • internet refers to the protocol name, "internet protocol ip".
  • [Type of Service]: and 1 byte integer, "8bits" which used for quality of service. It usually comes to zero. -[Total Length]: It is 2bytes, and the size in bytes of every ip and every ipv4 payload can be up to 65,535bytes in size.
  • [Fragment Offset]: Used in ip fragmentation. If it is set to 1, do not shred if it is set to zero it may shred.
  • [Flags] Are 3Bytes, normally comes zero
  • [TTL or Time to Live] 8bytes and the time per RFC measured in Hop "hop". Lifetime of a package.
    • Hop or hop is the number of times a packet passes through a router.

Using the command mtr

To better understand the concept of hop, we will use mtr.

sudo apt install mtr
Enter fullscreen mode Exit fullscreen mode

now just do the following:

root@terminal:~# mtr -n yahoo.co.jp
Enter fullscreen mode Exit fullscreen mode

Image description

  • Snt indicates that mtr does continuous sending
  • Loss and packet loss. In the eighth Hop it can be seen that there was a big packet loss 96.6%
  • From 1 to 19 are the number of routers that the packet passed to its destination, which is 20. Operation of mtr.

mtr operation:

  • For the mtr to know the way, for example from here to Japan. It sends a packet to yahoo from Japan with TTL=1, when it arrives at the first router it takes zero, sends an icmp saying, "Your packet was destroyed ttl expired". Now knowing who the router is in front, it sends the packet again to the same address, only this time with TTL=2, making this route until it knows all the Hops that the packet makes to the destination.

Texto alternativo da imagem)

Top comments (0)