3

Assuming multiple network interfaces (eth0, eth1...), how can I specify which one I would like to use?:

  • Can I specify per-application which network interface should be used?
  • Can I specify system-wide which network interface should be used (without necessarily disabling all the other 'competing' interfaces)?
    • If other interfaces must be disabled, is it possible to later (easily) recover the prior configurations of those other interfaces?

Thanks.

ChaimKut
  • 191
  • 4
  • 9

1 Answers1

2
  • Can I specify per-application which network interface should be used?

Yes. Use the per-application configuration options to bind it to the interface or an address assigned to the interface.

  • Can I specify system-wide which network interface should be used (without necessarily disabling all the other 'competing' interfaces)?

No.

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
  • To clarify, I'm writing an application and I would like my user to choose which network interface to use. How can I tell the OS that I would only like to communicate via a specific interface? Thanks. – ChaimKut May 19 '13 at 07:12
  • @ChaimKut: `bind(3)` to specific addresses. – Ignacio Vazquez-Abrams May 19 '13 at 07:29
  • 2
    Binding has nothing to do with which network interface is used, it just specifies which local address is used. The interface being used is determined by the routing policy database and the selected routing tables. However, you can configure the routing policy database to select different routing tables depending on the source address to achieve the same effect. – BatchyX May 19 '13 at 08:53
  • @BatchyX Well, you bind a static IP usually to only one interface. – mate64 May 19 '13 at 20:27
  • 2
    @cept0: Repeat after me: Binding (on linux) has nothing to do with which network interface is used. You can perfectly bind to `eth0`'s local address, but if your routing table/RPDB say your destination is via `eth1`, `eth1` will be used anyway. The only thing that you change with `bind()` is the source address of the packet. – BatchyX May 19 '13 at 20:34