Can QuotaGuared Tunnels Support Wildcard Hosts?

    Table of contents

    Here’s a typical question we get about Wildcard Hosts:

    Do the QuotaGuard tunnels support wildcard hosts? Our app lets users connect to their remote DBs (Snowflake/Postgres/MySQL) and while it wouldn’t be bad to setup the default ports for those, creating a new tunnel for each host wouldn’t be ideal.

    Fortunately, we offer a feature in the QGTunnel program called “dynamic tunnels”.

    The way to make this work is to find the place in your code where you want to create a tunnel. Just before that, you create a new file with the appropriate configuration, then connect through the tunnel, then after the connection is done, you delete that new file.

    func connect_to_db_through_qg(hostname, database_port) {
      local_port = random(10000..20000) #preferrably you use a port pool 
      create_file(hostname, database_port, local_port)
      connect_to_database(hostname, local_port) things with database..
      ..teardown database connection..

    ​When you create the file it needs to be in the same format as our .qgtunnel file you can download from our dashboard, which looks like this:

    accept = "localhost:12345"
    connect = "hostname:3306"
    transparent = true

    In this example, 12345 is the local port, hostname is hostname, and 3306 is the databases port.

    The file needs to be placed in the .qgtunnels directory, which should be put in the root of your application. You can add a .keep file to git in that directory if you want it to be there upon startup. Otherwise you will need to create the directory before adding the file.

    We usually recommend you name the file based on the port number, something like qgtunnel.12345, but the name doesn’t matter.

    When you are done with the connection, remove the file so we can close the socket connection to the proxy.

    Pro Tip We would also suggest you add the environment variable QGTUNNEL_DYNAMIC=true.

    Right now, we startup the dynamic mode feature automatically, but in future releases we are going to require this environment variable to enable the feature.

    Ready to Get Started?

    Get in touch or create a free trial account