|
⇤ ← Revision 1 as of 2013-01-11 16:49:42
Size: 2937
Comment: first translated version
|
← Revision 2 as of 2013-01-12 20:17:23 ⇥
Size: 831
Comment: Add link to french translation + import script from English master
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 2: | Line 2: |
| ~-[[DebianWiki/EditorGuide#translation|Translation(s)]]: [[ConvertNetToStatic|English]] - Italiano-~ | ~-[[DebianWiki/EditorGuide#translation|Translation(s)]]: [[ConvertNetToStatic|English]] - [[fr/ConvertNetToStatic|Français]] - Italiano-~ |
| Line 11: | Line 11: |
| {{{ #!highlight bash #!/bin/bash set -e #functions cidr2mask() { local i mask="" local full_octets=$(($1/8)) local partial_octet=$(($1%8)) for ((i=0;i<4;i+=1)); do if [ $i -lt $full_octets ]; then mask+=255 elif [ $i -eq $full_octets ]; then mask+=$((256 - 2**(8-$partial_octet))) else mask+=0 fi test $i -lt 3 && mask+=. done echo $mask } gen-interfaces(){ cat <<EOF | $FILTER # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 EOF #Use sed magic and function cidr2mask to convert ip command output into output of this form # eth0-1 iface eth0 inet static # eth0-2 address nnn.nnn.50.203 # eth0-4 broadcast nnn.nnn.51.255 # eth0-3 netmask nnn.nnn.254.0 # eth0-5 gateway 138.37.51.254 #In preparation for further filtering ( ip addr show |\ sed -n -e's%.*inet \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)/\([0-9]*\) brd \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\) scope global \(.*\)%'\ '\4-1 iface \4 inet static\n\4-2 \taddress \1\n\4-4 \tbroadcast \3%p' ip addr show |\ sed -n -e's%.*inet \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)/\([0-9]*\) brd \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\) scope global \(.*\)%'\ '\4-3 \2\n%p' | (read key mask; if [ -n "$mask" ] ; then printf "%s \t%s %s\n" $key netmask `cidr2mask $mask` ; fi) ip route show |sed -n -e's%default via \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\) dev \(.*\) %\2-5 \t\gateway \1%p' )| sort | cut -f2- -d" " | $FILTER if [ $BOND = 1 ] ; then cat <<EOF slaves eth0 eth1 bond_mode 802.3ad bond_miimon 100 bond_updelay 200 bond_downdelay 200 bond_xmit_hash_policy layer2+3 EOF fi } #Main BOND=0 if [ "$1" = "--bond" ] ; then BOND=1 fi FILTER=cat if [ $BOND = 1 ] ; then FILTER='sed -e s/eth0/bond0/ ' fi [ -f /etc/network/interfaces.orig ] || cp -p /etc/network/interfaces /etc/network/interfaces.orig gen-interfaces >/etc/network/interfaces.new ifdown eth0 cp -p /etc/network/interfaces /etc/network/interfaces-"`date +%F-%T`" mv /etc/network/interfaces.new /etc/network/interfaces if [ $BOND = 1 ] ; then ifconfig eth0 0.0.0.0 ifup bond0 else ifup eth0 fi }}} |
<<Include(ConvertNetToStatic, ,from="^##TAG:SCRIPT_1_START",to="^##TAG:SCRIPT_1_END")>> |
Translation(s): English - Français - Italiano
Esiste un bug segnalato da molto tempo (267838, segnato come bug che non verrà risolto) riguardandte l'installatore Debian che riguarda la possibilità di avviare una macchina usando DHCP durante l'installazione, ma creare il sistema installato con una configurazione di rete statica.
Questo è uno script scritto da AlexOwen da eseguire al primo avvio per fare il cambiamento per conto dell'utente. Accetta anche un argomento "--bond" per la conversione in un'interfaccia statica bonded.
L'autore lo rende disponibile nella speranza che sia di aiuto ad altri.
1 #!/bin/bash
2 set -e
3
4 #functions
5
6 cidr2mask() {
7 local i mask=""
8 local full_octets=$(($1/8))
9 local partial_octet=$(($1%8))
10
11 for ((i=0;i<4;i+=1)); do
12 if [ $i -lt $full_octets ]; then
13 mask+=255
14 elif [ $i -eq $full_octets ]; then
15 mask+=$((256 - 2**(8-$partial_octet)))
16 else
17 mask+=0
18 fi
19 test $i -lt 3 && mask+=.
20 done
21
22 echo $mask
23 }
24
25
26 gen-interfaces(){
27
28 cat <<EOF | $FILTER
29 # The loopback network interface
30 auto lo
31 iface lo inet loopback
32
33 # The primary network interface
34 auto eth0
35 EOF
36
37 #Use sed magic and function cidr2mask to convert ip command output into output of this form
38 # eth0-1 iface eth0 inet static
39 # eth0-2 address nnn.nnn.50.203
40 # eth0-4 broadcast nnn.nnn.51.255
41 # eth0-3 netmask nnn.nnn.254.0
42 # eth0-5 gateway 138.37.51.254
43 #In preparation for further filtering
44
45 (
46 ip addr show |\
47 sed -n -e's%.*inet \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)/\([0-9]*\) brd \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\) scope global \(.*\)%'\
48 '\4-1 iface \4 inet static\n\4-2 \taddress \1\n\4-4 \tbroadcast \3%p'
49 ip addr show |\
50 sed -n -e's%.*inet \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)/\([0-9]*\) brd \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\) scope global \(.*\)%'\
51 '\4-3 \2\n%p' | (read key mask; if [ -n "$mask" ] ; then printf "%s \t%s %s\n" $key netmask `cidr2mask $mask` ; fi)
52 ip route show |sed -n -e's%default via \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\) dev \(.*\) %\2-5 \t\gateway \1%p'
53 )| sort | cut -f2- -d" " | $FILTER
54
55 if [ $BOND = 1 ] ; then
56 cat <<EOF
57 slaves eth0 eth1
58 bond_mode 802.3ad
59 bond_miimon 100
60 bond_updelay 200
61 bond_downdelay 200
62 bond_xmit_hash_policy layer2+3
63 EOF
64 fi
65 }
66
67
68 #Main
69
70 BOND=0
71 if [ "$1" = "--bond" ] ; then
72 BOND=1
73 fi
74
75 FILTER=cat
76 if [ $BOND = 1 ] ; then
77 FILTER='sed -e s/eth0/bond0/ '
78 fi
79
80 [ -f /etc/network/interfaces.orig ] || cp -p /etc/network/interfaces /etc/network/interfaces.orig
81
82 gen-interfaces >/etc/network/interfaces.new
83
84 ifdown eth0
85
86 cp -p /etc/network/interfaces /etc/network/interfaces-"`date +%F-%T`"
87 mv /etc/network/interfaces.new /etc/network/interfaces
88
89 if [ $BOND = 1 ] ; then
90 ifconfig eth0 0.0.0.0
91 ifup bond0
92 else
93 ifup eth0
94 fi
