20042009 Ericsson AB. All Rights Reserved. The contents of this file are subject to the Erlang Public License, Version 1.1, (the "License"); you may not use this file except in compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Inet configuration Peter Andersson 2004-03-02 PA1 inet_cfg.xml
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 which, if defined, should specify the location and name of a user configuration file. Example:

Note that the usage of a 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 to the full name of the file. Example (bash):

Note that the kernel variable 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/host.conf, /etc/nsswitch.conf, etc) in these modes, except for /etc/resolv.conf and /etc/hosts that is read and monitored for changes on Unix platforms for the internal DNS client inet_res.

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 or , see below).

Native lookup (system calls) is always the default resolver method. This is true for all platforms except VxWorks and OSE Delta where or 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.

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 to view the state of the inet configuration database.

These are the valid configuration parameters:

Specify a system file that Erlang should read configuration data from. tells the parser how the file should be interpreted: (Unix resolv.conf), (FreeBSD host.conf), (BSDOS host.conf), (Linux host.conf), (Unix nsswitch.conf) or (Unix hosts). should specify the name of the file with full path.

Specify a system file that Erlang should read resolver configuration from for the internal DNS client inet_res, and monitor for changes, even if it does not exist. The path must be absolute.

This may override the configuration parameters and depending on the contents of the specified file. They may also change any time in the future reflecting the file contents.

If the file is specified as an empty string "", no file is read nor monitored in the future. This emulates the old behaviour of not configuring the DNS client when the node is started in short name distributed mode.

If this parameter is not specified it defaults to unless the environment variable is set which defines the directory for this file to some maybe other than .

Specify a system file that Erlang should read resolver configuration from for the internal hosts file resolver and monitor for changes, even if it does not exist. The path must be absolute.

These host entries are searched after all added with {file, hosts, File} above or {host, IP, Aliases} below when the lookup option file is used.

If the file is specified as an empty string "", no file is read nor monitored in the future. This emulates the old behaviour of not configuring the DNS client when the node is started in short name distributed mode.

If this parameter is not specified it defaults to unless the environment variable is set which defines the directory for this file to some maybe other than .

Specify a system registry that Erlang should read configuration data from. Currently, is the only valid option.

Add host entry to the hosts table.

Set domain name.

Add address (and port, if other than default) of primary nameserver to use for inet_res.

Add address (and port, if other than default) of secondary nameserver for inet_res.

Add search domains for inet_res.

Specify lookup methods and in which order to try them. The valid methods are: (use system calls), (use host data retrieved from system configuration files and/or the user configuration file) or (use the Erlang DNS client inet_res for nameserver queries).

The lookup method tries to parse the hostname as a IPv4 or IPv6 string and return the resulting IP address. It is automatically tried first when is not in the list. To skip it in this case the pseudo lookup method can be inserted anywhere in the list.

Set size of resolver cache. Default is 100 DNS records.

Set how often (in millisec) the resolver cache for inet_res. is refreshed (i.e. expired DNS records are deleted). Default is 1 h.

Set the time to wait until retry (in millisec) for DNS queries made by inet_res. Default is 2 sec.

Set the number of DNS queries inet_res will try before giving up. Default is 3.

Tells the DNS client inet_res to look up IPv6 addresses. Default is false.

Tells the DNS client inet_res to use TCP (Virtual Circuit) instead of UDP. Default is false.

Sets the EDNS version that inet_res will use. The only allowed is zero. Default is false which means to not use EDNS.

Sets the allowed UDP payload size inet_res will advertise in EDNS queries. Also sets the limit when the DNS query will be deemed too large for UDP forcing a TCP query instead, which is not entirely correct since the advertised UDP payload size of the individual nameserver is what should be used, but this simple strategy will do until a more intelligent (probing, caching) algorithm need be implemented. The default is 1280 which stems from the standard Ethernet MTU size.

Tell Erlang to use other primitive UDP module than inet_udp.

Tell Erlang to use other primitive TCP module than inet_tcp.

Clear the hosts table.

Clear the list of recorded nameservers (primary and secondary).

Clear the list of search domains.

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, set to use EDNS allowing larger responses). The resolver configuration will be updated when its configuration file changes, furthermore, DNS records should never be cached. The user configuration file (in this example named , stored in directory ) 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"]}.
      %% do not monitor the hosts file
      {hosts_file, ""}.
      %% read and monitor nameserver config from here
      {resolv_conf, "/usr/local/etc/resolv.conf"}.
      %% enable EDNS
      {edns,0}.
      %% disable caching
      {cache_size, 0}.
      %% specify lookup method
      {lookup, [file, dns]}.

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