How Do I Forward Multicast Traffic Between 2 Differant Lans Using Iptables?
How Do I Forward Multicast Traffic Between 2 Differant Lans Using Iptables?
Goal:
Need lmc or "LAN Messenger" [1] to work on 2 lans separated by a Linux gateway using iptables.
Information:
iptable rules:
filter table:
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -i lo -j ACCEPT
-A FORWARD -i slan1 -o olan1 -j ACCEPT
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m iprange --src-range 192.168.2.100-192.168.2.254 -j ACCEPT
-A FORWARD -i olan1 -o slan1 -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -j ACCEPT
-A FORWARD -i olan1 -o slan1 -p tcp -m tcp --dport 9696 -m conntrack --ctstate NEW -j ACCEPT
-A FORWARD -i olan1 -o slan1 -p tcp -m tcp --dport 50000 -m conntrack --ctstate NEW -j ACCEPT
-A FORWARD -i olan1 -o slan1 -p udp -m udp --dport 50000 -m conntrack --ctstate NEW -j ACCEPT
-A FORWARD -s 224.0.0.0/4 -d 224.0.0.0/4 -j ACCEPT
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -p igmp -j ACCEPT
-A FORWARD -i olan1 -o slan1 -j DROP
nat table:
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-A POSTROUTING -j MASQUERAD
-A FORWARD -i olan1 -o slan1 -p tcp -m tcp --dport 50000 -m conntrack --ctstate NEW -j ACCEPT
-A FORWARD -i olan1 -o slan1 -p udp -m udp --dport 50000 -m conntrack --ctstate NEW -j ACCEPT
-A FORWARD -s 224.0.0.0/4 -d 224.0.0.0/4 -j ACCEPT
-A FORWARD -p igmp -j ACCEPT
Monitored the traffic of the gateway using tcpdump, I never saw multicast traffic go through as I changed iptable rules.
[1] http://lanmsngr.sourceforge.net/
Doesn't multicast use some broadcasting as well? Don't think a gateway will forward broadcast traffic. - datUser
I am starting to that that is so. Is that what the programs pimd and smcroute do? - jc__
Why does it have to be iptables, and not a multicast routing demon like mrouted or similar (which is the intended way to handle this situation)? I am not even sure
you actually can do this with iptables. - dirkt
I just tested smcroute with two network namespaces and two veth pairs. Setup:
The Debian smcroute package is version 2.0.0, and doesn't seem to support virtual eth, so I installed version 2.3.1 from the smcroute homepage [1]. The
multicast route howto [2] of smcroute is also very helpful.
www.stackprinter.com/export?question=386490&service=unix.stackexchange 1/3
3/20/2019 How do I forward multicast traffic between 2 differant lans using iptables?
I used the ssmping package to test multicasts. I ran ssmpingd in ns2, while pinging with ssmping -4 -I veth0b 10.0.1.1 from ns1. These are source-specific
multicasts (SSM) using group 232.43.211.234, you can also test any-source multicasts (ASM) with asmping. I don't know what LAN messenger uses.
I enabled forwarding in the main namespace to allow the unicast ping requests to get through, then did
and everything worked fine. I would expect it also to work, adjusted to your setup, though you also may have to smcroutectl join to tell your switches they
should forward multicasts properly. Multiple tcpdump terminal windows on all relevant interfaces greatly help with debugging.
To be able to setup multicast routes a program must connect to the multicast routing socket in the kernel, when that socket is closed, which is done
automatically when a UNIX program ends, the kernel cleans up all routes.
This means if you intend to use the multicast routing feature of the kernel, you must use a demon, not a commandline tool.
The intended purpose of smcroute is to aid in situations where dynamic multicast routing does not work properly. However, a dynamic multicast
routing protocol is in nearly all cases the preferred solution. The reason for this is their ability to translate Layer-3 signalling to Layer-2 and vice
versa (IGMP or MLD).
Finally, pay close attention to the TTL that is produced by your LAN messenger, see multicast FAQ [3] at the end.
[1] http://troglobit.github.io/smcroute.html
[2] http://troglobit.github.io/multicast-howto.html
[3] http://troglobit.github.io/multicast-howto.html
Thank you for you detailed answer. I am a little fuzzy about vethX. Are these virtual adapters? Where did you create them? Are the virtual adapters a "pipe" between
the 2 physical adapters? - jc__
If I created a virtual "pipe" will that help the routing table adjustment I made? See my answer: - jc__
(1) Thank you again. I will accept you answer because I followed your advice on what program to use, the TTL info, and all the extra info you included. - jc__
1
I will try smcroute and/or pimd from the ubuntu repositories. So far I have not been able to make either one work.
Using smcroute:
iptables
-A INPUT -i lo -j ACCEPT
-A FORWARD -i slan1 -o olan1 -j ACCEPT
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -p igmp -j ACCEPT
-A FORWARD -i olan1 -o slan1 -p tcp -m tcp --dport 50000 -m conntrack --ctstate NEW -j ACCEPT
-A FORWARD -i olan1 -o slan1 -p udp -m udp --dport 50000 -m conntrack --ctstate NEW -j ACCEPT
-A PREROUTING -d 239.255.100.100/32 -j TTL --ttl-set 64
Extracted to /opt
/usr/local/etc/smcroute.conf
sudo smcrouted
www.stackprinter.com/export?question=386490&service=unix.stackexchange 2/3
3/20/2019 How do I forward multicast traffic between 2 differant lans using iptables?
ROUTE (S,G) INBOUND PACKETS BYTES OUTBOUND
(*, 239.255.100.100) slan1 0 0 olan1
(*, 239.255.100.100) olan1 0 0 slan1
(10.10.10.154, 239.255.100.100) slan1 2 344 olan1
(192.168.2.53, 239.255.255.250) olan1 4 776
(10.10.10.101, 239.255.100.100) slan1 1 32 olan1
(192.168.2.101, 239.255.100.100) olan1 1 32 slan1
(10.10.10.1, 239.255.100.100) slan1 2 64 olan1
/etc/init/smcroute.conf
Everything seems to work. Will let things run for a while with random reboots and occasional network outages, normal stuff.
TODO
[1] ftp://ftp.troglobit.com/smcroute/smcroute-2.3.1.tar.xz
www.stackprinter.com/export?question=386490&service=unix.stackexchange 3/3