Handbook:HPPA/Networking/Advanced/it

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Handbook:HPPA/Networking/Advanced and the translation is 100% complete.
Manuale HPPA
Installazione
Riguardo l'installazione
Il mezzo d'installazione
Configurare la rete
Preparare i dischi
Installare lo stage3
Installare il sistema base
Configurare il kernel
Configurare il sistema
Strumenti di sistema
Configurare l'avviatore
Ultimare l'installazione
Lavorare con Gentoo
Introduzione a Portage
Opzioni USE
Funzionalità di Portage
Sistema script di init
Variabili d'ambiente
Lavorare con Portage
File e cartelle
Variabili
Mixare i rami del software
Strumenti aggiuntivi
Repositorio pacchetti personalizzato
Funzionalità avanzate
Configurare la rete
Come iniziare
Configurazione avanzata
Networking modulare
Wireless
Aggiungere funzionalità
Gestione dinamica

La variabile config_eth0 è il cuore di una configurazione dell'interfaccia. È una lista di istruzioni di alto livello per configurare l'interfaccia (eth0 in questo caso). Ogni comando nella lista di istruzioni viene eseguito in sequenza. L'interfaccia è considerata OK se funziona almeno un comando.

Ecco un elenco di istruzioni integrate:

Valore Descrizione
null Non fare nulla.
noop Se l'interfaccia è attiva e c'è un indirizzo, interrompere la configurazione con successo.
Un indirizzo IPv4 o IPv6 Aggiunge l'indirizzo all'interfaccia.
dhcp, adsl, o apipa (o un valore personalizzato da un modulo di terze parti) Esegue il modulo che fornisce il comando. Per esempio dhcp eseguirà un modulo che fornisce DHCP servito da dhcpcd, dhclient, o pump.

Se un comando fallisce, specificare un valore di ripiego. Il ripiego (fallback) deve corrispondere in modo esatto alla struttura della configurazione.

È possibile concatenare questi valori insieme. Ecco alcuni esempi presi da situazioni reali:

FILE /etc/conf.d/netEsempi di configurazione
# Aggiunta di tre indirizzi IPv4
config_eth0="192.168.0.2/24
192.168.0.3/24
192.168.0.4/24"
  
# Aggiunta di un indirizzo IPv4 e due indirizzi IPv6
config_eth0="192.168.0.2/24
4321:0:1:2:3:4:567:89ab
4321:0:1:2:3:4:567:89ac"
  
# Mantiene nel nostro kernel l'indirizzo assegnato, a meno che
# l'interfaccia non funzioni allora ne assegna un altro via DHCP
# Se DHCP fallisce, aggiunge un indirizzo statico tramite APIPA
config_eth0="noop
dhcp"
fallback_eth0="null
apipa"
Nota
Quando si usa il modulo ifconfig e si aggiunge più di un indirizzo, vengono creati alias di interfaccia per ciascun indirizzo aggiunto. Quindi con i due esempi precedenti gli utenti otterranno le interfacce eth0, eth0:1 ed eth0:2. Non è possibile fare nulla di speciale con queste interfacce in quanto il kernel e gli altri programmi trattano eth0:1 ed eth0:2 semplicemente come eth0.
Importante
L'ordine di ripiego (fallback) è importante! Se non è stata specificata l'opzione null, apipa verrà eseguito solo se noop fallisce.
Nota
APIPA e DHCP sono trattati più avanti.

Dipendenze di rete

Gli script di init dentro /etc/init.d/ possono dipendere da un'interfaccia di rete specifica o semplicemente da "net" (rete). Tutte le interfacce di rete nel sistema init di Gentoo forniscono ciò che viene chiamato "net".

Se, in /etc/rc.conf, la variabile rc_depend_strict è impostata su YES, allora tutte le interfacce di rete che forniscono "net" devono essere attive prima di supporre che una dipendenza da "net" sia soddisfatta. In altre parole, se un sistema ha net.eth0 e net.eth1 e uno script di init dipende da "net", allora entrambi devono essere abilitati.

In caso contrario, se è impostato rc_depend_strict = "NO", la dipendenza "net" viene contrassegnata come risolta nel momento in cui viene attivata almeno un'interfaccia di rete.

Ma riguardo a net.br0 che dipende da net.eth0 e net.eh1? net.eh1 può essere un dispositivo wireless o PPP che necessita di una configurazione prima di poter essere aggiunto al ponte di collegamento dati (bridge). Ciò non può esser fatto in /etc/init.d/net.br0 poiché si tratta di un link simbolico a net.lo.

La risposta è definire l'impostazione rc_need_ in /etc/conf.d/net:

FILE /etc/conf.d/netAggiungere una dipendenza net.br0
rc_need_br0="net.eth0 net.eth1"

Solo questo, tuttavia, non è sufficiente. Gli script di init del lavoro di rete su Gentoo utilizzano una dipendenza virtuale chiamata "net" per informare il sistema quando la rete è disponibile. Chiaramente, nel caso precedente, la rete dovrebbe essere contrassegnata come disponibile solo quando net.br0 è attivo, non quando lo sono gli altri. Così dobbiamo specificarlo anche in /etc/conf.d/net:

FILE /etc/conf.d/netAggiornare le dipendenze virtuali e le disposizioni per la rete
rc_net_eth0_provide="!net"
rc_net_eth1_provide="!net"

Per una discussione più dettagliata sulle dipendenze, consultare la sezione sulla scrittura degli script di init sul Manuale di Gentoo. Ulteriori informazioni su /etc/rc.conf sono disponibili tramite commenti interni allo stesso file.

Nomi e valori delle variabili

Variable names are dynamic. They normally follow the structure of variable_${interface|mac|essid|apmac}. For example, the variable dhcpcd_eth0 holds the value for dhcpcd options for eth0 and dhcpcd_essid holds the value for dhcpcd options when any interface connects to the ESSID "essid".

However, there is no hard and fast rule that states interface names must be ethx. In fact, many wireless interfaces have names like wlanx, rax as well as ethx. Also, some user defined interfaces such as bridges can be given any name. To make life more interesting, wireless Access Points can have names with non alpha-numeric characters in them - this is important because users can configure networking parameters per ESSID.

The downside of all this is that Gentoo uses bash variables for networking - and bash cannot use anything outside of English alpha-numerics. To get around this limitation we change every character that is not an English alpha-numeric into an _ (underscore) character.

Another downside of bash is the content of variables - some characters need to be escaped. This can be achieved by placing the \ (backslash) character in front of the character that needs to be escaped. The following list of characters needs to be escaped in this way: ", ' and \.

In this example we use wireless ESSID as they can contain the widest scope of characters. We shall use the ESSID My "\ NET:

FILE /etc/conf.d/netVariable names
# This does work, but the domain is invalid
dns_domain_My____NET="My \"\\ NET"

The above sets the DNS domain to My "\ NET when a wireless card connects to an AP whose ESSID is My "\ NET.

Network interface naming

How it works

Network interface names are not chosen arbitrarily: the Linux kernel and the device manager (most systems have udev as their device manager although others are available as well) choose the interface name through a fixed set of rules.

When an interface card is detected on a system, the Linux kernel gathers the necessary data about this card. This includes:

  • The onboard (on the interface itself) registered name of the network card, which is later seen through the ID_NET_NAME_ONBOARD value.
  • The slot in which the network card is plugged in, which is later seen through the ID_NET_NAME_SLOT value.
  • The path through which the network card device can be accessed, which is later seen through the ID_NET_NAME_PATH value.
  • The (vendor-provided) MAC address of the card, which is later seen through the ID_NET_NAME_MAC value.

Based on this information, the device manager decides how to name the interface on the system. By default, it uses the first hit of the first three variables above (ID_NET_NAME_ONBOARD, _SLOT or _PATH). For instance, if ID_NET_NAME_ONBOARD is found and set to eno1, then the interface will be called eno1.

Given an active interface name, the values of the provided variables can be shown using udevadm:

root #udevadm test-builtin net_id /sys/class/net/enp3s0 2>/dev/null
ID_NET_NAME_MAC=enxc80aa9429d76
ID_OUI_FROM_DATABASE=Quanta Computer Inc.
ID_NET_NAME_PATH=enp3s0

As the first (and actually only) hit of the top three variables is ID_NET_NAME_PATH, its value is used as the interface name. If none of the variables contain values, then the system reverts back to the kernel-provided naming (eth0, eth1, etc.)

Using the old-style kernel naming

Before this change, network interface cards were named by the Linux kernel itself, depending on the order that drivers are loaded (amongst other, possibly more obscure reasons). This behavior can still be enabled by setting the net.ifnames=0 boot parameter in the boot loader.

Using custom names

The entire idea behind the change in naming is not to confuse people, but to make changing the names easier. Suppose a system has two interfaces that are otherwise called eth0 and eth1. One is meant to access the network through a wire, the other one is for wireless access. With the support for interface naming, users can have these called lan0 (wired) and wifi0 (wireless - it is best to avoid using the previously well-known names like eth* and wlan* as those can still collide with the suggested names).

Find out what the parameters are for the cards and then use this information to set up a custom own naming rule:

root #udevadm test-builtin net_id /sys/class/net/eth0 2>/dev/null
ID_NET_NAME_MAC=enxc80aa9429d76
ID_OUI_FROM_DATABASE=Quanta Computer Inc.
root #vim /etc/udev/rules.d/70-net-name-use-custom.rules
# First one uses MAC information, and 70- number to be before other net rules
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="c8:0a:a9:42:9d:76", NAME="lan0"
root #vim /etc/udev/rules.d/76-net-name-use-custom.rules
# Second one uses ID_NET_NAME_PATH information, and 76- number to be between
# 75-net-*.rules and 80-net-*.rules
SUBSYSTEM=="net", ACTION=="add", ENV{ID_NET_NAME_PATH}=="enp3s0", NAME="wifi0"

Because the rules are triggered before the default one (rules are triggered in alphanumerical order, so 70 comes before 80) the names provided in the rule file will be used instead of the default ones. The number granted to the file should be between 76 and 79 (the environment variables are defined by a rule start starts with 75 and the fallback naming is done in a rule numbered 80).