## 7 Inet configuration

### 7.1 Introduction

This chapter tells you how the Erlang runtime system is configured for IP communication. It also explains how you may configure it for your own particular needs by means of a configuration file. The information here is mainly intended for users with special configuration needs or problems. There should normally be no need for specific settings for Erlang to function properly on a correctly IP configured platform.

When Erlang starts up it will read the kernel variable `inetrc` which, if defined, should specify the location and name of a user configuration file. Example:

`% erl -kernel inetrc '"./cfg_files/erl_inetrc"'`

Note that the usage of a `.inetrc` file, which was supported in earlier Erlang versions, is now obsolete.

A second way to specify the configuration file is to set the environment variable `ERL_INETRC` to the full name of the file. Example (bash):

`% export ERL_INETRC=./cfg_files/erl_inetrc`

Note that the kernel variable `inetrc` overrides this environment variable.

If no user configuration file is specified and Erlang is started in non-distributed or short name distributed mode, Erlang will use default configuration settings and a native lookup method that should work correctly under most circumstances. Erlang will not read any information from system inet configuration files (like /etc/hosts, /etc/resolv.conf, etc) in these modes.

If Erlang is started in long name distributed mode, it needs to get the domain name from somewhere and will read system inet configuration files for this information. Any hosts and resolver information found then is also recorded, but not used as long as Erlang is configured for native lookups. (The information becomes useful if the lookup method is changed to `'file'` or `'dns'`, see below).

Native lookup (system calls) is always the default resolver method. This is true for all platforms except VxWorks and OSE Delta where `'file'` or `'dns'` is used (in that order of priority).

On Windows platforms, Erlang will search the system registry rather than look for configuration files when started in long name distributed mode.

### 7.2 Configuration Data

Erlang records the following data in a local database if found in system inet configuration files (or system registry):

- Host names and addresses
- Domain name
- Nameservers
- Search domains
- Lookup method

This data may also be specified explicitly in the user configuration file. The configuration file should contain lines of configuration parameters (each terminated with a full stop). Some parameters add data to the configuration (e.g. host and nameserver), others overwrite any previous settings (e.g. domain and lookup). The user configuration file is always examined last in the configuration process, making it possible for the user to override any default values or previously made settings. Call `inet:get_rc()` to view the state of the inet configuration database.

These are the valid configuration parameters:

`{file, Format, File}.`
  `Format = atom()`
  `File = string()`
  Specify a system file that Erlang should read configuration data from. `Format` tells the parser how the file should be interpreted: `resolv` (Unix resolv.conf), `host_conf_freebsd` (FreeBSD host.conf), `host_conf_bsdos` (BSDOS host.conf), `host_conf_linux` (Linux host.conf), `nsswitch_conf` (Unix nsswitch.conf) or `hosts` (Unix hosts). `File` should specify the name of the file with full path.
`{registry, Type}.`
  `Type = atom()`
  Specify a system registry that Erlang should read configuration data from. Currently, `win32` is the only valid option.
`{host, IP, Aliases}.`
  `IP = tuple()`
  `Aliases = [string()]`
  Add host entry to the hosts table.
`{domain, Domain}.`
  `Domain = string()`
  Set domain name.
`{nameserver, IP [,Port]}.`
  `IP = tuple()`
  `Port = integer()`
  Add address (and port, if other than default) of primary nameserver.
`{alt_nameserver, IP [,Port]}.`
  `IP = tuple()`
  `Port = integer()`
  Add address (and port, if other than default) of secondary nameserver.
`{search, Domains}.`
  `Domains = [string()]`
  Add search domains.
`{lookup, Methods}.`
  `Methods = [atom()]`
  Specify lookup methods and in which order to try them. The valid methods are: `native` (use system calls), `file` (use data retrieved from system configuration files and/or the user configuration file) or `dns` (use the Erlang DNS client for nameserver queries).
`{cache_size, Size}.`
  `Size = integer()`
  Set size of resolver cache. Default is 100 DNS records.
`{cache_refresh, Time}.`
  `Time = integer()`
  Set how often (in millisec) the resolver cache is refreshed (i.e. expired DNS records are deleted). Default is 1 h.
`{timeout, Time}.`
  `Time = integer()`
  Set the time to wait until retry (in millesec) for DNS queries. Default is 2 sec.
`{retry, N}.`
  `N = integer()`
  Set the number of DNS queries to try before giving up. Default is 3.
`{inet6, Bool}.`
  `Bool = true | false`
  Tells the system to use IPv6. Default is false.
`{udp, Module}.`
  `Module = atom()`
  Tell Erlang to use other primitive UDP module than inet_udp.
`{tcp, Module}.`
  `Module = atom()`
  Tell Erlang to use other primitive TCP module than inet_tcp.
`clear_hosts.`
  Clear the hosts table.
`clear_ns.`
  Clear the list of recorded nameservers (primary and secondary).
`clear_search.`
  Clear the list of search domains.

### 7.3 User Configuration Example

Here follows a user configuration example.

Assume a user does not want Erlang to use the native lookup method, but wants Erlang to read all information necessary from start and use that for resolving names and addresses. In case lookup fails, Erlang should request the data from a nameserver (using the Erlang DNS client). Furthermore, DNS records should never be cached. The user configuration file (in this example named `erl_inetrc`, stored in directory `./cfg_files`) could then look like this (Unix):

          %% -- ERLANG INET CONFIGURATION FILE --
          %% read the hosts file
          {file, hosts, "/etc/hosts"}.
          %% add a particular host
          {host, {134,138,177,105}, ["finwe"]}.
          %% read nameserver info from here
          {file, resolv, "/etc/resolv.conf"}.
          %% disable caching
          {cache_size, 0}.
          %% specify lookup method
          {lookup, [file, dns]}.

And Erlang could, for example, be started like this:

`% erl -sname my_node -kernel inetrc '"./cfg_files/erl_inetrc"'`

erts 5.5.5
Copyright © 1991-2007 Ericsson AB