Answer the question
In order to leave comments, you need to log in
How to send a request through a specific interface?
Hi all!
The server has 4 interfaces on which the Internet hangs eth0 eth1 eth2 eth3
The task is to write software that will make requests through a specific interface.
In general, the question is, how to send a curl request through a specific interface?
I write in golang, but that's not the point, I think
Answer the question
In order to leave comments, you need to log in
I have two addresses on the server on the same interface, to send a request with curl from the desired address, I use
Where NNNN is the IP address from which to send the request.
And man tells us that you can also specify the name of the interface there, a quote from man
--interface <name>
Perform an operation using a specified interface. You can enter interface name, IP address or host name. An example could look like:
curl --interface eth0
Do you mean TCP/UDP requests? Then you just need to configure the routing accordingly, the OS network stack will figure out where to send the packets.
I didn’t check it, but in fact the network works like this ...
https://golang.org/pkg/net/#Interface - from here we take the addresses
https://golang.org/pkg/net/#DialTCP - here as the 2nd parameter ( laddr - local address) insert one of the addresses to choose from and get a connection through the selected interface.
Correct if wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question