File: netenv.html

package info (click to toggle)
netenv 0.82-10
  • links: PTS
  • area: main
  • in suites: potato
  • size: 160 kB
  • ctags: 40
  • sloc: sh: 337; ansic: 136; makefile: 52
file content (393 lines) | stat: -rw-r--r-- 12,879 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
  <head>
    <title>Netenv 0.81 - Using a laptop in different network environments</title>
  </head>

  <body>
      <h2>Do you use your laptop in different network environments ?</h2>

    At home ? In the office ? At a customers site ?
    <p>
      If yes, the small package "netenv" might be useful for you. When 
      booting your laptop it provides you with a simple interface from 
      which you can choose the current network environment. If you are 
      the first time in an environment, you can enter the basic data
      for later reuse.
    <p>
      Netenv sets up a file containing variable assignments which
      describe the current environment. This can be used by the pcmcia
      setup scheme (e.g. like the one that comes with Debian and
      perhaps others). 
    <p>
      Have a look at netenv's chooser box:
    <p>

<img src="netenv.gif">
    <p>

      Besides the basic functionality of configuring the network
      interface, the netenv data can be used for thinks like:
    <ul>
      <li>Choose a proper XF86Config
	<p>

	Think of using your laptop standalone with touchpad
	vs. connected to a CRT monitor along with an external mouse.
	<p>
      <li>Configuring your windowmanager
	<p>
	  You can set up your windowmanager according to the current
	  location of your machine.
	<p>
      <li>Printing Environment
	<p>
	  The netenv data can easily be used to set up the printing
	  environment. 
    </ul>
    <p>
      Netenv is available as Debian package as well as tarball. It
      depends on dialog(1) for the menu system.
    <p>
A word to all gurus: In this docu I try to explain things with Linux
novices in mind, so be patient.
    <p>
You may start reading about <a HREF="./netenv.html#Basics">Basics</a>, 
or begin with <a HREF="./netenv.html#Installation">Installation</a>. Having the
Debian package you should be able to proceed to <a
HREF="./netenv.html#Configuration">Configuration</a>.
    <p>
But if you are like me, you may want to directly jump to my <a
HREF="./netenv.html#Examples">Examples</a> section. For those of you
who really reach this line, here is a link to all the <a
HREF="./netenv.html#otherstuff">other stuff</a>.



<h2><a name="Basics">Basics</h2>


The basic idea is to enter additional information in the very early
state of going multiuser before configuring any network interface.
    <p>

This is done using dialog(1), thus providing a well known user
interface. This way choosing a network environment is quite
comfortable. For details see below.
    <p>

Alternatively you can input on the boot prompt. This is done as
follows: When "lilo" prompts, type e.g. 
    <p>
<pre>
linux NETENV=off
</pre>

This sets up a shell variable "NETENV", containing "off" (this
means for me: I'm attaching my laptop to the LAN in the office). The
kernel starts the init process with "NETENV" as part of its
environment, so does init. So the netenv script can check for "NETENV". 
    <p>
After having set up <kbd>NETENV</kbd>, a corresponding configuration file
located in <kbd>/etc/netenv</kbd> is copied to <kbd>/etc/netenv/netenv</kbd>,
eg. <kbd>/etc/netenv/lulu-off</kbd>, being on a machine named <kbd>lulu</kbd>, having 
entered <kbd>linux NETENV=off</kbd>.
When using a pcmcia network adapter, it is no longer necessary to deal
with <kbd>/etc/pcmcia/network.opts</kbd>. Replace the assignment section in this
file simply with

<pre>. /etc/netenv/netenv
</pre>

<kbd>/etc/netenv/netenv</kbd> is world readable and can be used by user processes for
additional setup tasks, see the <a
href="./netenv.html#Examples">Examples</a> section. 

<h2><a name="Installation">Installation</h2>

Well, it depends. Those of you using the Debian netenv package may
continue reading about <A href="#Configuration">Configuration</A>
    <p>
All the others should untar the <kbd>netenv</kbd> package. It consists
of the shell script called - you guessed it - <kbd>netenv</kbd>,
example configuration files and documentation files. 
    <p>
You should copy the script <kbd>netenv</kbd> to the proper place. This can be
<kbd>/etc/init.d</kbd>, but that depends ... Probably you may want to make a
link, so that netenv is executed when your laptop comes up to run
level 2. There is no need to do anything when the laptop is shut down.
    <p>
Obviously netenv should be run before the network setup starts.
    <p>
On a Debian system this is done by putting <kbd>netenv</kbd> in the
directory <kbd>/etc/rc.boot</kbd>. You probably will find there
<kbd>0setserial</kbd>. You then may copy <kbd>netenv</kbd> to
<kbd>/etc/rc.boot/1netenv</kbd>. 
</pre>
To deal with the pcmcia setup scheme via <kbd>network.opts</kbd> as
mentioned before, you may copy <a href="network.opts">my
network.opts</a> to <kbd>/etc/pcmcia</kbd>.

<h2><a name="Configuration">Configuration</a></h2>

The netenv configuration files are expected in
<kbd>/etc/netenv</kbd>. Being on a machine named "lulu" files named
lulu, lulu-foo, lulu-bar etc. will be looked at.

The naming scheme is as follows:
<pre>
/etc/netenv/&lt;NODE-NAME&gt;-&lt;VALUE-OF-VARIABLE-NETENV&gt;
</pre>

The files in /etc/netenv contain assignments in shell syntax, e.g.

<pre>
IPADDR=123.456.78.9
DOMAIN=buzz.foobar.org
</pre>

Now you really should have a look in the <a
href="./netenv.html#Examples">Examples</a> section ...

<h2><a name="Examples">Examples</h2>

This is of course the most important section.
<p>
I would like to explain two example configurations. My laptop's node
name is <kbd>lulu</kbd>. This laptop is my main machine even at home,
where I use it connected to external CRT, keyboard and mouse.

<h3>Laptop_at_home</h3>

Staying at home means for me to connect to my private network setup as
well as using the laptop with an external CRT.
    <p>
This is the <kbd>netenv</kbd>-file, which I simply call
<kbd>/etc/netenv/lulu</kbd>, thus making it the default:
<pre>
netenv_id=Laptop_at_home_crt_3button_mouse
export PROFILE=30
IPADDR=192.168.123.2
NETMASK=255.255.0.0
NETWORK=192.168.0.0
BROADCAST=192.168.255.255
GATEWAY=192.168.123.1
DOMAIN=rw.sni.de
DNS_1=123.123.12.12
export PRINTER=printer-nana-deskjet
NETENV_SCRIPT=/etc/netenv/netenv_setup
XF86CONFIG_FILE=/etc/X11/XF86Config-crt
</pre>

    You will find this file in the doc-subdirectory.<p>
    <p>
As I hopefully mentioned earlier, this file is sourced by shell
scripts, so shell syntax rules apply. Everthing on a line after a hash
    is comment only.<p>
The line
<pre>
netenv_id=Laptop_at_home_crt_3button_mouse
</pre>
defines the verbose description in netenv's chooser box. Please, <b>do
not use spaces here</b>. You have been warned ...
<pre>
netenv_id=This_string_must_contain_no_blanks_nor_special_characters
</pre>
If the assignment <kbd>netenv_id</kbd> is not found, the entry will be
labeled "unknown". 

    <p>
<pre>PROFILE=30
</pre>
I use this variable for setting up my windowmanager according to the
current location of my laptop. I still use
fvwm95. To have the details look at my <a href="dot.fvwm95rc-cpp">.fvwm95rc-cpp</a>.
This file is precompiled
by means of the variable "PROFILE". This way I can use one source for
different displays and so on, see
<a href="http://www.ssc.com/lg/issue21/fvwm.html">http://www.ssc.com/lg/issue21/fvwm.html</a>

<pre>
IPADDR=192.168.123.2
NETMASK=255.255.0.0
NETWORK=192.168.0.0
BROADCAST=192.168.255.255
GATEWAY=192.168.123.1
DOMAIN=rw.sni.de
DNS_1=123.123.12.12
</pre>

This defines netenv's basic functionality: It sets up my network interface
as well as <kbd>/etc/resolv.conf</kbd>. Look at my remarks on the
<a href="./netenv.html#dns">DNS stuff</a>. As I connect to the net
transparently via an ISDN router, setting GATEWAY is important.
    <p>
Last not least this is the right place to define once and only once
my printing environment:
<pre>
export PRINTER=printer-nana-deskjet
export COLOR_PRINTER=printer-off-color-deskjet
</pre>
Of course I source this in my <kbd>.xsession</kbd>. Look at this
snippet:

<pre>
if [ -r /etc/netenv/netenv ]; then
. /etc/netenv/netenv
fi
</pre>

For the whole story here is my <a href="dot.xsession">.xsession</a> and
my <a href="dot.Xdefaults">.Xdefaults</a>
    <p>

But what is this:

<pre>NETENV_SCRIPT=/etc/netenv/netenv_setup
</pre>

If <kbd>netenv</kbd> finds an executable under this filename, it will
execute it (to be precise: source it). 
    <p>

<b>Beware ! This is run during early stage of going multi user ! No
network setup has been done yet ! It's done as root ! You have been
warned !</b> 
    <p>

So far legal terms and conditions. This is my script:

<pre>

#!/bin/sh
# Simple way to configure the X-Server 
if [ -r $XF86CONFIG_FILE ]; then
    echo $XF86CONFIG_FILE will be used for configuring the X-Server ...
    mv /etc/X11/XF86Config /etc/X11/XF86Config.old
    ln -s $XF86CONFIG_FILE /etc/X11/XF86Config
fi
</pre>

As you can see it depends on a variable XF86CONFIG_FILE. That is why
my netenv configurations file has this line

<pre>
XF86CONFIG_FILE=/etc/X11/XF86Config-crt
</pre> 

Of course there are other ways of switching between different X-server 
setups - hey, this is Linux ! The one I choosed has the disadvantage,
that you have to define the variable XF86CONFIG_FILE in each
netenv-file. So, if you are on the LCD and the Xserver comes up with
the CRT-XF86Config, you know what to change ...

<h3>Laptop_in_the_office</h3>

The <kbd>netenv</kbd>-file is named
<kbd>/etc/netenv/lulu-off</kbd>. Look: 

<pre>
# Networkenvironment: Laptop at office (Network-Interface: Ethernet)
netenv_id=Laptop_at_office
PROFILE=31
IPADDR=123.123.35.134
NETMASK=255.255.255.0
NETWORK=123.123.35.0
BROADCAST=123.123.35.255
GATEWAY=123.123.35.1
DOMAIN=rw.sni.de
DNS_1=123.123.12.12
export PRINTER=printer-off-ps
export COLOR_PRINTER=printer-off-color-deskjet
NETENV_SCRIPT=/etc/netenv/netenv_setup
XF86CONFIG_FILE=/etc/X11/XF86Config-lcd
</pre>

There are no substantial differences. I use the laptop's LCD, the
ethernet card is configured with appropiate values, the printing
environment changes.

<h2><a name="otherstuff">Other stuff</h2>


<h3>Special case: Setting up a new environment</h3>

Choosing "new" in the dialog menue (or entering linux NETENV=new on
the lilo-prompt) will force netenv to ask for user input describing 
the current environment. The input can be stored for later reuse. You
will be prompted for:

    <ul>
      <li> the current IP-address
      <li> the netmask of the current subnet
      <li> the IP-Address of the current network
      <li> the broadcast-Address of the current network
      <li> the Gateway-Address of the current network
      <li> the current Profile's value
    </ul>

 


<h3><a name="dns">DNS</h3>

By default netenv will <b>NOT</b> deal with your DNS configuration.
For me the mechanism implemented by
David Hinds (Skript network, part of the pcmcia-package) is quite
sufficient. To understand what's going on have a look at the source:

<pre>
        # Update DNS stuff
        cp /etc/resolv.conf /etc/resolv.new
        echo "# $DEVICE begin" >> /etc/resolv.new
        test "$DOMAIN" && echo "domain $DOMAIN" >> /etc/resolv.new
        if [ "$DNSSRVS $DNS_1 $DNS_2 $DNS_3" != "   " ] ; then
            for DNS in $DNSSRVS $DNS_1 $DNS_2 $DNS_3 ; do
                echo "nameserver $DNS" >> /etc/resolv.new
            done
        fi
        echo "# $DEVICE end" >> /etc/resolv.new
        mv /etc/resolv.new /etc/resolv.conf
</pre>

The file <kbd>/etc/resolv.conf</kbd> is copied to a temporary file. If 
any of the variables <kbd>DOMAIN, DNSSRVS, DNS_1, DNS_2</kbd> or
<kbd>DNS_3</kbd> have a value not equal null, the appropiate commands
will be added. This new section is starts with e.g. <kbd># eth0
begin</kbd> and ends with e.g. <kbd># eth0 end</kbd>. This is needed
when stopping the pcmcia services to remove the section. Your
<kbd>/etc/resolv.conf</kbd> will then be in the original state.

<h3>Networking via parallel port</h3>

If you want to connect your laptop to your home tower, look at the
attached script <a href="plip">plip</a>. The appropiate
<kbd>lulu-plip</kbd> will read like:

<pre>
# Networkenvironment: Tower at home (Network-Interface: Plip)
export PROFILE=10
PLIP_START=yes
PLIP_IPADDR=200.0.0.1
PLIP_PARTNER=lulu
PRINTER=home-deskjet
</pre>

To be able to do so, plip MUST be called after <kbd>kerneld</kbd> is started !
(plip is available only as module, eventually the module lp has been
inserted already, see the script for further details).

<h2>Conclusion</h2>

Hopefully netenv will be helpful. If you have any questions or
comments, mail me at <a href="bav@rw.sni.de">bav@rw.sni.de</a>. 


      <hr>
      <address><a href="mailto:bav@rw.sni.de">Gerd Bavendiek</a></address>
<!-- Created: Mon Apr 13 21:25:07 CEST 1998 -->
<!-- hhmts start -->
Last modified: Wed Jun 17 21:48:14 CEST 1998
<!-- hhmts end -->
  </body>
</html>