ffmpeg with double ethernet interfaces works wrong - linux

A server with double interfaces.
One(eht0) is used for WAN which provides http/ssh services for internet users.
The other(eth1) is used to receive multicast data from intranet.
218.108.132.177 is public network gateway.
125.210.198.1 is private network gateway.
233.49.3.*/24 is multicast address.
10.0.11.*/24 is the source of multicast data.
When the route table is like below, ffmpeg can't read the udp data from eth1, ffmpeg hung up:
rrca#rcasnap02:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
218.108.132.176 * 255.255.255.252 U 0 0 0 eth0
125.210.198.0 * 255.255.255.240 U 0 0 0 eth1
default 218.108.132.177 0.0.0.0 UG 100 0 0 eth0
default 125.210.198.1 0.0.0.0 UG 100 0 0 eth1
or
rrca#rcasnap02:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
218.108.132.176 * 255.255.255.252 U 0 0 0 eth0
125.210.198.0 * 255.255.255.240 U 0 0 0 eth1
default 218.108.132.177 0.0.0.0 UG 100 0 0 eth0
10.0.11.0 125.210.198.1 0.0.0.0 UG 100 0 0 eth1
or
rrca#rcasnap02:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
218.108.132.176 * 255.255.255.252 U 0 0 0 eth0
125.210.198.0 * 255.255.255.240 U 0 0 0 eth1
default 218.108.132.177 0.0.0.0 UG 100 0 0 eth0
233.49.3.0 125.210.198.1 255.255.255.0 UG 100 0 0 eth1
I want to the ffmpeg work right,but now I think the two default route in route table disturb eachother, and I take a try, when the public gateway route is deleted, or the private gateway route is at the head of public default gateway route, ffmpeg works well, I think it read multicast from eth1.But the route table is not thus, ffmpeg can't read data from eth1, I think it read data on eth0(which is not private network interface).
How to do ffmpeg works well with two interfaces at the same time?

You need to configure the correct route for multicast traffic. The kernel does an origin check on all incoming multicast traffic: if it arrives on a different interface from the one it would use to send such traffic it's dropped.
Just set a route for multicast on your eth1 interface:
# route add -net 224.0.0.0/8 dev eth1
Alternatively, disable the origin checking:
# echo 0 > /proc/sys/net/ipv4/conf/eth1/rp_filter

While the answer is correct in that a route is required, I had to route 224.0.0.0/4 (which includes up to 239.255.255.255) as my device was sending the video stream to 239.255.42.42

Related

DNS lookup failing over ethernet but not USB

I currently have two different 5g routers. My PC's wifi doesn't work, so I'm only able to connect either of them through wired connection. The old one that I want to get rid of uses a usb, and works. The new one uses ethernet, and fails with DNS lookup (ping www.google.com fails but ping 8.8.8.8 succeeds.)
resolve.conf looks like:
# Generated by NetworkManager
search lan
nameserver 192.168.1.1
nameserver fe80::d4bb:5cff:fe4e:6313
nameserver fe80::38:40ff:fe30:419e
# NOTE: the libc resolver may not support more than 3 nameservers.
# The nameservers listed below may not be recognized.
nameserver fe80::34e1:ffff:fe65:f72b
nameserver fe80::d43f:21ff:fe59:462a
nameserver 192.168.12.1
nameserver fe80::ca99:b2ff:fee7:71f5%enp5s0
nameserver fe80::d43f:21ff:fe59:462a%enp6s0f1u1
nmcli yields:
enp5s0: connected to Wired connection 1
"Intel I211"
ethernet (igb), 3C:7C:3F:1E:C6:01, hw, mtu 1500
ip4 default, ip6 default
inet4 192.168.12.232/24
route4 192.168.12.0/24 metric 100
route4 default via 192.168.12.1 metric 100
inet6 2607:fb90:3307:6e5d:91df:e64b:949:c78c/128
inet6 2607:fb90:3307:6e5d:bcb3:1b35:1589:bd17/64
inet6 fe80::48f9:3fb0:7e83:d1a7/64
route6 2607:fb90:3307:6e5d:91df:e64b:949:c78c/128 metric 100
route6 2607:fb90:3307:6e5d::/64 metric 100
route6 fe80::/64 metric 1024
route6 default via fe80::ca99:b2ff:fee7:71f5 metric 100
enp6s0f1u1: connected to Wired connection 2
"Novatel Wireless M2000"
ethernet (rndis_host), 00:15:FF:30:51:72, hw, mtu 1428
inet4 192.168.1.5/24
route4 192.168.1.0/24 metric 101
route4 default via 192.168.1.1 metric 101
inet6 2607:fb90:3395:673a:5552:7f52:abd9:488e/64
inet6 fe80::20b0:4b16:c9f:e9d0/64
route6 fe80::/64 metric 1024
route6 2607:fb90:3395:673a::/64 metric 101
route6 default via fe80::d43f:21ff:fe59:462a metric 101
"Wired connection 2" is the one that works (the USB one.)
So I'm pretty clear that my resolv.conf is specifically telling the usb interface to use one DNS server (fe80::d43f:21ff:fe59:462a) that works, and telling the ethernet interface to use another (fe80::ca99:b2ff:fee7:71f5) that fails. I just don't know why it's doing that, or how to make it stop (given that I think NetworkManager generates that file, and will presumably re-generate it if I just edit it myself.)
What happen? What do?

Use ip route add to add multicast routes to multiple devices

TLDR: Is there a way to use "ip route" to add multicast routes for multiple NICs?
We have software that joins two sockets bound to different ip addresses on separate NICS to two separate multicast groups, eg socket 1 is bound to 192.168.0.2 and joined to multicast group 233.255.10.1 while socket 2 is bound to 10.57.31.2 and joined to multicast group 239.255.100.1.
We are currently using a bash script (Linux kernel 3.14.39) to set multicast routes on the two network interfaces using route, eg
route add -net 224.0.0.0 netmask 240.0.0.0 eth0
route add -net 224.0.0.0 netmask 240.0.0.0 eth1
and verified via route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
224.0.0.0 0.0.0.0 240.0.0.0 U 0 0 0 eth0
224.0.0.0 0.0.0.0 240.0.0.0 U 0 0 0 eth1
I recently read that route was deprecated/obsolete and that we should be using ip route instead, eg
ip route add 224.0.0.0/4 dev eth0
ip route add 224.0.0.0/4 dev eth1
Unfortunately, the second call fails with "RTNETLINK answers: File exists" and of course the second route doesn't show up after these calls.
Is there a way to use ip route to add multicast routes to multiple NICs?
I can use /8 as a netmask? eg
ip route add 233.0.0.0/8 dev eth0
and
ip route add 239.0.0.0/8 dev eth1
but this is problematic as the script that does this is not aware of what multicast address is associated with which device and its not always guaranteed to be the same depending on system configuration. Using my first example of route add makes this a non issue.

Route command output

Route command output:
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.10 0.0.0.0 UG 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
$
From the above output the following are the doubts I have:
What is 0.0.0.0 means in destination and gateway column
If the packet is sent from 192.168.2.36 ip, what is the gateway for that. It use 192.168.2.10 or 0.0.0.0
Lets consider I have one more network with ip 192.168.1.0. If the packet is sent from any of the host from this network, what is the
gateway for that ip.
What is default gateway.
On the first line, 0.0.0.0 in Genmask means there is no mask, i.e. in combination with a destination of 0.0.0.0, it means all destinations (the default gateway definition). On the second line, 0.0.0.0 in the gateway column means no gateway (directly connected the local subnet).
When routing, it does not matter where you are sending from, but where you are sending to.
Packets sent to network 192.168.1.0 will be routed using gateway 192.168.2.10, since the first line is the only one that matches destination 192.169.1.0.
192.168.2.10 (see answer 1).

Linux port based routing

I have a requirement to host a java application on a server which can simulate multiple devices each one with separate IP address. The scalability requirements are so large that I cannot think of launching VMs or any containers.
The way I thought about supporting this is to have the application listen on a particular port on 127.0.0.1 , add a route to forward all the packets destined to say 192.168.0.1/24 (internal addresses where clients connected to my server will send packets) forward to 127.0.0.1:
Is this the best way of implementing or any other better options available.
You can create multiple loopback interface, in addition to 127.0.0.1, you can create a loopback interface on 127.0.0.2, 127.0.0.3, etc... Each one of them will be a loopback interface of its own.
ifconfig tells you:
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 353847 bytes 99880673 (95.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 353847 bytes 99880673 (95.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Note that the netmask is 255.0.0.0

ip routing table basics [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
Could you please explain the following basic ip routing table:
Destination Gateway Genmask Flags Metric Ref Use Iface
10.80.0.0 192.176.20.1 255.255.255.0 UG 0 0 0 eth0
192.176.100.0 * 255.255.255.0 U 0 0 0 int1
10.1.1.0 192.176.20.1 255.255.255.0 UG 0 0 0 eth0
10.13.1.0 192.176.100.1 255.255.255.0 UG 0 0 0 int1
192.176.0.0 * 255.255.0.0 U 1 0 0 eth0
default 192.176.20.2 0.0.0.0 UG 0 0 0 eth0
Well you have 2 local interfaces on the router; eth0 and int1. I guess it's easiest to go through line by line of the routing table.
Destination Gateway Genmask Flags Metric Ref Use Iface
10.80.0.0 192.176.20.1 255.255.255.0 UG 0 0 0 eth0
This states that any packet with a destination of 10.80.0.0/24 will be sent out eth0 using a gateway of 192.176.20.1.
Destination Gateway Genmask Flags Metric Ref Use Iface
192.176.100.0 * 255.255.255.0 U 0 0 0 int1
This states that any packet with a destination of 192.176.100.0/24 will be sent out int1 without using a gateway.
Destination Gateway Genmask Flags Metric Ref Use Iface
10.1.1.0 192.176.20.1 255.255.255.0 UG 0 0 0 eth0
This states that any packet with a destination of 10.1.1.0/24 will be sent out eth0 using a gateway of 192.176.20.1.
Destination Gateway Genmask Flags Metric Ref Use Iface
10.13.1.0 192.176.100.1 255.255.255.0 UG 0 0 0 int1
This states that any packet with a destination of 10.13.1.0/24 will be sent out int1 using a gateway of 192.176.100.1.
Destination Gateway Genmask Flags Metric Ref Use Iface
192.176.0.0 * 255.255.0.0 U 1 0 0 eth0
This states that any packet with a destination of 192.176.0.0/16 will be sent out eth0 without using a gateway.
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.176.20.2 0.0.0.0 UG 0 0 0 eth0
This states that any packet that doesn't match any of the above routes will be forwarded out eth0 with a gateway of 192.176.20.2. Most likely a route to the internet (also called Gateway of Last Resort, if I'm not mistaken).
If you need more information, don't hesitate to ask.
Extra info on the specifics: http://www.cyberciti.biz/faq/what-is-a-routing-table/
Destination = the address of the network that the packet is headed to
The "default" means that if the destination is not found in any of the other rules, than use this rule.
Genmask = The subnet mask
If there is more than one address in the routing table that works for the outgoing packet, the rule with the higher subnet mask will be used. If those are tied, then metric comes into play but that will be different based on what protocol is being used.
Interface = On-board connection
For example, the laptop I am on currently has three interfaces:
Ethernet card
Wireless card
Bluetooth
Routers generally have at least 2 interfaces for each side, 1 for each network they are a part of. For most home routers, 1 interface is part of your home network and the other is part of the external network (usually the internet) headed toward your ISP.
Gateway = Next hop
This is where the packet will be sent if the destination is not on the same network as the sender.
If the value is "*" or "On-link" or the address of the current device... these all mean the same thing. It means that the packet is addressed to a device that is directly reachable by the current host. In other words, they're on the same network so the gateway won't actually be used because the host will know the data link layer (MAC) address of the destination and be able to send it directly there. These values are just used for human readability in this case.
As for the process of sending a packet:
Destination and Genmask are used to figure out which rules are a
match for the destination address of the outgoing packet.
Interface is used to decide what communication device on the machine
to send it through.
Gateway is the address of the device on the same network that it will
send the packet to.

Resources