20042016 Ericsson AB. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Inet Configuration Peter Andersson 2004-03-02 PA1 inet_cfg.xml
Introduction

This section describes how the Erlang runtime system is configured for IP communication. It also explains how you can configure it for your needs by a configuration file. The information is primarily intended for users with special configuration needs or problems. There is normally no need for specific settings for Erlang to function properly on a correctly IP-configured platform.

When Erlang starts up it reads the Kernel variable , which, if defined, is to specify the location and name of a user configuration file. Example:

Notice that the use of an file, which was supported in earlier Erlang/OTP versions, is now obsolete.

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

Notice 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 uses default configuration settings and a native lookup method that works correctly under most circumstances. Erlang reads no information from system inet configuration files (such as /etc/host.conf and /etc/nsswitch.conf) 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(3).

If Erlang is started in long name distributed mode, it needs to get the domain name from somewhere and reads system inet configuration files for this information. Any hosts and resolver information found 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 priority order).

On Windows platforms, Erlang searches the system registry rather than looks 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):

Hostnames and host addresses Domain name Nameservers Search domains Lookup method

This data can also be specified explicitly in the user configuration file. This file is to contain lines of configuration parameters (each terminated with a full stop). Some parameters add data to the configuration (such as host and nameserver), others overwrite any previous settings (such as 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.

The valid configuration parameters are as follows:

Specify a system file that Erlang is to read configuration data from. tells the parser how the file is to be interpreted:

(Unix resolv.conf) (FreeBSD host.conf) (BSDOS host.conf) (Linux host.conf) (Unix nsswitch.conf) (Unix hosts)

is to specify the filename with full path.

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

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

If the file is specified as an empty string "", no file is read or monitored in the future. This emulates the old behavior 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 environment variable is set, which defines the directory for this file to some maybe other than .

Specify a system file that Erlang is to 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 lookup option file is used.

If the file is specified as an empty string "", no file is read or monitored in the future. This emulates the old behavior 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 environment variable is set, which defines the directory for this file to some maybe other than .

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

Add host entry to the hosts table.

Set domain name.

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

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

Add search domains for inet_res(3).

Specify lookup methods and in which order to try them. The valid methods are as follows:

(use system calls) (use host data retrieved from system configuration files and/or the user configuration file) (use the Erlang DNS client inet_res(3) for nameserver queries)

The lookup method tries to parse the hostname as an 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 the resolver cache size. Defaults to 100 DNS records.

Set how often (in milliseconds) the resolver cache for inet_res(3) is refreshed (that is, expired DNS records are deleted). Defaults to 1 hour.

Set the time to wait until retry (in milliseconds) for DNS queries made by inet_res(3). Defaults to 2 seconds.

Set the number of DNS queries inet_res(3) will try before giving up. Defaults to 3.

Tells the DNS client inet_res(3) to look up IPv6 addresses. Defaults to false.

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

Sets the EDNS version that inet_res(3) will use. The only allowed version is zero. Defaults to false, which means not to use EDNS.

Sets the allowed UDP payload size inet_res(3) 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; this is not entirely correct, as the advertised UDP payload size of the individual nameserver is what is to be used, but this simple strategy will do until a more intelligent (probing, caching) algorithm needs to be implemented. Default to 1280, which stems from the standard Ethernet MTU size.

Tell Erlang to use another primitive UDP module than inet_udp.

Tell Erlang to use another 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

Assume that 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. If lookup fails, Erlang is to request the data from a nameserver (using the Erlang DNS client, set to use EDNS allowing larger responses). The resolver configuration is updated when its configuration file changes. Also, DNS records are never to be cached. The user configuration file (in this example named , stored in directory ) can then look as follows (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 can, for example, be started as follows: