Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple physical NICs #9

Open
Aqua1ung opened this issue Dec 19, 2022 · 12 comments
Open

Multiple physical NICs #9

Aqua1ung opened this issue Dec 19, 2022 · 12 comments

Comments

@Aqua1ung
Copy link

Currently testing BindToInterface on my Ubuntu Kinetic. I have two physical NICs, one wired, and one wireless. Need ssmtp to use the wireless one: BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=./bindToInterface.so /usr/sbin/ssmtp, however, regardless of the value of BIND_INTERFACE, it still uses the wired NIC. (Testing with curl ifconfig.me tells me precisely that.) What am I doing wrong? Should I go to the trouble of messing with the route metrics? Does that not defeat the purpose of using BindToInterface in the first place?

@JsBergbau
Copy link
Owner

Halo Aqua1ung
Is your wireless NIC using another internect connection. It looks like, because this kind of error didn't happen so far.
Another thing: Especially in case of errors or malfunction, you should use absolut path for bindToInterface https://github.com/JsBergbau/BindToInterface#specifying-absolute-path

@Aqua1ung
Copy link
Author

Aqua1ung commented Dec 20, 2022

Halo Aqua1ung Is your wireless NIC using another internect connection. It looks like, because this kind of error didn't happen so far. Another thing: Especially in case of errors or malfunction, you should use absolut path for bindToInterface https://github.com/JsBergbau/BindToInterface#specifying-absolute-path

Yes, both NICs are connected to the Internet: is that not supported? And yes, I am using the absolute path for bindToInterface.

@JsBergbau
Copy link
Owner

Can you please post the output of
BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=<absolute Path to bindToInterface.so> curl ifconfig.me
and output of
curl --interface wlp1s0 ifconfig.me

@Aqua1ung
Copy link
Author

Aqua1ung commented Dec 21, 2022

dad@mificommander:~$ curl --interface wlp1s0 ifconfig.me
98.221.xxx.xxx
dad@mificommander:~$ curl --interface wlp1s0 ifconfig.me
98.221.xxx.xxx
dad@mificommander:~$ BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=/usr/lib/bindToInterface.so curl ifconfig.me
172.58.xxx.xxx
dad@mificommander:~$ curl --interface wlp1s0 ifconfig.me
98.221.xxx.xxx
dad@mificommander:~$ BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=/usr/lib/bindToInterface.so curl ifconfig.me
172.58.xxx.xxx
dad@mificommander:~$ curl --interface wlp1s0 ifconfig.me
98.221.xxx.xxx
dad@mificommander:~$ BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=/usr/lib/bindToInterface.so curl ifconfig.me
172.58.xxx.xxx

See also here.

[Edit] Once in a blue moon I also get 98.221.xxx.xxx from BIND_INTERFACE=wlp1s0. All in all, pretty random it seems.

@JsBergbau
Copy link
Owner

Please uncomment the line
//#define DEBUG recompile and post the full output of BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=/usr/lib/bindToInterface.so curl ifconfig.me

@Aqua1ung
Copy link
Author

Not sure what "uncomment" would mean in C. Should I remove the whole //# string, or just the //? (Where I come from # means "comment")

@JsBergbau
Copy link
Owner

Just remove the //.
# is the so called preprocessor. It changes the code before it is presented to the compiler. Some kind of effiency measure.

@Aqua1ung
Copy link
Author

Aqua1ung commented Dec 21, 2022

Here goes:

dad@mificommander:~$ BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=/usr/lib/bindToInterface.so curl ifconfig.me
connecting to: 34.160.111.145:80 
Bound Interface: none. Socket not bound to desired interface (Bound to: none). Binding to interface: wlp1s0
98.221.xxx.xxx 
dad@mificommander:~$ BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=/usr/lib/bindToInterface.so curl ifconfig.me
172.58.xxx.xxx 
dad@mificommander:~$ BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=/usr/lib/bindToInterface.so curl ifconfig.me
172.58.xxx.xxx

[Edit] As far as I can tell, it looks like the BIND_INTERFACE directive only kicks in once in a blue moon, despite being invoked every time. I wonder why that would be? Am I doing something wrong?

@JsBergbau
Copy link
Owner

It looks like LD_PRELOAD isn't respected every time. That is really strange and seems some kind of Linux issue.
I'm using BindToInterface with multiple VPNs and microsocks https://github.com/rofl0r/microsocks and this works like a charm.
Could you try to place the library in your home path? I have it there and it works every time.

@Aqua1ung
Copy link
Author

Could you try to place the library in your home path? I have it there and it works every time.

You mean move bindToInterface.so to ~/?

@Aqua1ung
Copy link
Author

Aqua1ung commented Dec 23, 2022

Here goes:

dad@mificommander:/usr/lib$ curl --interface wlp1s0 ifconfig.me
98.221.xxx.xxx
dad@mificommander:/usr/lib$ BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=~/bindToInterface.so curl ifconfig.me
connecting to: 34.160.111.145:80 
Bound Interface: none. Socket not bound to desired interface (Bound to: none). Binding to interface: wlp1s0
98.221.xxx.xxx 
dad@mificommander:/usr/lib$ BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=~/bindToInterface.so curl ifconfig.me
172.58.xxx.xxx
dad@mificommander:/usr/lib$ BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=~/bindToInterface.so curl ifconfig.me
172.58.xxx.xxx
dad@mificommander:/usr/lib$ curl --interface wlp1s0 ifconfig.me
98.221.xxx.xxx

And here's an even more interesting one:

dad@mificommander:/usr/lib$ BIND_INTERFACE=wlp1s0 DNS_OVERRIDE_IP=8.8.8.8 LD_PRELOAD=~/bindToInterface.so curl ifconfig.me
connecting to: 34.160.111.145:80 
Bound Interface: none. Socket not bound to desired interface (Bound to: none). Binding to interface: wlp1s0
172.58.xxx.xxx

[Edit] Also, I've seen some opinions that LD_PRELOAD is unsuitable for this task, and I quote: "Because LD_PRELOAD does not control the route that the processes uses. It will use the first route. And since it always uses the same route, it will default to the interface registered to the route.(which is not what we want)"

@JsBergbau
Copy link
Owner

Thats really strange and currently I have no idea whats happening there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants