1

I am on a network which has a default route via eth0. There is another interface eth1 which can also handle a packet sent to a destination I am interested in. I will be making calls to this destination IP via the requests module.

Is there a way to define which interface the requests call should go though, at the script level?

I know I can modify the routing in order to force the route but I would like to understand if there is not a via eth0 concept I could use within the Python script.

WoJ
  • 27,165
  • 48
  • 180
  • 345
  • Without more information it sounds like your routing is not setup correctly. If eth1 is the best route to the host you want to connect to why isn't the routing tables setup to do that automatically? /etc/host does not change the route, only the name to IP lookup. – Barry Scott Jun 07 '16 at 09:36
  • The target IP can be reached by either of these routes. The routing is correct, there is one `default` route via `eth0` (which is normal - the packet must go somewhere if there is no explicit routing). What I want to do is bypass this `default` route from within my script (without changing the routing table) – WoJ Jun 07 '16 at 10:31
  • about `/etc/hosts`: I know that it does not change the routing, I was thinking about tricks to force the resolution of a host to an IP which would then route though `eth0`if a route is available. But after re-reading myself, this is not relevant to the question so I just deleted that part not to raise confusion. Thanks. – WoJ Jun 07 '16 at 10:38
  • If `eth0` and `eth1` have different IP addresses, then see: “[Python Requests, how to bind to different source ip for each request?](http://stackoverflow.com/questions/28773033)” – Vasiliy Faronov Jun 07 '16 at 12:54

0 Answers0