Hydra networking

Hydra supports a number of networking options. This section digs explores the available options and when you might want to use them. In the following examples we'll use the config.json file from a Hydra-router instance - but the config could have been from any other hydra-enabled application.

{
  "externalRoutes": {},
  "routerToken": "",
  "disableRouterEndpoint": false,
  "debugLogging": true,
  "queuerDB": 3,
  "requestTimeout": 30,
  "hydra": {
    "serviceName": "hydra-router",
    "serviceDescription": "Service Router",
    "serviceIP": "",
    "servicePort": "80",
    "serviceType": "router",
    "plugins": {
      "logger": {
        "logRequests": false,
        "toConsole": false,
        "noFile": true,
        "redact": [
          "password"
        ],
        "elasticsearch": {
          "host": "",
          "port": 9200,
          "index": "hydra",
          "rotate": "daily"
        }
      }
    },
    "redis": {
      "url": "redis://prod.p45rev.ng.0001.usw2.cache.amazonaws.com:6379/15"
    }
  }
}

In the config.json file above we're primarily interested in the hydra.serviceIP and the hydra.servicePort fields.

The servicePort allows you to specify the IP port you'd like hydra to listen on. In the example above hydraRouter is listening on port 80. If you don't specify a servicePort (if servicePort is empty for example) then hydra will select a random non-privileged port above 1024. The servicePort field also support specifying a range of ports.

In this example, a random service port will be selected from 3000 to 4000.

"servicePort": "3000-4000"

As a bonus, if hydra detects that a random port is already in use it will try another port in the specified range.

Turning our attention to the serviceIP field, if the field is empty, hydra will choose the first IPv4 address it finds. If the field contains an IP address such as 192.168.1.18 then hydra will use that address. If the field contains text but isn't a valid IP address then hydra assumes you've specified a DNS name.

When Hydra start it looks at all available network interfaces. We can see this in action when starting a Hydra-router.

 _   _           _             ____             _
| | | |_   _  __| |_ __ __ _  |  _ \ ___  _   _| |_ ___ _ __
| |_| | | | |/ _` | '__/ _` | | |_) / _ \| | | | __/ _ \ '__|
|  _  | |_| | (_| | | | (_| | |  _ < (_) | |_| | ||  __/ |
|_| |_|\__, |\__,_|_|  \__,_| |_| \_\___/ \__,_|\__\___|_|
       |___/

Starting service hydra-router:1.4.18 on 10.255.0.13:80
Detected IPv4 IPs:
* lo: 127.0.0.1 255.0.0.0
* eth0: 10.255.0.13 255.255.0.0
* eth0: 10.255.0.12 255.255.255.255
* eth1: 172.18.0.3 255.255.0.0
* eth2: 10.0.9.3 255.255.255.0
* eth2: 10.0.9.2 255.255.255.255

You you'd like Hydra to bind to a specific address you can tell hydra which interface and network mask it should use to identify the IP it should use via the serviceInterface key.

You can do this in the config.json file using a value of interfaceName/interfaceMask:

"serviceInterface": "eth2/255.255.255.0",

results matching ""

    No results matching ""