Gestione configurazioni di rete notebook

From RVM Wiki
Jump to navigation Jump to search

E' possibile far configurare le schede di rete di un notebook automaticamente tramite il pacchetto guessnet

Prima di eseguire le operazioni seguenti, staccare il cavo lan ed estrarre la scheda pcmcia dal socket

Installazione di resolvconf

Il pacchetto resolvconf permette di gestire dinamicamente la configurazione dns della macchina.

Installando resolconf, si può dichiarare nel file /etc/network/interfaces/ le direttive:

dns-nameservers
dns-search
dns-domain
dns-sortlist

che corrispondo ai relativi parametri spiegati in man resolvconf (senza dns-)

Installiamo il pacchetto:

sudo apt-get install resolvconf

A scanso di equivoci, resettiamo la configurazione dns:

echo "" > /etc/resolv.conf

Riavviamo il networkig:

sudo /etc/init.d/networking stop; sudo /etc/init.d/networking start

Installazione ifplugd

Il pacchetto ifplugd permette di "sentire" quando una scheda lan o wifi viene collegata ad una rete, e di conseguena può far eseguire delle azioni

sudo apt-get install ifplugd

Configurazione ifplugd

Supponendo di avere una scheda lan eth0 ed una wifi pcmcia ath0, le si assegna entrambi in gestione ad ifplugd.

etho è una scheda onboard, quindi gestita come interfaccia "normale", mentre ath0 è una scheda pcmcia, quindi gestita via demone hotplug:

sudoedit /etc/default/ifplugd
...
INTERFACES="eth0"
HOTPLUG_INTERFACES="ath0"
...

Riavviare ifplugd

/etc/init.d/ifplugd stop; /etc/init.d/ifplugd start


Configurazione della scheda lan

Supponiamo di partire con una configurazione singola della scheda lan in dhcp.

Il vantaggio di avere ifplugd è che ogni volta che si inserirà il cavo lan automaticamente si richiamerà dhclient.

Definiamo il profilo per la scheda lan:

sudoedit /etc/network/interface

#loopback interface, always present

auto lo
iface lo inet loopback

#definiamo l'interfaccia lan come dhcp
iface eth0 inet dhcp

Riavviamo il networking

sudo /etc/init.d/networking stop; sudo /etc/init.d/networking start


Verifica di ifplugd per la scheda Lan

Monitoriamo il syslog:

 sudo tail -f /var/log/syslog | cut --delim=" " -f 6-

Inseriamo il cavo di rete:

ifplugd(eth0)[9734]: Link beat detected.
kernel: e100: eth0: e100_watchdog: link up, 100Mbps, full-duplex
ifplugd(eth0)[9734]: Executing '/etc/ifplugd/ifplugd.action eth0 up'.
dhclient: Internet Systems Consortium DHCP Client V3.0.1
ifplugd(eth0)[9734]: client: Internet Systems Consortium DHCP Client V3.0.1
dhclient: Copyright 2004 Internet Systems Consortium.
ifplugd(eth0)[9734]: client: Copyright 2004 Internet Systems Consortium.
dhclient: All rights reserved.
ifplugd(eth0)[9734]: client: All rights reserved.
dhclient: For info, please visit http://www.isc.org/products/DHCP
ifplugd(eth0)[9734]: client: For info, please visit http://www.isc.org/products/DHCP
dhclient:
dhclient: Listening on LPF/eth0/00:08:02:68:3a:7c
ifplugd(eth0)[9734]: client: Listening on LPF/eth0/00:08:02:68:3a:7c
dhclient: Sending on   LPF/eth0/00:08:02:68:3a:7c
ifplugd(eth0)[9734]: client: Sending on   LPF/eth0/00:08:02:68:3a:7c
dhclient: Sending on   Socket/fallback
ifplugd(eth0)[9734]: client: Sending on   Socket/fallback
dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7
ifplugd(eth0)[9734]: client: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7
dhclient: DHCPOFFER from 192.168.6.100
dhclient: DHCPREQUEST on eth0 to 255.255.255.255 port 67
ifplugd(eth0)[9734]: client: DHCPOFFER from 192.168.6.100
ifplugd(eth0)[9734]: client: DHCPREQUEST on eth0 to 255.255.255.255 port 67
dhclient: DHCPACK from 192.168.6.100
ifplugd(eth0)[9734]: client: DHCPACK from 192.168.6.100
dhclient: bound to 192.168.6.88 -- renewal in 37766 seconds.
ifplugd(eth0)[9734]: client: bound to 192.168.6.88 -- renewal in 37766 seconds.

Stacchiamo il cavo di rete, dopo alcuni secondi verrà rilasciato l'ip:

ifplugd(eth0)[9734]: Link beat lost.
kernel: e100: eth0: e100_watchdog: link down
ifplugd(eth0)[9734]: Executing '/etc/ifplugd/ifplugd.action eth0 down'.
dhclient: Internet Systems Consortium DHCP Client V3.0.1
ifplugd(eth0)[9734]: client: Internet Systems Consortium DHCP Client V3.0.1
dhclient: Copyright 2004 Internet Systems Consortium.
ifplugd(eth0)[9734]: client: Copyright 2004 Internet Systems Consortium.
dhclient: All rights reserved.
ifplugd(eth0)[9734]: client: All rights reserved.
dhclient: For info, please visit http://www.isc.org/products/DHCP
ifplugd(eth0)[9734]: client: For info, please visit http://www.isc.org/products/DHCP
dhclient:
dhclient: Listening on LPF/eth0/00:08:02:68:3a:7c
ifplugd(eth0)[9734]: client: Listening on LPF/eth0/00:08:02:68:3a:7c
dhclient: Sending on   LPF/eth0/00:08:02:68:3a:7c
ifplugd(eth0)[9734]: client: Sending on   LPF/eth0/00:08:02:68:3a:7c
dhclient: Sending on   Socket/fallback
ifplugd(eth0)[9734]: client: Sending on   Socket/fallback
dhclient: DHCPRELEASE on eth0 to 192.168.6.100 port 67
ifplugd(eth0)[9734]: client: DHCPRELEASE on eth0 to 192.168.6.100 port 67


Installazione di guessnet

Installiamo ora guessnet

sudo apt-get install guessnet

Configurazione dei profili di rete

Guessnet è utilizzabile direttamente da ifupdown, cioè con delle semplici dichiarazioni in /etc/network/interfaces

In pratica si associa l'interfaccia fisica a delle interfacce virtuali a cui si assegnano delle configurazioni particolari.

Guessnet esegue dei test specifici ad esempio per vedere se riesce a pingare un host ed al primo successo sceglie la configurazione virtuale e la applica all'interfaccia fisica.

Se tutti i test falliscono è possibile scegliere un profilo di default, che noi decideremo essere dhcp.

Vediamo una configurazione di esempio.

Il profilo "lan-pub" viene selezionato se ci si trova in una lan con un host (tipicamente il gateway) con ip 192.168.6.254 e mac 00:50:04:74:15:AE.

Il profilo "lan-home" viene selezionato se ci si trova in una lan con un host (tipicamente il gateway) con ip 192.168.250.254 e mac 00:0F:B5:7F:18:A8.

Se nessuna di queste situazioni si verifica, verrà impostato il profilo lan-dhcp.

mapping eth0
        script guessnet-ifupdown
        map lan-pub lan-home
        map default: lan-dhcp
        map timeout: 5
        map verbose: true
        map debug:true

iface lan-pub inet static
        address 192.168.6.200
        netmask 255.255.255.0
        gateway 192.168.6.254
        dns-nameservers 194.20.8.1
        dns-search pubblistil.priv
        test peer address 192.168.6.254 mac 00:50:04:74:15:AE

iface lan-home inet static
        address 192.168.250.200
        netmask 255.255.255.0
        gateway 192.168.250.254
        dns-nameservers 194.20.8.1
        dns-search diesis.priv
        test peer address 192.168.250.254 mac 00:0F:B5:7F:18:A8

iface lan-dhcp inet dhcp

Disinseriamo il cavo e restartiamo il networking ed ifplugd:

sudo /etc/init.d/networking stop; sudo /etc/init.d/networking start
sudo /etc/init.d/ifplugd stop; sudo /etc/init.d/ifplugd start

Monitoriamo il log ed inseriamo il cavo:

sudo tail -f /var/log/syslog | cut --delim=" " -f 6-

ifplugd(eth0)[8396]: Link beat detected.
kernel: e100: eth0: e100_watchdog: link up, 100Mbps, full-duplex
ifplugd(eth0)[8396]: Executing '/etc/ifplugd/ifplugd.action eth0 up'.
ifplugd(eth0)[8396]: client: guessnet: 2 candidates found in input
ifplugd(eth0)[8396]: client: guessnet: Guessnet 0.33 starting...
ifplugd(eth0)[8396]: client: guessnet: Trying MII detection
ifplugd(eth0)[8396]: client: guessnet: 2 candidate profiles
ifplugd(eth0)[8396]: client: guessnet: Trying MII detection
ifplugd(eth0)[8396]: client: guessnet: Initialized test subsystems
ifplugd(eth0)[8396]: client: guessnet: Added "default" test lan-dhcp
ifplugd(eth0)[8396]: client: guessnet: Default test is lan-dhcp
ifplugd(eth0)[8396]: client: guessnet: Will check network lan-pub for IP address 192.168.6.254 (MAC 00:50:04:74:15:ae)
ifplugd(eth0)[8396]: client: guessnet: Starting test subsystem
kernel: device eth0 entered promiscuous mode
ifplugd(eth0)[8396]: client: guessnet: Sending 10 ARP probes, 1 every second...
ifplugd(eth0)[8396]: client: guessnet: Will check network lan-home for IP address 192.168.250.254 (MAC 00:0f:b5:7f:18:a8)
ifplugd(eth0)[8396]: client: guessnet: Sending 10 ARP probes, 1 every second...
ifplugd(eth0)[8396]: client: guessnet: Started tests
ifplugd(eth0)[8396]: client: guessnet: 3 candidates
ifplugd(eth0)[8396]: client: guessnet: Got ARP reply from 192.168.250.254 00:0f:b5:7f:18:a8
ifplugd(eth0)[8396]: client: guessnet: ARP reply from 192.168.250.254 00:0f:b5:7f:18:a8 matches
kernel: device eth0 left promiscuous mode
postfix/postfix-script: fatal: the Postfix mail system is not running
ifplugd(eth0)[8396]: client: run-parts: /etc/resolvconf/update-libc.d/postfix exited with return code 1
ifplugd(eth0)[8396]: client: Reloading squid configuration files...done.
ifplugd(eth0)[8396]: client: run-parts: /etc/resolvconf/update.d/libc exited with return code 1
ifplugd(eth0)[8396]: client: run-parts: /etc/network/if-up.d/000resolvconf exited with return code 1
ifplugd(eth0)[8396]: Program executed successfully.

La rete è stata identificata correttamente, infatti:

ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:08:02:68:3A:7C
          inet addr:192.168.250.200  Bcast:192.168.250.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1147 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1236 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:415344 (405.6 KiB)  TX bytes:136355 (133.1 KiB)

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.250.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.250.254 0.0.0.0         UG    0      0        0 eth0

cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 194.20.8.1
search diesis.priv

Configurazione scheda Wireless

Le schede PCMCIA vengono gestite da hotplug, e quindi non avrebbero bisogno di ifplugd.

Testiamo comunque una configurazione singola per vedere se il tutto funziona correttamente:

sudoedit /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

iface ath0 inet dhcp
        wireless-essid homefuz

Configuriamo ifplug

Restartiamo il networking:

sudo /etc/init.d/networking stop; sudo /etc/init.d/networking start
sudo /etc/init.d/ifplugd stop; sudo /etc/init.d/ifplugd start

Monitoriamo il log e inseriamo la scheda PCMCIA:

sudo tail -f /var/log/syslog | cut --delim=" " -f 6-

kernel: ath_hal: no version for "struct_module" found: kernel tainted.
kernel: ath_hal: module license 'Proprietary' taints kernel.
kernel: ath_hal: 0.9.14.9 (AR5210, AR5211, AR5212, RF5111, RF5112, RF2413)
kernel: wlan: 0.8.6.0 (EXPERIMENTAL)
kernel: ath_rate_onoe: 1.0
kernel: ath_pci: 0.9.6.0 (EXPERIMENTAL)
kernel: PCI: Enabling device 0000:03:00.0 (0000 -> 0002)
kernel: ACPI: PCI interrupt 0000:03:00.0[A] -> GSI 11 (level, low) -> IRQ 11
pci.agent[10787]:      ath_pci: loaded successfully
kernel: Build date: Jul 16 2005
kernel: Debugging version (IEEE80211)
kernel: ath0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
kernel: ath0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
kernel: ath0: turboG rates: 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
kernel: ath0: H/W encryption support: WEP AES AES_CCM TKIP
kernel: ath0: mac 7.9 phy 4.5 radio 5.6
kernel: ath0: Use hw queue 1 for WME_AC_BE traffic
kernel: ath0: Use hw queue 0 for WME_AC_BK traffic
kernel: ath0: Use hw queue 2 for WME_AC_VI traffic
kernel: ath0: Use hw queue 3 for WME_AC_VO traffic
kernel: ath0: Use hw queue 8 for CAB traffic
kernel: ath0: Use hw queue 9 for beacons
kernel: Debugging version (ATH)
kernel: ath0: Atheros 5212: mem=0x20800000, irq=11
ifplugd.hotplug[10885]: Invoking ifplugd for ath0
ifplugd(ath0)[10907]: ifplugd 0.26 initializing.
ifplugd(ath0)[10907]: Using interface ath0/00:11:95:8F:0B:68 with driver <ath_pci> (version: 0.9.6.0 (EXPERIMENTAL))
ifplugd(ath0)[10907]: Using detection mode: wireless extension
ifplugd(ath0)[10907]: Initialization complete, link beat not detected.
waproamd.hotplug[10908]: Invoking waproamd for ath0
ifplugd(ath0)[10907]: Link beat detected.
ifplugd(ath0)[10907]: Executing '/etc/ifplugd/ifplugd.action ath0 up'.
dhclient: Internet Systems Consortium DHCP Client V3.0.1
ifplugd(ath0)[10907]: client: Internet Systems Consortium DHCP Client V3.0.1
dhclient: Copyright 2004 Internet Systems Consortium.
ifplugd(ath0)[10907]: client: Copyright 2004 Internet Systems Consortium.
dhclient: All rights reserved.
ifplugd(ath0)[10907]: client: All rights reserved.
dhclient: For info, please visit http://www.isc.org/products/DHCP
ifplugd(ath0)[10907]: client: For info, please visit http://www.isc.org/products/DHCP
dhclient:
dhclient: Listening on LPF/ath0/00:11:95:8f:0b:68
ifplugd(ath0)[10907]: client: Listening on LPF/ath0/00:11:95:8f:0b:68
dhclient: Sending on   LPF/ath0/00:11:95:8f:0b:68
ifplugd(ath0)[10907]: client: Sending on   LPF/ath0/00:11:95:8f:0b:68
dhclient: Sending on   Socket/fallback
ifplugd(ath0)[10907]: client: Sending on   Socket/fallback
dhclient: DHCPDISCOVER on ath0 to 255.255.255.255 port 67 interval 4
ifplugd(ath0)[10907]: client: DHCPDISCOVER on ath0 to 255.255.255.255 port 67 interval 4
dhclient: DHCPOFFER from 192.168.250.254
dhclient: DHCPREQUEST on ath0 to 255.255.255.255 port 67
ifplugd(ath0)[10907]: client: DHCPOFFER from 192.168.250.254
ifplugd(ath0)[10907]: client: DHCPREQUEST on ath0 to 255.255.255.255 port 67
dhclient: DHCPACK from 192.168.250.254
ifplugd(ath0)[10907]: client: DHCPACK from 192.168.250.254
postfix/postfix-script: fatal: the Postfix mail system is not running
ifplugd(ath0)[10907]: client: run-parts: /etc/resolvconf/update-libc.d/postfix exited with return code 1
ifplugd(ath0)[10907]: client: Reloading squid configuration files...done.
ifplugd(ath0)[10907]: client: run-parts: /etc/resolvconf/update.d/libc exited with return code 1
dhclient: bound to 192.168.250.200 -- renewal in 102919 seconds.
ifplugd(ath0)[10907]: client: bound to 192.168.250.200 -- renewal in 102919 seconds.
ifplugd(ath0)[10907]: Program executed successfully.