K
K
KARLS0N2020-04-17 21:42:57
linux
KARLS0N, 2020-04-17 21:42:57

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

6 answer(s)
J
jcmvbkbc, 2020-04-17
@jcmvbkbc

I need to run the snmpwalk program so that it connects to the router from the address 192.168.2.20

I think that this should help: echo clientaddr 192.168.2.20 >> ~/.snmp/snmp.conf
See .
In general, there is no one recipe: the application itself must do bind for the socket from which it sends requests, each application does this in its own way (or does not do it at all).

D
Dmitry, 2020-04-18
@hempy80

linux network namespaces

H
hellfleet, 2020-04-28
@hellfleet

IPTABLES -t mangle -A OUTPUT -m owner --uid-owner <тут id овнера процесса>  -j MARK --set-mark 2

Next, make a routing table
ip route add default via DE.SI.RED.IP table 120
Next, the rule
ip rule add fwmark 2 lookup 120
is something like this

S
Sergey Karbivnichy, 2020-04-17
@hottabxp

Multiple IP addresses on one network adapter

K
Karpion, 2020-04-17
@Karpion

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.

A
Alexey Dmitriev, 2020-04-20
@SignFinder

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 question

Ask a Question

731 491 924 answers to any question