Configuração de Rede

O Ubuntu vem com alguns utilitários em ambiente gráfico para configuração de dispositivos de rede. Este documento está orientado para administradores de servidores, e focar-se-á na gestão da rede a partir da linha de comandos.

Ethernet

Most ethernet configuration is centralized in a single file, /etc/network/interfaces. If you have no ethernet devices, only the loopback interface will appear in this file, and it will look something like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback
address 127.0.0.1
netmask 255.0.0.0

If you have only one ethernet device, eth0, and it gets its configuration from a DHCP server, and it should come up automatically at boot, only two additional lines are required:

auto eth0
iface eth0 inet dhcp

The first line specifies that the eth0 device should come up automatically when you boot. The second line means that interface (“iface”) eth0 should have an IPv4 address space (replace “inet” with “inet6” for an IPv6 device) and that it should get its configuration automatically from DHCP. Assuming your network and DHCP server are properly configured, this machine's network should need no further configuration to operate properly. The DHCP server will provide the default gateway (implemented via the route command), the device's IP address (implemented via the ifconfig command), and DNS servers used on the network (implemented in the /etc/resolv.conf file.)

To configure your ethernet device with a static IP address and custom configuration, some more information will be required. Suppose you want to assign the IP address 192.168.0.2 to the device eth1, with the typical netmask of 255.255.255.0. Your default gateway's IP address is 192.168.0.1. You would enter something like this into /etc/network/interfaces:

iface eth1 inet static
	address 192.168.0.2
	netmask 255.255.255.0
	gateway 192.168.0.1

In this case, you will need to specify your DNS servers manually in /etc/resolv.conf, which should look something like this:

search mydomain.example
nameserver 192.168.0.1
nameserver 4.2.2.2

The search directive will append mydomain.example to hostname queries in an attempt to resolve names to your network. For example, if your network's domain is mydomain.example and you try to ping the host “mybox”, the DNS query will be modified to “mybox.mydomain.example” for resolution. The nameserver directives specifiy DNS servers to be used to resolve hostnames to IP addresses. If you use your own nameserver, enter it here. Otherwise, ask your Internet Service Provider for the primary and secondary DNS servers to use, and enter them into /etc/resolv.conf as shown above.

Muitas mais configurações são possíveis, incluindo interfaces de marcação telefónica PPP, redes IPv6, dispositivos VPN, etc.. Consulte man 5 interfaces para saber mais informações e opções suportadas. Lembre-se que o ficheiro /etc/network/interfaces é utilizado pelos scripts ifup/ifdown como a configuração de mais alto nível que pode ser utilizada noutras distribuições de Linux, e que os tradicionais utilitários de baixo nível, tais como ifconfig, route, e dhclient ainda estão disponíveis para configurações ad hoc.

Gerindo Entradas de DNS

This section explains how to configure which nameserver to use when resolving IP addresses to hostnames and vice versa. It does not explain how to configure the system as a name server.

Para gerir entradas de DNS, pode adicionar, editar ou remover nomes de DNS do ficheiro /etc/resolv.conf. Um ficheiro de exemplo sample file é dado abaixo:

search com
nameserver 204.11.126.131
nameserver 64.125.134.133
nameserver 64.125.134.132
nameserver 208.185.179.218

The search key specifies the string which will be appended to an incomplete hostname. Here, we have configured it to com. So, when we run: ping ubuntu it would be interpreted as ping ubuntu.com.

The nameserver key specifies the nameserver IP address. It will be used to resolve a given IP address or hostname. This file can have multiple nameserver entries. The nameservers will be used by the network query in the same order.

[Atenção]

If the DNS server names are retrieved dynamically from DHCP or PPPoE (retrieved from your ISP), do not add nameserver entries in this file. It will be overwritten.

[Atenção]

The changes you make in /etc/resolv.conf will be erased when you reboot your machine. If you want to make this change permanent, you should install resolvconf package from the Universe repository and update the DNS information in the /etc/resolvconf/resolv.conf.d/base file provided by that package.

Gerindo Computadores

Para gerir servidores, pode adicionar, editar, ou remover servidores do ficheiro /etc/hosts. Este ficheiro contém endereços IP e os correspondentes nomes associados. Quando o seu sistema tenta traduzir o nome de uma máquina para um endereço IP ou determinar o nome de uma máquina para um endereço IP, vai verificar o ficheiro /etc/hosts antes de recorrer aos servidores de nomes. Se o endereço IP está listado no ficheiro /etc/hosts, os servidores de nomes não são utilizados. Este comportamento pode ser alterado por edição do ficheiro /etc/nsswitch.conf.

Se a sua rede contém computadores cujos endereços IP não estão listados em DNS, é recomendado que os adicione ao ficheiro /etc/hosts.