Answer the question
In order to leave comments, you need to log in
How to run an application in Linux from a second IP address?
Linux has two network addresses on the same interface 192.168.2.10 and 192.168.2.20. By default, all programs work through the IP 192.168.2.10, but I need to run the snmpwalk program so that it connects to the router from the address 192.168.2.20. Routes cannot be changed because other programs may stop working.
Question - how to do it?
Answer the question
In order to leave comments, you need to log in
I need to run the snmpwalk program so that it connects to the router from the address 192.168.2.20
echo clientaddr 192.168.2.20 >> ~/.snmp/snmp.conf
IPTABLES -t mangle -A OUTPUT -m owner --uid-owner <тут id овнера процесса> -j MARK --set-mark 2
ip route add default via DE.SI.RED.IP table 120
ip rule add fwmark 2 lookup 120
Advanced programs written by smart programmers have the key to select an IP address. Especially open source programs - there, if someone needs it, he adds it himself and, with the consent of the author, adds edits to the official source.
If the program doesn't know how to do this, you can run a virtual machine (or a full-fledged one, or something like Jail in FreeBSD) so that the program running inside the virtual machine can use only the desired IP address.
And finally, you can organize NAT to force the replacement of the outgoing IP address. The problem is how to separate the necessary traffic to wrap it in a NAT machine - this needs to be dug separately. Perhaps here you can select traffic on the TCP / UDP port. And you can enable NAT only for the duration of the desired program.
The outgoing interface is the interface that provides the route to the requested ip.
If you want to "break" this and understand what you are doing - you can try to redirect traffic through a specific interface - for example, through iproute2 - it allows, for example, traffic marked in iptables to be redirected to a specific interface.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question