Course contentsShow
← Linux
Lesson 1244 of 1,81910. Network Administration and Kernel StacksFree lesson

Advanced Multicast Routing

Manage PIM and IGMP settings within the Linux kernel.

In this lesson, you will learn how to configure the Linux kernel to participate in multicast routing by managing IGMP (Internet Group Management Protocol) and PIM (Protocol Independent Multicast) settings.

The Kernel’s Role in Multicast

While standard routing handles unicast traffic, multicast routing requires the kernel to maintain a Virtual Multicast Routing (VMR) table. The kernel does not route multicast packets natively like a dedicated hardware router; instead, it relies on a user-space daemon (like pimd or mrouted) to perform the heavy lifting of group membership management.

To enable this, the kernel must be compiled with CONFIG_IP_MROUTE and CONFIG_IP_PIMSM_V1 or V2. You can verify your kernel’s readiness by checking for these flags in your config file or inspecting /proc/net/ip_mr_cache.

Managing IGMP and PIM

When you act as a multicast router, your interface needs to listen for IGMP reports from hosts and exchange PIM hellos with neighboring routers to build the distribution tree.

You control the kernel’s behavior through sysctl. For instance, to ensure an interface properly handles multicast forwarding, you must enable it specifically:

# Enable multicast routing for a specific interface
sysctl -w net.ipv4.conf.eth0.mc_forwarding=1

If you are dealing with PIM, you need to ensure the kernel allows the exchange of PIM messages. Unlike IGMP (which is handled largely by the socket layer), PIM often requires specific kernel hooks to be active. You can monitor the multicast routing table state using:

# View the current multicast routing cache
cat /proc/net/ip_mr_cache

The Workflow

  1. Enable Forwarding: You must set net.ipv4.ip_forward to 1, followed by the specific mc_forwarding flag for your interfaces.
  2. Daemon Hand-off: Run a multicast routing daemon. The daemon opens a specialized raw socket (IPPROTO_IGMP) and sends MRT_INIT setsockopt calls to the kernel.
  3. State Installation: The daemon receives join requests and instructs the kernel to install (S,G) or (*,G) entries into the VMR table, allowing the kernel to switch from slow-path processing (passing traffic to the daemon) to fast-path hardware/kernel-level forwarding.

Key Takeaway: To manage multicast routing, you must enable kernel-level mc_forwarding and use a user-space daemon to program the ip_mr_cache table via raw socket control commands.