go-gost / gost

GO Simple Tunnel - a simple tunnel written in golang
https://gost.run
MIT License
3.96k stars 488 forks source link

loadbalance to multi-port ( Port Hopping ) #326

Closed AkramiPro closed 1 month ago

AkramiPro commented 9 months ago

hi, thank you for awesome program. I know that you support load balancing. but i want to load balance on same ip but on different ports. like 192.168.1.10:20000-50000 because in my country they have some limit on ports so i need to connect to each port randomly I use hysteria in my remote server and it can accept request on multi-port. I just need to config gost to transfer traffic on random port in range that i gave him. can you add this to gost ?

https://v2.hysteria.network/zh/docs/advanced/Port-Hopping/

image

ginuerzh commented 9 months ago

The hysteria port-hopping is a protocol specific feature, and is different from the load balancing on gost hop.

AkramiPro commented 9 months ago

thank you for your time and response yes i know that but i just give some info for you to maybe it help you to understand why i need load balance on port instead of ips i make example for you :

currently config:

  - name: service-1
    addr: :443
    handler:
      type: tcp
    listener:
      type: tcp
    forwarder:
      selector:
        strategy: round
        maxFails: 1
        failTimeout: 30s
      nodes:
        - name: target-0
          addr: 127.0.0.1:1001
        - name: target-1
          addr: 127.0.0.1:1002
        - name: target-2
          addr: 127.0.0.1:1003
        - name: target-3
          addr: 127.0.0.1:1004
        - name: target-4
          addr: 127.0.0.1:1005
        - name: target-5
          addr: 127.0.0.1:1006
        - name: target-6
          addr: 127.0.0.1:1007
        - name: target-7
          addr: 127.0.0.1:1008
        - name: target-8
          addr: 127.0.0.1:1009
        - name: target-9
          addr: 127.0.0.1:1010

expected config:

  - name: service-1
    addr: :443
    handler:
      type: tcp
    listener:
      type: tcp
    forwarder:
      selector:
        strategy: round
        maxFails: 1
        failTimeout: 30s
      nodes:
        - name: target-0
          addr: 127.0.0.1:1001-1010
ginuerzh commented 9 months ago

The port range scheme 127.0.0.1:1001-1010 can be added later, but it may not work for hysteria. You can manually specify several ports to test.

AkramiPro commented 9 months ago

i test the manually specify several ports and hysteria work with that without any problem because in remote server i use iptables rules (base on hysteria docs) to forward all request on port-range on single local port that hysteria run and its work fine

this is my network:

Client1 ---> Server A ( gost 192.168.1.1:443 )  ----> Server B ( 192.168.1.2:1001 ) ---> Server B ( hsyteria 192.168.1.2:443)
Client2 ---> Server A ( gost 192.168.1.1:443 )  ----> Server B ( 192.168.1.2:1002 ) ---> Server B ( hsyteria 192.168.1.2:443)
Client3 ---> Server A ( gost 192.168.1.1:443 )  ----> Server B ( 192.168.1.2:1003 ) ---> Server B ( hsyteria 192.168.1.2:443)
...
...
...

Server A (gost) 192.168.1.1:443 :

services:
  - name: service-0
    addr: :443
    handler:
      type: rudp
    listener:
      type: rudp
      metadata:
        ttl: 5s
        backlog: 2048
        readQueueSize: 2048
        readBufferSize: 2048
    forwarder:
      selector:
        strategy: round
        maxFails: 1
        failTimeout: 30s
      nodes:
        - name: target-0
          addr: 192.168.1.2:1001
        - name: target-1
          addr: 192.168.1.2:1002
        - name: target-2
          addr: 192.168.1.2:1003
        - name: target-3
          addr: 192.168.1.2:1004
        - name: target-4
          addr: 192.168.1.2:1005
        - name: target-5
          addr: 192.168.1.2:1006
        - name: target-6
          addr: 192.168.1.2:1007
        - name: target-7
          addr: 192.168.1.2:1008
        - name: target-8
          addr: 192.168.1.2:1009
        - name: target-9
          addr: 192.168.1.2:1010

Server B (hysteria) 192.168.1.2:1001-1010 -> 443

iptables -t nat -A PREROUTING -i eth0 -p udp --dport 1001:1010 -j DNAT --to-destination :443

it is bypass port limit that exists in some country like iran and china can i know when you have time to add this port-range schema ? thank you

ginuerzh commented 9 months ago

Wait for the next nightly version.

AkramiPro commented 9 months ago

Thank you