Hello Chaitanya
In general networking contexts, a “magic cookie” is a unique value or sequence of bytes used to identify, authenticate, or distinguish data in communication protocols. The term is often used to describe a token or identifier that serves a specific purpose.
In the context of DHCP, the magic cookie helps to differentiate DHCP messages from BOOTP messages.
If you look at a DHCP message, you will see that the Magic Cookie is a field found within DHCP messages. For example, the following Wireshark capture shows a DHCP offer message.
Ignore the red boxes for now, and take a look at the Magic Cookie field about halfway down the pane. It says
Magic cookie: DHCP
.
DHCP messages are formatted in an identical way to BOOTP messages. (DHCP developed from BOOTP). Without the specific magic cookie value, a host would not be able to differentiate between a BOOTP and a DHCP message.
The Magic Cookie is defined as the first 32 bits of the Options field. If those 32 bits are set to 99.130.83.99 (shown in dotted decimal format), then you know that the message must be interpreted as a DHCP message. This is defined in RFC 2131.
In all modern networks, the Magic Cookie is set to this value, because DHCP has replaced BOOTP virtually everywhere.
I hope this has been helpful!
Laz