F
F
faangelius2017-08-11 12:32:24
linux
faangelius, 2017-08-11 12:32:24

How to send UDP packets through a specific interface?

Greetings!
The PC has three interfaces eth0, eth1, eth2. Each interface is connected to data communication equipment.
Each interface has its own static address, for example eth0 has 192.168.255.200/16, eth1 2.255.1.2/30, eth2 2.255.2.2/30. With the last two interfaces I tried in different ways, while I have problems with routing. Attempts to rigidly set the route were also unsuccessful.
The task is to check the transmission of UDP packets through the equipment. That is, the packet must go to eth1, "pass" through the equipment and get to eth2. The problem is that the system does not send packets to the interface and then to the equipment, but immediately "receives" them on eth2.
I write software in C++ under Astra Linux 1.5.
How to force the system to send packets to the desired interface? What is the general way to solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2017-08-11
@faangelius

the packet must go to eth1, "pass" through the equipment and get to eth2. The problem is that the system does not send packets to the interface and then to the equipment, but immediately "receives" them on eth2.

That's right, without tricks, this scheme will not work.
Possible tricks:
- send a packet through a RAW socket so that the kernel router does not interfere;
- send the packet not to the eth2 address, but to another address. Edit the destination address with iptables, in the mangle table, in the POSTROUTING chain.

M
Mystray, 2017-08-13
@Mystray

This is because linux will never send everything that is intended for itself to the outside.
A possible way out is to move one of the interfaces to a dedicated Network Namespace. Then this interface will disappear from the main system and appear already in this namespace, along with its own separate routing table and firewall rules.
Accordingly, one of the applications also run inside this namespace.
But it should be borne in mind that the application will either work in the main system, or work in this namespace, and they will not have any network interaction except through "outside" (if you do not do this explicitly)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question