| … | |
… | |
| 2 | <!DOCTYPE sections SYSTEM "/dtd/book.dtd"> |
2 | <!DOCTYPE sections SYSTEM "/dtd/book.dtd"> |
| 3 | |
3 | |
| 4 | <!-- The content of this document is licensed under the CC-BY-SA license --> |
4 | <!-- The content of this document is licensed under the CC-BY-SA license --> |
| 5 | <!-- See http://creativecommons.org/licenses/by-sa/2.5 --> |
5 | <!-- See http://creativecommons.org/licenses/by-sa/2.5 --> |
| 6 | |
6 | |
| 7 | <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-net-advanced.xml,v 1.10 2005/12/21 12:20:43 jkt Exp $ --> |
7 | <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-net-advanced.xml,v 1.11 2005/12/22 19:55:49 jkt Exp $ --> |
| 8 | |
8 | |
| 9 | <sections> |
9 | <sections> |
| 10 | |
10 | |
| 11 | <version>1.3</version> |
11 | <version>1.4</version> |
| 12 | <date>2005-08-14</date> |
12 | <date>2005-12-22</date> |
| 13 | |
13 | |
| 14 | <section> |
14 | <section> |
| 15 | <title>Advanced Configuration</title> |
15 | <title>Advanced Configuration</title> |
| 16 | <body> |
16 | <body> |
| 17 | |
17 | |
| 18 | <p> |
18 | <p> |
| 19 | The config_eth0 variable is the heart of an interface's configuration. It's a |
19 | The <c>config_eth0</c> variable is the heart of an interface configuration. It's |
| 20 | high level instruction list for configuring the interface (eth0 in this case). |
20 | a high level instruction list for configuring the interface (<c>eth0</c> in this |
| 21 | Each command in the instruction list is performed sequentially. The interface is |
21 | case). Each command in the instruction list is performed sequentially. The |
| 22 | deemed OK if at least one command works. |
22 | interface is deemed OK if at least one command works. |
| 23 | </p> |
23 | </p> |
| 24 | |
24 | |
| 25 | <p> |
25 | <p> |
| 26 | Here's a list of in-built instructions. |
26 | Here's a list of in-built instructions. |
| 27 | </p> |
27 | </p> |
| … | |
… | |
| 30 | <tr> |
30 | <tr> |
| 31 | <th>Command</th> |
31 | <th>Command</th> |
| 32 | <th>Description</th> |
32 | <th>Description</th> |
| 33 | </tr> |
33 | </tr> |
| 34 | <tr> |
34 | <tr> |
| 35 | <ti>null</ti> |
35 | <ti><c>null</c></ti> |
| 36 | <ti>Do nothing</ti> |
36 | <ti>Do nothing</ti> |
| 37 | </tr> |
37 | </tr> |
| 38 | <tr> |
38 | <tr> |
| 39 | <ti>noop</ti> |
39 | <ti><c>noop</c></ti> |
| 40 | <ti> |
40 | <ti> |
| 41 | If the interface is up and there is an address then abort configuration |
41 | If the interface is up and there is an address then abort configuration |
| 42 | successfully |
42 | successfully |
| 43 | </ti> |
43 | </ti> |
| 44 | </tr> |
44 | </tr> |
| … | |
… | |
| 46 | <ti>an IPv4 or IPv6 address</ti> |
46 | <ti>an IPv4 or IPv6 address</ti> |
| 47 | <ti>Add the address to the interface</ti> |
47 | <ti>Add the address to the interface</ti> |
| 48 | </tr> |
48 | </tr> |
| 49 | <tr> |
49 | <tr> |
| 50 | <ti> |
50 | <ti> |
| 51 | dhcp, adsl or apipa (or a custom command from a 3rd party module) |
51 | <c>dhcp</c>, <c>adsl</c> or <c>apipa</c> (or a custom command from a 3rd |
| 52 | </ti> |
52 | party module) |
| 53 | <ti> |
53 | </ti> |
|
|
54 | <ti> |
| 54 | Run the module which provides the command. For example "dhcp" will run a |
55 | Run the module which provides the command. For example <c>dhcp</c> will run |
| 55 | module that provides dhcp which can be one of either dhcpcd, udhcpc, |
56 | a module that provides DHCP which can be one of either <c>dhcpcd</c>, |
| 56 | dhclient or pump. |
57 | <c>udhcpc</c>, <c>dhclient</c> or <c>pump</c>. |
| 57 | </ti> |
58 | </ti> |
| 58 | </tr> |
59 | </tr> |
| 59 | </table> |
60 | </table> |
| 60 | |
61 | |
| 61 | <p> |
62 | <p> |
| … | |
… | |
| 94 | "apipa" |
95 | "apipa" |
| 95 | ) |
96 | ) |
| 96 | </pre> |
97 | </pre> |
| 97 | |
98 | |
| 98 | <note> |
99 | <note> |
| 99 | When using the ifconfig module and adding more than one address, interface |
100 | When using the <c>ifconfig</c> module and adding more than one address, |
| 100 | aliases are created for each extra address. So with the above two examples you |
101 | interface aliases are created for each extra address. So with the above two |
| 101 | will get interfaces eth0, eth0:1 and eth0:2. You cannot do anything special with |
102 | examples you will get interfaces <c>eth0</c>, <c>eth0:1</c> and <c>eth0:2</c>. |
| 102 | these interfaces as the kernel and other programs will just treat eth0:1 and |
103 | You cannot do anything special with these interfaces as the kernel and other |
| 103 | eth0:2 as eth0. |
104 | programs will just treat <c>eth0:1</c> and <c>eth0:2</c> as <c>eth0</c>. |
| 104 | </note> |
105 | </note> |
| 105 | |
106 | |
| 106 | <impo> |
107 | <impo> |
| 107 | The fallback order is important! If we did not specify the "null" option then |
108 | The fallback order is important! If we did not specify the <c>null</c> option |
| 108 | the "apipa" command would only be run if the "noop" command failed. |
109 | then the <c>apipa</c> command would only be run if the <c>noop</c> command |
|
|
110 | failed. |
| 109 | </impo> |
111 | </impo> |
| 110 | |
112 | |
| 111 | <note> |
113 | <note> |
| 112 | <uri link="?part=4&chap=3#apipa">APIPA</uri> and <uri |
114 | <uri link="?part=4&chap=3#apipa">APIPA</uri> and <uri |
| 113 | link="?part=4&chap=3#dhcp">DHCP</uri> are discussed later. |
115 | link="?part=4&chap=3#dhcp">DHCP</uri> are discussed later. |
| … | |
… | |
| 119 | <title>Network Dependencies</title> |
121 | <title>Network Dependencies</title> |
| 120 | <body> |
122 | <body> |
| 121 | |
123 | |
| 122 | <p> |
124 | <p> |
| 123 | Init scripts in <path>/etc/init.d</path> can depend on a specific network |
125 | Init scripts in <path>/etc/init.d</path> can depend on a specific network |
| 124 | interface or just net. "net" can be defined in <path>/etc/conf.d/rc</path> to |
126 | interface or just net. <c>net</c> can be defined in <path>/etc/conf.d/rc</path> |
| 125 | mean different things using the <c>RC_NET_STRICT_CHECKING</c> variable. |
127 | to mean different things using the <c>RC_NET_STRICT_CHECKING</c> variable. |
| 126 | </p> |
128 | </p> |
| 127 | |
129 | |
| 128 | <table> |
130 | <table> |
| 129 | <tr> |
131 | <tr> |
| 130 | <th>Value</th> |
132 | <th>Value</th> |
| 131 | <th>Description</th> |
133 | <th>Description</th> |
| 132 | </tr> |
134 | </tr> |
| 133 | <tr> |
135 | <tr> |
| 134 | <ti>none</ti> |
136 | <ti><c>none</c></ti> |
| 135 | <ti>The net service is always considered up</ti> |
137 | <ti>The <path>net</path> service is always considered up</ti> |
| 136 | </tr> |
|
|
| 137 | <tr> |
138 | </tr> |
|
|
139 | <tr> |
| 138 | <ti>no</ti> |
140 | <ti><c>no</c></ti> |
| 139 | <ti> |
|
|
| 140 | This basically means that at least one net.* service besides net.lo must be |
|
|
| 141 | up. This can be used by notebook users that have a wifi and a static nic, |
|
|
| 142 | and only wants one up at any given time to have the net service seen as up. |
|
|
| 143 | </ti> |
141 | <ti> |
| 144 | </tr> |
142 | This basically means that at least one <path>net.*</path> service besides |
| 145 | <tr> |
143 | <path>net.lo</path> must be up. This can be used by notebook users that |
| 146 | <ti>lo</ti> |
144 | have a WIFI and a static NIC, and only wants one up at any given time to |
|
|
145 | have the net service seen as up. |
| 147 | <ti> |
146 | </ti> |
| 148 | This is the same as the 'no' option, but net.lo is also counted. This should |
147 | </tr> |
| 149 | be useful to people that do not care about any specific interface being up |
148 | <tr> |
| 150 | at boot. |
149 | <ti><c>lo</c></ti> |
| 151 | </ti> |
150 | <ti> |
| 152 | </tr> |
151 | This is the same as the <c>no</c> option, but <path>net.lo</path> is also |
| 153 | <tr> |
152 | counted. This should be useful to people that do not care about any specific |
| 154 | <ti>yes</ti> |
153 | interface being up at boot. |
| 155 | <ti> |
154 | </ti> |
|
|
155 | </tr> |
|
|
156 | <tr> |
|
|
157 | <ti><c>yes</c></ti> |
|
|
158 | <ti> |
| 156 | For this ALL network interfaces MUST be up for the 'net' service to be |
159 | For this ALL network interfaces MUST be up for the <path>net</path> service |
| 157 | considered up. |
160 | to be considered up. |
| 158 | </ti> |
161 | </ti> |
| 159 | </tr> |
162 | </tr> |
| 160 | </table> |
163 | </table> |
| 161 | |
164 | |
| 162 | <p> |
165 | <p> |
| 163 | But what about net.br0 depending on net.eth0 and net.eth1? net.eth1 may be a |
166 | But what about <path>net.br0</path> depending on <path>net.eth0</path> and |
| 164 | wireless or ppp device that needs configuration before it can be added to the |
167 | <path>net.eth1</path>? <path>net.eth1</path> may be a wireless or PPP device |
| 165 | bridge. This cannot be done in <path>/etc/init.d/net.br0</path> as that's a |
168 | that needs configuration before it can be added to the bridge. This cannot be |
| 166 | symbolic link to net.lo |
169 | done in <path>/etc/init.d/net.br0</path> as that's a symbolic link to |
| 167 | </p> |
170 | <path>net.lo</path>. |
| 168 | |
|
|
| 169 | <p> |
171 | </p> |
| 170 | The answer is making your own depend() function in <path>/etc/conf.d/net</path>. |
172 | |
|
|
173 | <p> |
|
|
174 | The answer is making your own <c>depend()</c> function in |
|
|
175 | <path>/etc/conf.d/net</path>. |
| 171 | </p> |
176 | </p> |
| 172 | |
177 | |
| 173 | <pre caption="net.br0 dependency in /etc/conf.d/net"> |
178 | <pre caption="net.br0 dependency in /etc/conf.d/net"> |
| 174 | <comment># You can use any dependency (use, after, before) as found in current scripts</comment> |
179 | <comment># You can use any dependency (use, after, before) as found in current scripts</comment> |
| 175 | depend_br0() { |
180 | depend_br0() { |
| … | |
… | |
| 193 | <p> |
198 | <p> |
| 194 | Variable names are dynamic. They normally follow the structure of |
199 | Variable names are dynamic. They normally follow the structure of |
| 195 | <c>variable_${interface|mac|essid|apmac}</c>. For example, the variable |
200 | <c>variable_${interface|mac|essid|apmac}</c>. For example, the variable |
| 196 | <c>dhcpcd_eth0</c> holds the value for dhcpcd options for eth0 and |
201 | <c>dhcpcd_eth0</c> holds the value for dhcpcd options for eth0 and |
| 197 | <c>dhcpcd_essid</c> holds the value for dhcpcd options when any interface |
202 | <c>dhcpcd_essid</c> holds the value for dhcpcd options when any interface |
| 198 | connects to the essid "essid". |
203 | connects to the ESSID "essid". |
| 199 | </p> |
204 | </p> |
| 200 | |
205 | |
| 201 | <p> |
206 | <p> |
| 202 | However, there is no hard and fast rule that states interface names must be |
207 | However, there is no hard and fast rule that states interface names must be |
| 203 | ethx. In fact, many wireless interfaces have names like wlanx, rax as well as |
208 | ethx. In fact, many wireless interfaces have names like wlanx, rax as well as |
| … | |
… | |
| 209 | |
214 | |
| 210 | <p> |
215 | <p> |
| 211 | The downside of all this is that Gentoo uses bash variables for networking - |
216 | The downside of all this is that Gentoo uses bash variables for networking - |
| 212 | and bash cannot use anything outside of English alpha-numerics. To get around |
217 | and bash cannot use anything outside of English alpha-numerics. To get around |
| 213 | this limitation we change every character that is not an English alpha-numeric |
218 | this limitation we change every character that is not an English alpha-numeric |
| 214 | into a _ character. |
219 | into a <c>_</c> character. |
| 215 | </p> |
220 | </p> |
| 216 | |
221 | |
| 217 | <p> |
222 | <p> |
| 218 | Another downside of bash is the content of variables - some characters need to |
223 | Another downside of bash is the content of variables - some characters need to |
| 219 | be escaped. This can be achived by placing the \ character in front of the |
224 | be escaped. This can be achived by placing the <c>\</c> character in front of |
| 220 | character that needs to be escaped. The following list of characters needs |
225 | the character that needs to be escaped. The following list of characters needs |
| 221 | to be escaped in this way: <c>"</c>, <c>'</c> and <c>\</c>. |
226 | to be escaped in this way: <c>"</c>, <c>'</c> and <c>\</c>. |
| 222 | </p> |
227 | </p> |
| 223 | |
228 | |
| 224 | <p> |
229 | <p> |
| 225 | In this example we use wireless ESSID as they can contain the widest scope |
230 | In this example we use wireless ESSID as they can contain the widest scope |