From: Gdss on
Hello everybody,

I'm in a situation where I have 2 network interfaces, each one has a public
ip address, and the default route is set on the interface 0.

If I wanted to use interface 1 for the application I'm about to launch, how
could I do?

Let's imagine I want to do a ping using as source address the IP of the
interface 1, and I want packets generated by it routed through interface 1.
Is that possible?

I tried doing "ping -I <address of interface 1> destination" and it seems to
work. I also tried to do an ssh -b <address of interface 1> destination,
but it doesn't work.

Any hints?
Thank you very much.
From: David Schwartz on
On Jan 22, 2:52 am, Gdss <g...(a)picaciux.it> wrote:
> Hello everybody,
>
> I'm in a situation where I have 2 network interfaces, each one has a public
> ip address, and the default route is set on the interface 0.
>
> If I wanted to use interface 1 for the application I'm about to launch, how
> could I do?
>
> Let's imagine I want to do a ping using as source address the IP of the
> interface 1, and I want packets generated by it routed through interface 1.
> Is that possible?
>
> I tried doing "ping -I <address of interface 1> destination" and it seems to
> work. I also tried to do an ssh -b <address of interface 1> destination,
> but it doesn't work.
>
> Any hints?
> Thank you very much.

Your question seems to be a bit confused. Which interface is used to
transmit a packet has nothing whatsoever to do with the source address
of the packet. The choice of outbound interfaces depends on the
*destination*, not the source.

If a machine has two interfaces, 'A' numbered 192.168.31.1/24 and 'B'
numbered 129.168.34.1/42, it will use interface 'A' if the
*destination* is 192.168.31.5 even if the source is 192.168.34.1.

DS
From: Moe Trin on
On Tue, 22 Jan 2008, in the Usenet newsgroup comp.os.linux.networking, in
article <fn4pv6$pa8$1(a)news.unina.it>, Gdss wrote:

>I'm in a situation where I have 2 network interfaces, each one has a
>public ip address, and the default route is set on the interface 0.
>
>If I wanted to use interface 1 for the application I'm about to launch,
>how could I do?

"Policy Routing"

[compton ~]$ whatis ip tc
ip (8) - show / manipulate routing, devices, policy routing and tunnels
tc (8) - show / manipulate traffic control settings
[compton ~]$

See the Adv-Routing-HOWTO for additional details.

-rw-rw-r-- 1 gferg ldp 297491 Sep 4 2003 Adv-Routing-HOWTO

But this also assumes that the application can be bound to a specific
interface. Some allow this, some don't.

Old guy

From: habibielwa7id on
On Jan 22, 12:52 pm, Gdss <g...(a)picaciux.it> wrote:
> Hello everybody,
>
> I'm in a situation where I have 2 network interfaces, each one has a public
> ip address, and the default route is set on the interface 0.
>
> If I wanted to use interface 1 for the application I'm about to launch, how
> could I do?
>
> Let's imagine I want to do a ping using as source address the IP of the
> interface 1, and I want packets generated by it routed through interface 1.
> Is that possible?
-It's all about routing man, I use the ping command with -i only when
I have 2 gateways to the Internet, And this setup called multipath
routing or dual routing, Check www.lartc.org for details.
-But if you don't have 2 Internet connections so why you use -i or
whatever, The Linux routing table will lead the application to it's
destination as it should go according to the routing table. You can
force your system to go through a specific interface when you want to
reach specific host through this interface with the route command
like, route add -host 11.22.33.44 gw 192.168.1.2, This way your system
will go to 11.22.33.44 through 192.168.1.2 interface. I wish I could
help someway.
> I tried doing "ping -I <address of interface 1> destination" and it seems to
> work. I also tried to do an ssh -b <address of interface 1> destination,
> but it doesn't work.
>
> Any hints?
> Thank you very much.
Regards,
From: Gdss on
David Schwartz wrote:

> On Jan 22, 2:52 am, Gdss <g...(a)picaciux.it> wrote:
>> Hello everybody,
>>
>> I'm in a situation where I have 2 network interfaces, each one has a
>> public ip address, and the default route is set on the interface 0.
>>
>> If I wanted to use interface 1 for the application I'm about to launch,
>> how could I do?
>>
>> Let's imagine I want to do a ping using as source address the IP of the
>> interface 1, and I want packets generated by it routed through interface
>> 1. Is that possible?
>>
>> I tried doing "ping -I <address of interface 1> destination" and it seems
>> to work. I also tried to do an ssh -b <address of interface 1>
>> destination, but it doesn't work.
>>
>> Any hints?
>> Thank you very much.
>
> Your question seems to be a bit confused. Which interface is used to
> transmit a packet has nothing whatsoever to do with the source address
> of the packet. The choice of outbound interfaces depends on the
> *destination*, not the source.
>
> If a machine has two interfaces, 'A' numbered 192.168.31.1/24 and 'B'
> numbered 129.168.34.1/42, it will use interface 'A' if the
> *destination* is 192.168.31.5 even if the source is 192.168.34.1.

So, if I explicity binded to one ip address, that would just mean that the
source ip address would set to that ip address? So that is not a bind to an
interface, but a mere selection of the source address?
Thus there is no bind to an interface?

I did this test:
I started an umts connection (ppp0 has been created);
I unplugged the ethernet cable
Then I did this:

wget --bind-address <ppp0 ip> http://XXXXXXXXXXX /index.php
--12:36:08-- http://XXXXXXXXXXX /index.php
=> `index.php'
Risoluzione di www.XXXXXXXXXXX in corso... 62.149.140.20
Connessione a XXXXXXXXXXX |62.149.140.20:80... failed: No route to the host

So, this confirms your statement.

Then I did:
ping -I ppp0 209.85.129.104 (google)
PING 209.85.129.104 (209.85.129.104) from YYYYYYYYYYY ppp0: 56(84) bytes of
data.
64 bytes from 209.85.129.104: icmp_seq=1 ttl=241 time=2257 ms
64 bytes from 209.85.129.104: icmp_seq=2 ttl=241 time=1276 ms
64 bytes from 209.85.129.104: icmp_seq=3 ttl=241 time=277 ms
64 bytes from 209.85.129.104: icmp_seq=4 ttl=241 time=187 ms

YYYYYYYYYYY (eth0 ip address!!)

The things I don't understand:
1) why ping uses the ip address of eth0
2) why packets get routed through ppp0 interface.

Is that due to the difference between a tcp socket and icmp packets?

Thanks.