Wiki Ubuntu-it

Indice
Partecipa
FAQ
Wiki Blog
------------------
Ubuntu-it.org
Forum
Chiedi
Chat
Cerca
Planet
  • Pagina non alterabile
  • Informazioni
  • Allegati
  • Differenze per "Cestino/Router"
Differenze tra le versioni 45 e 53 (in 8 versioni)
Versione 45 del 16/10/2008 14.38.51
Dimensione: 18159
Commento:
Versione 53 del 18/10/2020 21.48.33
Dimensione: 0
Autore: jeremie2
Commento:
Le cancellazioni sono segnalate in questo modo. Le aggiunte sono segnalate in questo modo.
Linea 1: Linea 1:
#pragma section-numbers on
#format wiki
#language it
[[BR]]

[[Indice]]

= Introduzione =

Questa pagina esiste a causa della mancanza di informazioni concise e istruzioni facilmente oomprensibili a proposito dell'installazione di un router per reti via cavo e/o senza fili su '''Ubuntu'''. È destinata ad utenti esperti e intermedi che devono o vorrebbero mettere a punto un'installazione dedicata di Ubuntu facente funzioni di router a casa o in ufficio. Il risultato finale è un potente router che può fornire funzionalità analoghe a prodotti conosciuti (per esempio, il Linksys WRT54G).

Il router che sarà creato è un [:InternetRete/ConfigurazioneRete/GatewayLan: gateway internet] per client via cavo/senza fili che condividono una connessione a banda larga con un unico indirizzo IP.

Le funzioni base che il router sarà in grado di eseguire:
 * Firewall
 * IP Masquerading
 * Port forwarding
 * Server DHCP
 * Server DNS cache

= Preparativi =

== Connessione a banda larga ==

È necessaria una connessione ADSL. Il fornitore di servizi a banda larga deve presentare le necessarie informazioni per configurare l'indirizzo IP statico o fornire un indirizzo assegnato dinamicamente tramite DHCP.

== Requisiti hardware ==

Occorre possedere un computer adeguato ad agire come router. Il calcolatore puo utilizzare vecchi componenti hardware, e avere caratteristiche tali da soddisfare i [:Installazione/RequisitiDiSistema: requisiti minimi] per installare '''Ubuntu''' dovrebbe essere sufficiente. Per esempio l'autore di questa pagina fa funzionare il suo router su un processore ''Pentium 3'' a ''600 MHz'' e con ''256 megabyte'' di RAM. Ne viene incoraggiato l'uso come server per altre applicazioni, probabilmente installando '''postfix''', '''apache''', '''mysql''' e/o '''samba'''. Questa guida suggerisce un'installazione '''server''' di Ubuntu, ma non vi è alcuna ragione per la quale un'installazione '''desktop''' non dovrebbe funzionare. Se si prevede di poter accedere al router da remoto, conviene installare '''ssh''' prima di continuare.

Per l'implementazione di un router server occorre avere a disposizione i seguenti componenti:
 * Scheda di rete connessa al modem DSL o al cavo a banda larga
 * '''Per una rete via cavo''',
   * Un'altra scheda di rete connessa ad un hub o switch.
 * '''Per una rete senza fili''',
  * Una scheda di rete wireless impostata in modalità «master»
||<tablestyle="text-align: justify; width:100%;" style="border:none;" 5%>[[Immagine(Icone/Piccole/note.png,,center)]] ||<style="padding:0.5em; border:none;">''Per mostrare le interfacce di rete disponibili digitare il comando'' {{{ifconfig -a}}}.||
||<tablestyle="text-align: justify; width:100%;" style="border:none;" 5%>[[Immagine(Icone/Piccole/note.png,,center)]] ||<style="padding:0.5em; border:none;">''Nel caso della rete senza fili il comando'' {{{sudo iwconfig «nome_dispositivo» mode master}}} ''non dovrebbe restituire alcun errore''.||
||<tablestyle="text-align: justify; width:100%;" style="border:none;" 5%>[[Immagine(Icone/Grandi/info.png,,center)]] ||<style="padding:0.5em; border:none;">Se la scheda di rete wireless non viene riconosciuta durante l'installazione '''Server''' di Ubuntu, puo darsi che essa utilizzi il chipset madwifi (come ad esempio D-Link DWL-G520). ||


= Informazioni sulla rete interna =

Questi sono i valori per gli indirizzi IP che saranno utilizzati nella configurazione della rete interna:

||<style="background-color:#FB8B00; ">||<style="background-color:#FB8B00; ":> '''Router''' ||
|| Host ||<:> 192.168.0.1 ||
|| Rete ||<:> 192.168.0.0 ||
|| Netmask || 255.255.255.0 ||
|| Broadcast || 192.168.0.255 ||

||<style="background-color:#FB8B00; ">||<style="background-color:#FB8B00; ":> '''Client''' ||
|| Host (uno o più) || 192.168.0.2 - 192.168.0.254 ||
|| Netmask ||<:> 255.255.255.0 ||
|| Broadcast ||<:> 192.168.0.255 ||
|| Gateway ||<:> 192.168.0.1 ||

||<tablestyle="text-align: justify; width:100%;" style="border:none;" 5%>[[Immagine(Icone/Piccole/warning.png,,center)]] ||<style="padding:0.5em; border:none;">'''Gli utenti più esperti prestino attenzione in caso di modifiche, poichè i cambiamenti dovranno riflettersi in tutta la successiva configurazione del router.''' ||

= Configurazione delle interfacce di rete =

== Descrizione dei tipi di dispositivo ==

||<style="background-color:#FB8B00; "> '''Interfaccia''' ||<style="background-color:#FB8B00; ":> '''Rete''' ||<style="background-color:#FB8B00; ":>'''Descrizione''' ||
||<style="text-align:center"> «'''eth0'''» ||<style="text-align:center"> esterna || scheda di rete connessa alla rete esterna (connessione a banda larga) ||
||<style="text-align:center"> «'''eth1'''» ||<style="text-align:center"> interna || scheda di rete connessa a un hub o ad uno switch ||
||<style="text-align:center"> «'''wlan0'''» ||<style="text-align:center"> interna || scheda di rete wireless ||
||<style="text-align:center"> «'''br0'''» ||<style="text-align:center"> interna || bridge di rete fra «'''eth1'''» e «'''wlan0'''» che tratterà le due schede come se fossero un unico dispositivo ||

||<tablestyle="text-align: justify; width:100%;" style="border:none;" 5%>[[Immagine(Icone/Piccole/note.png,,center)]] ||<style="padding:0.5em; border:none;">''È importante notare che i nomi dei dispositivi di rete qui sopra (eth0, eth1 e wlan0) sono usati come convenzione. È molto probabile che il router riconosca i dispositivi con nomi differenti (per esempio, i madwifi chiamano il relativo dispositivo wireless "ath0"). Si prega, di conseguenza, di sostituire i nomi presenti in questa guida con quelli assegnati dal sistema.'' ||
||<tablestyle="text-align: justify; width:100%;" style="border:none;" 5%>[[Immagine(Icone/Grandi/info.png,,center)]] ||<style="padding:0.5em; border:none;">Per informazioni su come cambiare i nomi dei dispositivi di rete digitare in un terminale {{{man iftab}}}. ||


== Copia della configurazione ==

Digitare il seguente comando per creare una copia della configurazione di rete corrente:
{{{sudo cp /etc/network/interfaces /etc/network/interfaces.bak
}}}

== Rete esterna ==

=== Configurare l'interfaccia di rete esterna ===

Qui verrà configurato il sistema di rete di Ubuntu per richiamare l'intefaccia locale di loopback e quella della rete esterna modificando il file `/etc/networking/interfaces`. L'obiettivo primario è quello di impostare l'interfaccia della rete esterna (eth0, o qualunque altra si stia usando al posto di essa), in modo da poter essere richiamata dal sottosistema di rete.
||<tablestyle="text-align: justify; width:100%;" style="border:none;" 5%>[[Immagine(Icone/Grandi/info.png,,center)]] ||<style="padding:0.5em; border:none;">Gli esempi qui sotto servono solamente per la maggior parte delle configurazioni di base. Se l'installazione richiedesse una configurazione extra (ad esempio si dovesse impostare la connessione ADSL con PPPoE), adattare i seguenti esempi in modo tale che l'interfaccia della rete esterna alla fine risulti connessa ad Internet. ||

 * '''Con indirizzi IP assegnati in modo dinamico (DHCP):'''

 Aprire il file `/etc/network/interfaces` con un [:Ufficio/EditorDiTesto:editor di testo], cancellare tutto il contenuto e sostituirlo con il blocco riportato di seguito. Prestare attenzione alle righe commentate.
 {{{# Set up the local loopback interface
auto lo
iface lo inet loopback

# Set up the external interface
#
# Don't forget to change eth0 to the proper name of the external
# interface if applicable.
#
auto eth0
iface eth0 inet dhcp}}}

 * '''Con indirizzi IP assegnati staticamente:'''

 Aprire il file `/etc/network/interfaces` con un [:Ufficio/EditorDiTesto:editor di testo], cancellare tutto il contenuto e sostituirlo con il blocco riportato di seguito. Prestare attenzione alle righe commentate.

 {{{# Set up the local loopback interface
auto lo
iface lo inet loopback

# Set up the External interface
#
# For every xxx.xxx.xxx.xxx, enter the numeric address given to you
# by your Internet provider. Don't forget to change eth0 to the proper
# name of the external interface if applicable.
#
auto eth0
iface eth0 inet static
    address xxx.xxx.xxx.xxx
    netmask xxx.xxx.xxx.xxx
    gateway xxx.xxx.xxx.xxx}}}

Ora, impostare i nomi e gli indirizzi IP dei server DNS, così come specificato dal proprio provider, nel file `/etc/resolv.conf`, il quale dovrebbe presentarsi più o meno in modo simile:
 {{{nameserver xxx.xxx.xxx.xxx
nameserver xxx.xxx.xxx.xxx}}}

Tu puoi visitare il [https://help.ubuntu.com/6.06/ubuntu/serverguide/C/network-configuration.html Ubuntu Server Guide - Network Configuration] per ulteriori guide.

=== Test della connettività ===

Ricaricare la configurazione di rete ed eseguire il test per la connettivita',
 {{{sudo /etc/init.d/networking restart
ping -c 3 -W 10 ubuntu.com}}}
E se tutto va bene dovrebbe apparire qualcosa di simile:
 {{{PING ubuntu.com (82.211.81.166) 56(84) bytes of data.
64 bytes from signey.ubuntu.com (82.211.81.166): icmp_seq=1 ttl=43 time=99.9 ms
64 bytes from signey.ubuntu.com (82.211.81.166): icmp_seq=2 ttl=43 time=109 ms
64 bytes from signey.ubuntu.com (82.211.81.166): icmp_seq=3 ttl=43 time=100 ms

--- ubuntu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 99.982/103.450/109.419/4.254 ms}}}

== Rete interna ==

=== Solo cablata ===

'''Aggiungere '' quanto segue a `/etc/network/interfaces` e seguire le righe commentate con attenzione..
 {{{# Set up the internal wired network
#
# Don't forget to change eth1 to the proper name of the internal
# wired network interface if applicable.
#
auto eth1
iface eth1 inet static
    address 192.168.0.1
    network 192.168.0.0
    netmask 255.255.255.0
    broadcast 192.168.0.255}}}

L'interfaccia delle vostra rete interna è: __'''eth1'''__ (o qualsiasi altra stiate usando al posto di essa)

=== Solo Wireless ===

Se si pensa di utilizzare WEP, generare una chiave di rete,
 {{{dd if=/dev/random bs=1 count=13 2>/dev/null | xxd -p
}}}

'''Aggiungere''' quanto segue a `/etc/network/interfaces` e seguire le righe commentate con attenzione.
 {{{# Set up the internal wireless network
#
# Don't forget to change wlan0 to the proper name of the internal
# wireless network interface if applicable.
#
# If you would like to use WEP, uncomment the line 'wireless-key'
# and replace '<key goes here>' with a WEP key.
#
# You may also change the network essid and channel.
#
auto wlan0
iface wlan0 inet static
    wireless-mode master
    wireless-essid "UbuntuWireless"
    wireless-channel 1
    #wireless-key <key goes here>
    address 192.168.0.1
    network 192.168.0.0
    netmask 255.255.255.0
    broadcast 192.168.0.255}}}


La vostra interfaccia di rete interna è: __'''wlan0'''__ (o qualsiasi altra stiate usando al posto di essa)

=== Cablata e wireless contemporaneamente ===

Innanzitutto installare gli strumenti necessari per creare un bridge di rete,
 {{{sudo apt-get install bridge-utils
}}}

Se si pensa di utilizzare WEP, generare una chiave di rete,
 {{{dd if=/dev/random bs=1 count=13 2>/dev/null | xxd -p
}}}

'''Aggiungere''' le seguenti a `/etc/network/interfaces` e seguire le righe commentate con attenzione.
 {{{# Set up the internal wireless network
#
# Don't forget to change wlan0 to the proper name of the internal
# wireless network interface if applicable.
#
# If you would like to use WEP, uncomment the line 'wireless-key'
# and replace '<key goes here>' with a WEP key.
#
# You may also change the network essid and channel.
#
auto wlan0
iface wlan0 inet manual
    wireless-mode master
    wireless-essid "UbuntuWireless"
    wireless-channel 1
    #wireless-key <key goes here>

# Set up the internal wired network
#
# It's not necessary to bring this interface up as the bridge
# we are about to create does this. Leave these lines commented.
#
#auto eth1
#iface eth1 inet manual


# Set up the internal wired/wireless network bridge
#
# Don't forget to change wlan0 and eth1 to the proper name of
# the internal wired and wireless interfaces if applicable.
#
auto br0
iface br0 inet static
    address 192.168.0.1
    network 192.168.0.0
    netmask 255.255.255.0
    broadcast 192.168.0.255
    bridge-ports eth1 wlan0}}}

La vostra interfaccia di rete interna è: __'''br0'''__

== Riavviare la rete ==

Ora, se il seguente comando viene eseguito con successo, i tuoi dispositivi di rete sono stati correttamente configurati.
 {{{sudo /etc/init.d/networking restart
}}}

= Configurazione del Firewall =

== Sfondo ==

== Il Firewall Script ==

'''''Questo è solo un __progetto grezzo__!'''''

{{{
#!/bin/sh

IPTABLES=/sbin/iptables
AWK=/usr/bin/awk
IFCONFIG=/sbin/ifconfig


# External (Internet-facing) interface
EXTIF="eth0"

# External IP address (automatically detected)
EXTIP="`$IFCONFIG $EXTIF | $AWK /$EXTIF/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'`"
 
# Internal interface
INTIF="br0"

# Internal IP address (in CIDR notation)
INTIP="192.168.0.1/32"

# Internal network address (in CIDR notation)
INTNET="192.168.0.0/24"

# The address of anything/everything (in CIDR notation)
UNIVERSE="0.0.0.0/0"


echo "External: [Interface=$EXTIF] [IP=$EXTIP]"
echo "Internal: [Interface=$INTIF] [IP=$INTIP] [Network:$INTNET]"

echo
echo -n "Loading rules..."

# Enabling IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward


# Clear any existing rules and set the default policy to DROP
$IPTABLES -P INPUT DROP
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT DROP
$IPTABLES -F OUTPUT
$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
$IPTABLES -F -t nat

# Delete all User-specified chains
$IPTABLES -X

# Reset all IPTABLES counters
$IPTABLES -Z

###################################################
# INPUT: Incoming traffic from various interfaces #
###################################################

# Loopback interface is valid
$IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT


# Local interface, local machines, going anywhere is valid
$IPTABLES -A INPUT -i $INTIF -s $INTNET -d $UNIVERSE -j ACCEPT


# Remote interface, claiming to be local machines, IP spoofing, get lost
$IPTABLES -A INPUT -i $EXTIF -s $INTNET -d $UNIVERSE -j REJECT


# External interface, from any source, for ICMP traffic is valid
$IPTABLES -A INPUT -i $EXTIF -p ICMP -s $UNIVERSE -d $EXTIP -j ACCEPT


# Allow any related traffic coming back to the MASQ server in.
$IPTABLES -A INPUT -i $EXTIF -s $UNIVERSE -d $EXTIP -m state --state ESTABLISHED,RELATED -j ACCEPT


# Internal interface, DHCP traffic accepted
$IPTABLES -A INPUT -i $INTIF -p tcp --sport 68 --dport 67 -j ACCEPT
$IPTABLES -A INPUT -i $INTIF -p udp --sport 68 --dport 67 -j ACCEPT


# External interface, HTTP/HTTPS traffic allowed
$IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED -p tcp -s $UNIVERSE -d $EXTIP --dport 80 -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED -p tcp -s $UNIVERSE -d $EXTIP --dport 443 -j ACCEPT

# External interface, SSH traffic allowed
$IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED -p tcp -s $UNIVERSE -d $EXTIP --dport 22 -j ACCEPT


# Catch-all rule, reject anything else
$IPTABLES -A INPUT -s $UNIVERSE -d $UNIVERSE -j REJECT


####################################################
# OUTPUT: Outgoing traffic from various interfaces #
####################################################

# Workaround bug in netfilter
$IPTABLES -A OUTPUT -m state -p icmp --state INVALID -j DROP

# Loopback interface is valid.
$IPTABLES -A OUTPUT -o lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT


# Local interfaces, any source going to local net is valid
$IPTABLES -A OUTPUT -o $INTIF -s $EXTIP -d $INTNET -j ACCEPT


# local interface, MASQ server source going to the local net is valid
$IPTABLES -A OUTPUT -o $INTIF -s $INTIP -d $INTNET -j ACCEPT


# outgoing to local net on remote interface, stuffed routing, deny
$IPTABLES -A OUTPUT -o $EXTIF -s $UNIVERSE -d $INTNET -j REJECT


# anything else outgoing on remote interface is valid
$IPTABLES -A OUTPUT -o $EXTIF -s $EXTIP -d $UNIVERSE -j ACCEPT


# Internal interface, DHCP traffic accepted
$IPTABLES -A OUTPUT -o $INTIF -p tcp -s $INTIP --sport 67 -d 255.255.255.255 --dport 68 -j ACCEPT
$IPTABLES -A OUTPUT -o $INTIF -p udp -s $INTIP --sport 67 -d 255.255.255.255 --dport 68 -j ACCEPT


# Catch all rule, all other outgoing is denied and logged.
$IPTABLES -A OUTPUT -s $UNIVERSE -d $UNIVERSE -j REJECT


###########################
# Packet Forwarding / NAT #
###########################

# ----- Begin OPTIONAL FORWARD Section -----

#Optionally forward incoming tcp connections on port 1234 to 192.168.0.100
#$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -p tcp --dport 1234 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
#$IPTABLES -A PREROUTING -t nat -p tcp -d $EXTIP --dport 1234 -m state --state NEW,ESTABLISHED,RELATED -j DNAT --to 192.168.0.100:1234

# ----- Fine della sezione facoltativa -----


# Accept solicited tcp packets
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow packets across the internal interface
$IPTABLES -A FORWARD -i $INTIF -o $INTIF -j ACCEPT

# Forward packets from the internal network to the Internet
$IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT

# Catch-all REJECT rule
$IPTABLES -A FORWARD -j REJECT

# IP-Masquerade
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j SNAT --to $EXTIP


echo " done."}}}

= DHCP e DNS =

= Ulteriori risorse =

 * [https://help.ubuntu.com/community/Router Documento originale]
 * [http://it.wikipedia.org/wiki/Network_address_translation Voce encliclopedica di Masquerading]
----
CategoryNuoviDocumenti CategoryInTraduzione