Author Topic: [Not Possible] Choosing a NIC in the Browser  (Read 2268 times)

Offline muungwana

  • Hero Member
  • *****
  • Posts: 6198
Re: [Not Possible] Choosing a NIC in the Browser
« Reply #15 on: January 08, 2011, 04:09:49 PM »

"ping  whatismyip.com" says the IP address of this website is "72.233.89.197"

if you want all traffic to that address to go through "wlan0", all you will have to do is run this command to add this route to the routing table of the computer

Quote
route add -host 72.233.89.197 gw 192.168.1.254

when you dont want traffic to that host to go through that interface and want it to go through the default one then just delete the route with this command

Quote
route del -host 72.233.89.197 gw 192.168.1.254

"192.168.1.254" is the IP address of "wlan0" interface on your computer.

you can check the gateway in use by using "tracepath" command. Just type "tracepath whatismyip.com" and look at the first entry.

"whatismyip.com" is one of those websites with multiple IP addresses and hence you may get a different address each time you DNS the address. Just try "ping whatismyip.com" multiple times and you will get different IP addresses returned.

To work around this, add the following line to "/etc/hosts" text file. This will make sure your computer resolves to the same IP addresses each time every application asks for "whatismyip.com" IP address.

Quote
72.233.89.197    whatismyip.com
.. 3 things are certain in life : death, taxes and software bloat ..
.. tell me something i don't know, something i can use as i struggle to reason with the world around me ..

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: [Not Possible] Choosing a NIC in the Browser
« Reply #16 on: January 08, 2011, 04:36:00 PM »
muungwana,
                       thanks for the response.
I just used that URL as an example not as something I might be using in the future.
I am using it for test purposes ......  as it reports what IP address the connection is made from. In that way I am very sure which NIC is being used to make the connection.

Code: [Select]
route add -host 72.233.89.197 gw 192.168.1.254
The present difficulty is that the 'route' command requires root privileges, so is not available to the user.
I may have to set up something in the sudoers file for it.

I do not wish to have to specify a host .......  but it seems I must?

What I am aiming to do at this time to see if it works for me is to use a script into which I will put some URL or other that I wish to connect to, using the wlan0 NIC.
So I guess that will have something like this

1. route command to make wlan0 default
2. command to launch browser or wget or whatever to connect to some URL yet to be determined.
3. route command to undo 1.

Presumably the connection made in 2. above will continue using wlan0 even after 3. has been executed.
If not then it won't work for me.

****

I am trying to find a method to use a particular NIC for some connections .......  and if I have to use a script to achieve that then I will test it for a while to see if it fits in.
What I connect to, or use for the connection, cannot be predetermined.
So setting up static routes is not of any use apparently.

But if I can make the wlan0 NIC the default or whatever, make the connection, then revert the change, and have the connection continue on that NIC, while I use the eth0 NIC for other connections then all should be OK.

Thanks again for your post.

regards.


Offline muungwana

  • Hero Member
  • *****
  • Posts: 6198
Re: [Not Possible] Choosing a NIC in the Browser
« Reply #17 on: January 08, 2011, 05:03:32 PM »
"route" command does require root privileges and you may need to set up sudo to handle it if you want to access it from a normal user account without entering passwords.

It is my understanding(you may need to test to confirm), the routing table is consulted when the connected is about to be made and a change in routing table have no effect on an already established connected and hence your 3 steps should work just fine, you may need to test though to confirm.

In those three steps, step one will be running
Quote
route add default gw 192.168.1.254

Step three will be running:
Quote
route del default gw 192.168.1.254

Here, you are changing the default route and hence no need to add specific routes to specific hosts. The need to add specific hosts is necessary only if the default route is on one interface and you want traffic to go through another.

All traffic in step two will go through this interface and will continue to do so after step three if they dont drop the connection because the routing table may be consulted on reconnect attempt.
.. 3 things are certain in life : death, taxes and software bloat ..
.. tell me something i don't know, something i can use as i struggle to reason with the world around me ..

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: [Not Possible] Choosing a NIC in the Browser
« Reply #18 on: January 08, 2011, 05:26:56 PM »
Quote
All traffic in step two will go through this interface and will continue to do so after step three if they dont drop the connection because the routing table may be consulted on reconnect attempt.

It should work so ......  will do some tests tomorrow to see how it goes.

Thanks.