WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How to properly setup HAProxy MC/TC 11.1 x86?  (Read 1690 times)

Offline Santos

  • Full Member
  • ***
  • Posts: 105
How to properly setup HAProxy MC/TC 11.1 x86?
« on: July 08, 2021, 04:54:37 PM »
Hello there.

I was trying to configure a simple proxy server on my computer. What I want to do is route incoming traffic/requests from a specific port over TCP and have the client access to the internet through my HAProxy server.

Something like this, but without  Squid  (not in the repo):
https://unix.stackexchange.com/questions/116191/give-server-access-to-internet-via-client-connecting-by-ssh

Why?
I have a rooted android device with Debian Buster on it. The phone is a cheap flip phone, great to play with. The ARM processor is handeling the  proot  envorinment and when the network load is intense (using youtube-dl or installing packages with apt) the connection drops to around 512 bytes/sec.
So, I want to share the lighting speed of my laptop's NIC (10/100, haha) with my phone. I've made some tests, the phone is perfectly capable of transferring data at around 5 Mbytes/sec which probably with the TCP/IP overhead plus ssh I would think 3 Mbytes/sec would be it's top speed, which is fine for me.

Anyway, I will proceed to describe the process I use to have access to my phone and how I normally use Debian on it.

Code: [Select]
## This binds port 9999 on my computer (client) to port 22 on my phone (server).
#adb forward tcp:9999 tcp:22
## Accesing to the "server" and exposing the "client" ssh port (22) to the phone in a reverse tunneling configuration with ssh.
## ssh server is already configured in my computer. I just need to use the port that I made available from my computer, like so:
#ssh -R 9999:localhost:22 cheaphone@localhost -p 9999
# I'm logged into my phone, running Debian Buster. Now, I want to convert the phone into the "client" and my computer into the "server".
## sshfs to access my HDD from my phone. Logged as root on both devices (computer and phone).
#$phone@debian#: sshfs root@localhost:/mnt/sda1 /home/android/tsda1 -p 9999
## After making my HDD available to my phone I would like to set up the proxy server, as the previous link (unixexchange) suggest:
## This is the step where I'm stuck at. I now this will configure the proxy connection on the phone, but I do not know how to route the request from my phone, with my laptop and route it to the internet via eth0.
#$phone@debian#: export http_proxy=http://127.0.0.1:3129 ; export https_proxy=http://127.0.0.1:3129

1/2

Offline Santos

  • Full Member
  • ***
  • Posts: 105
Re: How to properly setup HAProxy MC/TC 11.1 x86?
« Reply #1 on: July 08, 2021, 04:55:33 PM »
2/2


Basically, I want to bind another port and use whatever program is suitable for a proxy, and specially available on TC repo: redsocks, haproxy, polipo, proxychains-ng, etc.
Probably I'll be doing something like this:

Code: [Select]
## Bind a new port from my computer to my phone
## /adb/ is the binary used to talk to the phone,  /forward/  binds the local port and the remote port like this: adb forward tcp:local-port-to-bind tcp:remote-port-on-the-phone
#adb forward tcp:3128 tcp:3129
## After doing so, I assume the proxy server will not complaing about the port being used already, hence allowing me to route all traffic from my phone through port 3129 into my laptop's port 3128 and send all traffic to eth0 back and fort..

The set up I got is:
Code: [Select]
Rooted android phone
MicroCore 11.1 x86
ssh
sshfs
adb
Android phone plugged in with a cable (micro usb).
Network setup automagically with DHCP, no firewall, no VPN, no extra proxies, no extra gateways or devices messing with the network.
I do have an extra router, but doesn't do any network managment whatsoever it is setup as a network switch.

My network goes like this:
Phone -> USB cable -> laptop -> Ethernet cable -> Router acting as a network switch -> Ethernet cable -> main router -> ISP *Internet*

Pretty much is like setting up two computers on the same network, one (my laptop) will be the simple-enough-proxy-server-to-get-internet-access and my phone will be the client.

I've been reading like crazy all configurations, tutorials, posts and wikis of HAProxy, I'm just so confused because all info. is about how to set up a load balancing server or super complicated servers for routing specific datagrams with SSL, certificates, HTTPS, wrap packets in different network protocols and such. But I'm not able to find a tutorial to setup a simple proxy server (Which I think HAProxy can't do, but it DOES routing of packages from one interface to another, which is what I want from usb to ethernet and viceversa).

Any approach would be very much welcomed, either a proxy server or routing from one port to the other, as long as I can route the eth0 connection to the binded port on localhost to my phone plugged via a usb cable.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10960
Re: How to properly setup HAProxy MC/TC 11.1 x86?
« Reply #2 on: July 08, 2021, 11:01:04 PM »
HAproxy is the wrong tool for what you want. You don't want a proxy at all, you want to set up your laptop as a router, from usb0 etc to eth0. Masquerading is the keyword to google for, this setup is done with iptables.
The only barriers that can stop you are the ones you create yourself.

Offline Santos

  • Full Member
  • ***
  • Posts: 105
Re: How to properly setup HAProxy MC/TC 11.1 x86?
« Reply #3 on: July 08, 2021, 11:24:54 PM »
Thank you.

I was going with the network approach, since everything is exposed to the network and since I got a successful SSH connection I thought tunneling would be the answer. Because my computer can not see the phone as a usb0 address (it does but usb0 will provide internet, having usb0 as a Incoming connection on the phone is, I think, not possible or near impossible). And android is so restricted that doing the routing with the bare interfaces as usb0 on the phone will not work, this is what I first tried but the way Android sees connections and network data is very categorical: Java and C "subsystem" one can not access the other, meaning if I got usb0 to receive connection from the laptop, the app (linuxdeploy) emulating Debian will simply not even see the connection.

I'm trying to give internet access to the distro being emulated, to the proot environment not to the phone itself. The unixexchange link is the answer I'm looking for, but is not the implementation I have access to (no Squid access).

Having said that, pretty much is like having 2 computers on the same network, one with access to the internet, the other one without it. That's why I think a proxy will be the answer, but I do not know how to implement it with the available tools on tinycore.