How to specify network interface with Ruby's F

2019-07-22 15:29发布

I'm using Faraday which wraps various adapters, including Net::HTTP, Excon, Typhoeus, Patron, and EventMachine. I would like to specify the network interface (e.g. en0 or en1), but I'm not sure how or if it is possible. I'd be open to answers at the Ruby level or the Linux level.

Note: According to Making HTTP requests from different network interfaces with Ruby and Curb, this is possible with Curb.

3条回答
萌系小妹纸
2楼-- · 2019-07-22 16:08

I came across this issue with Typhoeus (not using Faraday) and binding to a specific local interface. The following worked for me:

options = {
  interface: '<ip address>'
}
req = Typhoeus::Request.new("https://example.com/3", options)
查看更多
唯我独甜
4楼-- · 2019-07-22 16:24

Not sure if it is possible to bind to specific network interface, but with Faraday you can set request option :bind to {:host => "<your_ip>", :port => "<your_port>" } to specify at least IP address and port.

As far as I know em-http, em-synchrony, httpclient & typhoeus adapters respect these settings.

查看更多
登录 后发表回答