Objectivo
Em certos casos é vantajoso atribuir mais do que um endereço a um sistema. Se o sistema tem várias interfaces de rede, basta atribuir endereços diferentes a cada uma. No caso de haver apenas uma ligação de rede, é possível criar interfaces virtuais. Assim, a partir de uma interface eth0 são criadas uma ou mais interfaces virtuais, eth0:0, eth0:1, etc.
Configuração
A configuração de uma interface virtual é efectuada no ficheiro /etc/network/interfaces:
# 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
# The primary network interface
#allow-hotplug eth0
#iface eth0 inet dhcp
# Static IP address
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
# Virtual interface
# Static IP address
auto eth0:0
iface eth0:0 inet static
address 192.168.1.101
netmask 255.255.255.0
Na configuração da interface eth0:0 só são definidos os parâmetros address e netmask, uma vez que os restantes parâmetros são iguais aos da interface eth0.
Graças à linha “auto eth0:0”, no ficheiro /etc/network/interfaces, a interface virtual será automaticamente activada a cada arranque do sistema. Por agora, activar manualmente a ligação:
server:~# ifup eth0:0
Associar um nome de sistema ou hostname ao novo endereço, no ficheiro /etc/hosts:
127.0.0.1 localhost
192.168.1.100 server.home.lan server
192.168.1.101 virtual.home.lan virtual
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Verificação
O comando ifconfig deverá mostrar a interface virtual eth0:0 activada, com o endereço IP e demais parâmetros atribuídos:
server:~# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:3c:96:f8
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe3c:96f8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7793 errors:0 dropped:0 overruns:0 frame:0
TX packets:4236 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7869739 (7.5 MiB) TX bytes:349972 (341.7 KiB)
Interrupt:19 Base address:0x2000
eth0:0 Link encap:Ethernet HWaddr 00:0c:29:3c:96:f8
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:34 errors:0 dropped:0 overruns:0 frame:0
TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB)
O comando ping permite verificar se um servidor está acessível e a responder a comunicações em rede:
server:~# ping -c3 virtual
PING virtual.home.lan (192.168.1.101) 56(84) bytes of data.
64 bytes from virtual.home.lan (192.168.1.101): icmp_seq=1 ttl=64 time=0.031 ms
64 bytes from virtual.home.lan (192.168.1.101): icmp_seq=2 ttl=64 time=0.046 ms
64 bytes from virtual.home.lan (192.168.1.101): icmp_seq=3 ttl=64 time=0.047 ms
--- virtual.home.lan ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.031/0.041/0.047/0.009 ms
Referências
- Rede local, Endereço IP estático
- Rede local, Nome do sistema
- Referência Debian, 10.6.6 Configurando múltiplas interfaces Ethernet para um gateway (http://www.debian.org/doc/manuals/reference/ch-gateway.pt-br.html#s-high-virtual)




















