Multicast IP Addresses
I posted this on StackOverflow and was told it might be more appropriate here.
I'm having trouble understanding how multicast addresses work.
First off, is it true that if I have N clients or peers working on separate networks, they all subscribe to the same multicast group, and this group allows any source to send messages, these peers/hosts can all communicate to each other through this group? (sounds like black magic!)
Second, I've heard hints that the IANA controls/regulates the multicast addresses. So do you have to request / ask IANA for a specific multicast address for your project / company? How does this work? Am I mistaken? Can you clarify multicast networking for me?
Thanks much!
Solution 1:
Yes, your understanding is true to some extent. In theory it works like this: your application binds to a multicast address, the operating system gets this and subscribes the computer in the multicast group. When other computers send packets to that address, they arrive at your computer until all applications unbind from that address and the operating system removes the computer from the multicast group.
The magic is a combination of IGMP and PIM. IGMP is used between the OS and the nearest router, it allows the OS to tell the router that it is entering or leaving a multicast group, and that it is interested in receiving packets for that address. PIM is used between routers to discover and exchange multicast group data, and to find and reach all subscribers of multicast groups when packets addressed to that group are transmitted.
IANA regulates multicast address (as well as almost everything else in the Internet). If you want to use multicast on the Internet, you need a multicast address allocation just like you do with unicast addresses:
- IPv4 Multicast Address Space Registry
- IPv6 Multicast Address Space Registry
If you want to use multicast in your local network, without routing to the outside Internet, you have administratively scoped ranges for private use defined in RFC 2365. The address range is 239.192.0.0/14.
Solution 2:
Multicast works like you think, except that the switches along the network all have to "understand" what the clients want. This means it's only useful for private networks, and you don't need to involve IANA. This also means you need to setup your switches for multicast to work correctly; if you only have one switch, or one switch stack, this is usually fairly easy. If you have multiple stacks, and especially if you have different brands, this can become quite complicated.