Structure of an IP protocol
Published: 2022-10-28 18:41:29

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9iheffjroup2g0jmv6ww.png)

 - 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     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
```

 - 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
```

now just do the following:

```
root@terminal:~# mtr -n yahoo.co.jp
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/der11mjkdp3y3wssxk3d.png)

 - 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.

<br />

[![Texto alternativo da imagem](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png))](https://www.linkedin.com/in/israel-lopes-419a32189)