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 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Netenv 0.94 - Using a laptop in different network environments</title>
</head>
<body>
<h2><a name="top">Do you use your laptop in different network environments ?</a></h2>
At home ? In the office ? At a customers site ?
<p>
If yes, the small package <i>netenv</i> 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>
<I>Netenv</I> 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, RedHat
and SuSe). If you have a Network Interface Card (often simpy
called NIC) onboard, you can use the same mechanism.
<p>
Have a look at <i>netenv</i>'s chooser box:
<p>
<img src="netenv-chooser-box.png">
<p>
Besides the basic functionality of configuring the NIC, the <i>netenv</i> 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 wheel mouse.
<p>
<li>Setting up DNS
<p>
You create the appropriate /etc/resolv.conf.
<p>
<li>Printing Environment
<p>
Assigning a proper value for e.g. PRINTER defines a default printer.
<p>
<li>Editing your Netscape preferences file
<p>
So it's possible to avoid network timeouts, when working not
connected to the net and viewing only local files.
<p>
<li>Configuring Fetchmail
<p>
Having a permanent connection to my mailserver I use
<i>netenv</i> to call fetchmail as a daemon which fetches mail
periodically.
<p>
<li>Linking /dev/pilot
<p>
If you use a palm, you may link /dev/pilot to a serial
device when a cradle is connected and to the IRDA-port if
you are on the road.
</ul>
<p>
<I>Netenv</I> is available prepackaged for Debian and Redhat Linux as
well as tarball. Mandrake- and SuSe-Users may use the RedHat-RPM.
<i>netenv</i> depends on dialog(1) resp. gdialog (which comes
with the mentionend distributions).
<p>
A word to all gurus: In this docu I try to explain things with Linux
novices in mind, so be patient.
<hr>
<p>
<a name="toc">Table of Contents</a>
<p>
<a href="#top">What does <i>netenv</i> do ?</a>
<p>
<a href="#download">Where to get <i>netenv</i> ?</a>
<p>
<a href="#installation">How to install</a>
<p>
<a href="#basics">Basics</a>
<p>
<a href="#firsttimeconfig">First time configuration</a>
<p>
<a href="#config">Configuration</a>
<p>
<a href="#examples">Examples</a>
<p>
<a href="#dns">Remarks at DNS</a>
<p>
<a href="#suse">Remarks for SuSe 7.3 Users</a>
<p>
<a href="#alternatives"><i>netenv</i> alternatives</a>
<p>
<a href="#final">Conclusion</a>
<p>
<hr>
<h2><a name="download">Where to get <i>netenv</i> ?</h2>
<I>Netenv</I> has a homepage at Sourceforge:
<a href="http://netenv.sourceforge.net">http://netenv.sourceforge.net</a>
<p>
But you may know this already ...
<p>
You will find there the tar-file as well as the RedHat-RPM. The latter
should be useable in Mandrake and Suse too.
<p>
Debian-User
<p>
<I>Netenv</I> has been available for Debian quite a while. Look at
<a href="http://www.debian.org/distrib/packages">http://www.debian.org/distrib/packages</a>.
<p>
<a href="#toc">Back to Table of Contents</a>
<h2><a name="installation">How to Install</h2>
It depends ... For all distributions, which use RPM, do as root e.g.:
<pre>
rpm -i netenv-0.94-1.i386.rpm
</pre>
In Debian e.g.:
<pre>
dpkg -i netenv-0.92-2.i386.deb
</pre>
In all other cases:
<pre>
tar xvf netenv-0.94-2.tar
</pre>
This installs a shellscript called <kbd>netenv</kbd>,
a little helper utility trpnc, configuration examples and these docs.
Depending on the distribution a little handwork may be necessary.
<h3>RedHat</h3>
<em>I don't know anything about current RedHat versions. Therefore the
following hints are probably out of date. You may find useful hints in
the section <a href="#how-to-use-tar">How to use the tar-file</a></em>
<p>
The <i>netenv</i>-RPM has been packaged under RedHat 6.1. So it should
be possible to install in all distributions using RPM.
<p>
The postinstall-script puts
<ul>
<li>a call to <i>netenv</i> in <kbd>/etc/rc.d/rc.sysinit</kbd>
<li>and cares for the integration in the NIC's configuration
</ul>
<kbd>/etc/rc.d/rc.sysinit</kbd> now looks like this:
<pre>
lulu:/home/bav> tail -2 /etc/rc.d/rc.sysinit
# Added by package netenv on 06.03.2000 19:53:10
/usr/sbin/netenv
</pre>
Additionally <kbd>/etc/sysconfig/network-scripts/ifcfg-eth0</kbd> will
be changed. Just after first installing Redhat this file looks like:
<pre>
lulu:/etc/sysconfig/network-scripts>>> cat ifcfg-eth0
DEVICE=eth0
BROADCAST=192.168.200.255
IPADDR=192.168.200.201
NETMASK=255.255.255.0
NETWORK=192.168.200.0
ONBOOT=yes
</pre>
Installing <i>netenv</i> adds two lines:
<pre>
lulu:/etc/sysconfig/network-scripts>>> tail -3 ifcfg-eth0
ONBOOT=yes
# Added by package netenv on 06.03.2000 19:53:10
if [ -r /tmp/netenv ]; then . /tmp/netenv; fi
</pre>
<h3>SuSe</h3>
With Suse 8.x a couple of changes in system boot and network
configuration were introduced. The current procedure assumes
Suse 8.1, but it should work with 8.0 as well. For older versions
see the next paragraph.
<h4><a name="suse-8-1">SuSe 8.1</h4>
The postinstall-script adds two lines to /etc/init.d/boot.local:
<pre>lulu:/etc/init.d> tail -3 boot.local
#
# Added by package netenv on 06.12.2002 10:45:10
/usr/sbin/netenv
</pre>
This way netenv is called during boot. netenv assumes the NIC to be
configured is eth0, so the line
<pre>if [ -r /tmp/netenv ]; then . /tmp/netenv; fi
</pre>
is appended to the file <pre>/etc/sysconfig/network/ifcfg-eth0</pre>
It then looks like:
<pre>lulu:/etc/sysconfig/network> cat ifcfg-eth0
FIREWALL="YES"
BOOTPROTO='static'
BROADCAST='nn.nn.nn.nn'
IPADDR='nn.nn.nn.nn'
NETMASK='nn.nn.nn.nn'
NETWORK='nn.nn.nn.nn'
REMOTE_IPADDR=''
STARTMODE='onboot'
UNIQUE='oxTw.yHaVEFCrUXE'
WIRELESS='no'
if [ -r /tmp/netenv ]; then . /tmp/netenv; fi
</pre>
The entries IPADDR, NETMASK etc. spring from the basic installation.
There is no need to delete them as they are superseded by the
assignments in /tmp/netenv. In this example I assume that the NIC is
not a PCMCIA-NIC. Otherwise the line
<pre>STARTMODE='onboot'</pre>
must read
<pre>STARTMODE='hotplug'</pre>
<h4>SuSe 7.3</h4>
The postinstall-script adds two lines to /etc/rc.d/boot.local:
<pre>
mweb@guru:/etc/rc.d > tail -3 boot.local
# before we're going to the first run level.
#
# Added by package netenv on 06.02.2001 20:28:10
/usr/sbin/netenv
</pre>
For PCMCIA-Cards an entry in /etc/pcmcia/network.opts
is done:
<pre>
mweb@guru:/etc/pcmcia > tail -2 network.opts
esac
# Added by package netenv on 06.02.2001 20:28:10
if [ -r /tmp/netenv ]; then . /tmp/netenv; fi
</pre>
If the laptop has a builtin NIC and PCMCIA must not be used, you may
override the values defined by YAST as follows:
<pre>
mweb@guru:/etc/rc.d > head -16 network
#! /bin/sh
# Copyright (c) 1996 SuSE GmbH Nuernberg, Germany. All rights reserved.
#
# Author: Florian La Roche <florian@suse.de>, 1996
# Werner Fink <werner@suse.de>, 1996
# Burchard Steinbild <bs@suse.de>, 1996
# Rolf Haberrecker <rolf@suse.de>, 1998
# Werner Fink <werner@suse.de> (based on a patch of Andries Brouwer) 1999
#
# /sbin/init.d/network
#
. /etc/rc.status
. /etc/rc.config
if [ -r /tmp/netenv ] ; then . /tmp/netenv; fi
</pre>
<h3>Debian</h3>
The Debian-Package netenv is currently worked on. As far as I know,
PCMCIA-NIC's can be used without further configuration.
<p>
Onboard-NIC's though need a changed /etc/network/interfaces. You can
do this using netenv procedures, see the example script
netenv_setup_debian_example. If you do nothing, your NIC will be
configured like it was during system installation regardless what you
choose with netenv.
<h3>Mandrake</h3>
Mandrake 9 users reported that the splash-screen had to be disabled
(disable vga=nnn in /etc/lilo.conf) in order to be able to input
something during boot. Furthermore the cdialog seems not to be stable.
Problems could be solved only after using the SuSE dialog binary instead.
<h3><a name="how-to-use-tar">How to use the tar-file</h3>
These are the necessary steps:
<pre>
tar zxvf netenv-0.94-2.tar.gz
cd netenv-0.94-2
make
make install # must be user root from now on !
make config
</pre>
Depending on the distribution the last step <kbd>make config</kbd> may
eventually have to be done manually.
<p>
netenv must be called <b>before</b> the normal network- or PCMCIA-start.
Check for <kbd>/etc/init.d/boot.local</kbd> or the equivalent. See the
<a href="#suse-8-1">SuSE 8.1</a> paragraph for further details.
<p>
After you have ensured that netenv is called during boot, the
configuration data must be read by the network scripts. Modern
distributions seem to use <kbd>ifup</kbd> to start a preconfigured net
interface. Then the <a href="#suse-8-1">SuSE 8.1</a> paragraph should
contain the details.
<p>
A common issue is to confuse eth0 and eth1 if there is an onboard NIC
and a PCMCIA NIC. Chances are that eth0 is the onboard and eth1 is the
PCMCIA NIC. Verify with <kbd> dmesg | grep eth</kbd> and <kbd>lspci</kbd>.
<p>
Netenv checks for eth1, but depending on the configuration at the time
of installation this cannot be waterproof.
<p>
<a href="#toc">Back to Table of Contents</a>
<h2><a name="basics">Basics</h2>
The basic idea is to enter information about the current location of
the laptop in a very early phase of booting. This happens before
configuring any network interface.
<p>
This is done using dialog(1), a simple menu interface, well known to
most users. Booting is continued after the user has done his
selection. For a default environment this may be as simple as just
pressing RETURN.
<p>
If "lilo" is used as bootmanager, you may alternatively input after
the lilo-prompt:
<p>
<pre>
linux NETENV=office
</pre>
This defines a shell variable "NETENV" with the value "office". This
means for me: I am with my laptop named lulu in the office. The file
containing the values for IP-address etc. is
/etc/netenv/lulu-lavie. The Linuxkernel starts the init-process
with the variable NETENV as part of its environment. The same does
init with the so called rc-scripts.
<p>
The netenv-script tests for NETENV beeing defined. If it is, netenv
carries out further actions without popping up the manu.
<p>
After having selected the current environment, netenv copies the
actual file to /tmp/netenv.
<p>
This file has modes 644, so being readable by any user for further
user dependent configuration tasks.
<p>
<a href="#toc">Back to Table of Contents</a>
<h2><a name="firsttimeconfig">First time configuration</a></h2>
After installing the user root should call netenv. Do simply:
<pre>
netenv
</pre>
This will fire up a menu with only one choice:
<pre>
new Set_up_new_environment
</pre>
These parameters will be asked for:
<pre>
Enter the current IP-Address or the keyword dhcp ...
Enter the netmask of the current subnet ...
Enter the IP-Address of the current network ...
Enter the Broadcast-Address of the current network ...
Enter the Gateway-Address of the current network ...
Enter the IP-address of the current nameserver ...
</pre>
If in a network with DHCP-Server, input dhcp instead of an
IP-Address. Then a /tmp/netenv is generated containing only
<pre>
BOOTPROTO='dhcp'
STARTMODE='hotplug'
</pre>
All other values will be derived according to the DHCP-configuration.
If the NIC is onboard, netenv should have written
<pre>
STARTMODE='onboot'
</pre>
In case of a static IP-address there will be a default entry for the
other items, which will be sufficient in many situations.
<p>
Finally you will be asked if you want to save this configuration for
further use:
<pre>
Do you want to save this configuration ?
</pre>
Please <b>do not use spaces</b> in this name !
<p>
Depending on the Distribution netenv offers to restart the network and
to activate the changes this way.
<p>
If this is not applicable, take out your PCMCIA-NIC (if it's PCMCIA
you use ...) and stick it in again (cardmgr will ring the bell). The
same result may be achieved doing
<pre>
/etc/init.d/pcmcia restart
</pre>
In any case cardmanager from the PCMCIA-package should configure the interface.
<p>
Ping your gateway-address and you will know !
<p>
Didn't work ? Is the link-LED green ? Check the output of
<pre>ifconfig eth0</pre>
<p>
The procedure just described may be also be used, wenn you want to
switch from one network environment to another while your laptop stays
up and running. There is no need to reboot - it's Linux ...
<p>
Those, who use a NIC onboard instead of a PCMCIA-NIC have to restart their
network.
<p>
In RedHat or SuSE e.g.:
<pre>
/etc/init.d/network restart
</pre>
Netenv does this according to your input.
<p>
<a href="#toc">Back to Table of Contents</a>
<h2><a name="config">Configuration</a></h2>
<I>Netenv</I> is configured using files. You will find them in
<kbd>/etc/netenv</kbd>. On a laptop named "lulu" files
lulu, lulu-foo, lulu-bar etc. will be used.
So the naming scheme is as follows:
<pre>
/etc/netenv/<NODE-NAME>-<VALUE-OF-VARIABLE-NETENV>
</pre>
The filename identical to the laptop's hostname is the first item in the
selection menu. You simply may press RETURN and booting is continued.
You should put the most frequently used environment into this file.
<p>
All files contain assignments in shell syntax, e.g.
<pre>
netenv_id=At_Home_LCD_WheelMouse_pcmcia
...
IPADDR=123.456.78.9
...
NETSCAPE_PROXY_TYPE=2
</pre>
Spaces will cause trouble. For a well configured NIC you will have to
define at least
<pre>
IPADDR
NETMASK
NETWORK
BROADCAST
</pre>
Depending on the situation you may additionally have to define
<pre>
GATEWAY
DNS_1
</pre>
<b>You may stick any variableassignment into the file - as long as everything
is syntactically right.</b>
There is something special with an assignment like
<pre>
NETENV_SCRIPT=/etc/netenv/netenv_setup
</pre>
If the file pointed to is readable, netenv will
execute this file (to be precise: it will source it) after the current
network environment has been choosen.
<p>
<b>Pay Attention ! This will be in a very early stage of boot. No
network will be active ! NETENV_SCRIPT will be executed with root privileges !</b>
<p>
With the help of this script you may do quite useful things. More on
this in the <a href="#examples">example section</a>.
<p>
<h3>Expert Mode</h3>
If you choose CANCEL in the netenv-dialog-box, you may enter a
shell. After quitting this, the chooserbox pops up again.
<b>Security hints:</b>
The directory /etc/netenv and the files in it must be writeable only
for root. netenv does some basic checks for this.
<p>
<a href="#toc">Back to Table of Contents</a>
<h2><a name="examples">Examples</a></h2>
Of course this is the most important part of this documentation ...
<p>
The examples are described step by step. So please read them one after
the other !
<h3>StandAlone_Touchpad</h3>
<pre>
lulu:/etc/netenv>>> cat lulu-touch-pad
netenv_id=StandAlone_Touchpad_no_eth
STARTMODE=manual
export XF86CONFIG_FILE=/etc/X11/XF86Config-4-lcd-touch
NETENV_SCRIPT=/etc/netenv/netenv_setup
# This may be used to edit ~/.netscape/preferences.js
NETSCAPE_PROXY_TYPE=3
</pre>
I use this one when my laptop has no network connection.
<p>
The value of the variable netenv_id (as I said earlier: Please <b>without</b>
spaces) will be used as decription in the chooser box.
<p>
There is no IP-address defined. By setting STARTMODE=manual there will
no NIC be configured during boot. I assign
NETENV_SCRIPT=/etc/netenv/netenv_setup. This is a file
containing shell commands. It is attached to this documentation <a href="netenv_setup">here</a>.
<p>
This sample is written in a simple manner to get you started. Relevant
code section here is:
<pre>
lulu:/etc/netenv>>> cat netenv_setup
...
# 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
fi
...
</pre>
As I defined XF86CONFIG_FILE the code creates a link. Right now it is
pointing to the configuration file, which I created for my laptop with
touchpad.
<p>
Typically netenv_setup does everything the root user is needed for and
the whole system is concerned with. Personal settings are done via
.xinitrc. Here is an example:
<p>
In my private configuration I use NETSCAPE_PROXY_TYPE:
<pre>
lulu:/home/bav> cat .xinitrc
#!/bin/sh
...
if [ -r /tmp/netenv ]; then
. /tmp/netenv
fi
if [ -n "$NETSCAPE_PROXY_TYPE" ]; then
~/tools/edit-ns-preferences $NETSCAPE_PROXY_TYPE
fi
...
</pre>
You will find the script edit-ns-preferences in the
<i>netenv</i>-documentation. It will avoid nasty network-timeouts, when
starting the browser.
<h3>In_the_Office</h3>
<pre>
lulu:/etc/netenv>>> cat lulu-lavie
# Networkenvironment: netask
netenv_id="lavie_pcmcia_dhcp"
export BOOTPROTO=dhcp
export STARTMODE=hotplug
export PRINTER=cc_hp
NETSCAPE_PROXY_TYPE=2
FETCHMAIL_POLL_INTERVALL=900
</pre>
In the office I get my network configuration from a
DHCP-Server. STARTMODE=hotplug is set, because my laptop has no onboard-NIC
and therefore the PCMCIA-NIC has to be used.
<p>
PRINTER=cc_hp sets the defaultprinter to the printer in the office. NETSCAPE_PROXY_TYPE=2
activates automatic proxyconfiguration in Netscape.
<p>
When I am in the office, mail shall be fetched periodically. For this
I use FETCHMAIL_POLL_INTERVALL. The following snippet from my
<kbd>~/.xinitrc</kbd> starts fetchmail as daemon, which will became active every 15 min
and carry out things defined in <kbd>~/.fetchmailrc</kbd>:
<pre>
if [ -n "$FETCHMAIL_POLL_INTERVALL" ]; then
fetchmail -d $FETCHMAIL_POLL_INTERVALL
fi
</pre>
<h3>Laptop_at_home</h3>
At home I use my default configuration file. As I work here most of
the time the filename equals my laptops node name. So I just have to
press return in the netenv-chooser-box:
<pre>
netenv_id=At_Home_Docking_LCD_WheelMouse_onboard_VPN
IPADDR=nnn.nn.nnn.nnn
NETMASK=nnn.nnn.nnn.nnn
NETWORK=nnn.nn.nnn.nnn
BROADCAST=nnn.nn.nnn.nnn
GATEWAY=nnn.nn.nnn.nnn
SEARCH=foo.bar.com
DNS_1=nnn.nn.nn.nn
DNS_2=nnn.nn.nn.nn
FETCHMAIL_POLL_INTERVALL=900
# If the variable NETENV_SCRIPT points to an readable file,
# it will be run when netenv is executed
NETENV_SCRIPT=/etc/netenv/netenv_setup
ICEWM_INCLUDE_FILE=home
# This defines my CRT with 1024x768 and a wheelmouse
XF86CONFIG_FILE=/etc/X11/XF86Config-4-lcd-wheel
# This may be used to edit ~/.netscape/preferences.js
NETSCAPE_PROXY_TYPE=2
# This may be used to edit ~/.opera/opera6.ini
OPERA_PROXY_FILE=proxy-fsc.ini
# NIC is in the docking unit - like it were onboard
STARTMODE='onboot'
</pre>
Relevant portion from my netenv_setup is this:
<pre>
lulu:/etc/netenv>>> cat netenv_setup
...
PROFILE=$1
...
if [ "$PROFILE" = "default" ]; then
print_action linking /dev/pilot
rm -f /dev/pilot; ln -s /dev/ttyS0 /dev/pilot
print_status
print_action calling ptal-init start
/usr/sbin/ptal-init start
print_status
else
# When there is no docking station, start irattach appropiately and
# link /dev/pilot to ircomm0.
print_action running irattach
/usr/sbin/irattach /dev/ttyS3 -s
print_status
print_status linking /dev/pilot
rm -f /dev/pilot; ln -s /dev/ircomm0 /dev/pilot
print_status
fi
...
</pre>
netenv_setup is called with the parameter PROFILE, which equals
"default" here (in all other cases it is the filename of the
descriptionfile minus hostname portion).
<p>
At home I use a cradle for my palm. So /dev/pilot must point to the
appropriate serial device. Additionally the software for my HP
Officejet has to be started. In all other environments the palm can be
reached only via IRDA. ptal must not be started then.
<p>
At home my laptop is in a docking-unit. This has a NIC. In order to use
this NIC
<pre>STARTMODE='onboot'</pre>
has to be set.
<h3>At_Customer_Foobar</h3>
Earlier versions of libc made it possible for a non privileged user
to make kind of private /etc/hosts by setting the environment variable
HOSTALIASES. Due to security issues this is no longer possible in
recent versions of libc.
<p>
If you don't like to edit your /etc/hosts manually, the following idea may help.
For me it is useful, as I find computers with identical names but
different IP-addresses in different environments.
<p>
I put marks in my /etc/hosts like this:
<pre>
lulu:/home/bav> cat /etc/hosts
...
# netenv hosts begin
# netenv hosts end
...
</pre>
Now I define nodes with their IP-addresses, which I want to connect to
in the current environments:
<pre>
NETENV_HOST_ENTRIES="192.168.10.11 abba:192.168.10.12 bebe:192.168.10.3 alfa-sw:\
192.168.10.4 beta-sw:192.168.10.13 coca:192.168.10.14 cola"
</pre>
This code in my /etc/netenv/netenv_setup will care for editing /etc/hosts
after choosing the environment:
<pre>
if [ -n "$NETENV_HOST_ENTRIES" ]; then
if egrep '^# netenv hosts begin$' /etc/hosts > /dev/null 2>&1; then
(
awk 'NR==1,/^# netenv hosts begin$/' /etc/hosts
echo $NETENV_HOST_ENTRIES | awk -F'\:' '{ for ( j=1; j<=NF; j++ ) print $j }'
awk '/^# netenv hosts end$/,/*/' /etc/hosts
) > /etc/hosts.netenv
mv /etc/hosts.netenv /etc/hosts
chmod 644 /etc/hosts
echo netenv_setup: /etc/hosts was modified ...
fi
else
if egrep '^# netenv hosts begin$' /etc/hosts > /dev/null 2>&1; then
(
awk 'NR==1,/^# netenv hosts begin$/' /etc/hosts
awk '/^# netenv hosts end$/,/*/' /etc/hosts
) > /etc/hosts.netenv
mv /etc/hosts.netenv /etc/hosts
chmod 644 /etc/hosts
echo netenv_setup: /etc/hosts was cleaned up ...
fi
fi
</pre>
Now /etc/hosts looks like this:
<pre>
...
# netenv hosts begin
192.168.10.11 abba
192.168.10.12 bebe
192.168.10.3 alfa-sw
192.168.10.4 beta-sw
192.168.10.13 coca
192.168.10.14 cola
# netenv hosts end
...
</pre>
All these nodes are trusted, so I use the mechanism in my <kbd>~/.xinitrc</kbd>
and call xhost appropriate:
<pre>
XHOST_PLUS_LISTE=`awk '/^# netenv hosts begin$/,/^# netenv hosts end$/' /etc/hosts | awk '!/^#/ {print $2}'`
xhost $XHOST_PLUS_LISTE
</pre>
xhost gives me:
<pre>
lulu:/home/bav> xhost
access control enabled, only authorized clients can connect
INET:cola
INET:coca
INET:beta-sw
INET:alfa-sw
INET:bebe
INET:abba
</pre>
<p>
<a href="#toc">Back to Table of Contents</a>
<h2><a name="dns">Remarks concerning DNS</h2>
<I>Netenv</I> does <b>no</b> DNS configuration. Unfortunately there
are a couple of differences in this area looking at the distributions.
<p>
I always felt the mechanism, which David Hinds implemented in his
PCMCIA-package, being sufficient (Script network). This snippet
shows what is happening there:
<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
one of the variables <kbd>DOMAIN, DNSSRVS, DNS_1,
DNS_2</kbd> or <kbd>DNS_3</kbd> are defined, appropiate commands are
issued. This new section starts e.g. with <kbd># eth0 begin</kbd> and
ends with e.g <kbd># eth0 end</kbd>. These makes are used, to clear
the section, when PCMCIA is shut down. Afterwards
<kbd>/etc/resolv.conf</kbd> will be in the original state.
<p>
So defining e.g. DNS_1 makes this thing work.
<p>
If you want to use <i>netenv</i> for this task, you may put following code
in /etc/netenv/netenv_setup:
<pre>
if [ ! -z "$DNS_1" ]; then
(
echo "# resolv.conf autogenerated by netenv "`date`
if [ ! -z "$DOMAIN" ]; then echo domain $DOMAIN; fi
if [ ! -z "$SEARCH" ]; then echo search $SEARCH; fi
echo nameserver $DNS_1
if [ ! -z "$DNS_2" ]; then echo nameserver $DNS_2; fi
) > /etc/resolv.conf
chmod 644 /etc/resolv.conf
echo netenv: /etc/resolv.conf was set up ...
fi
</pre>
<p>
<a href="#toc">Back to Table of Contents</a>
<h2><a name="suse">Remarks for SuSe 7.3 Users</h2>
If you have an onboard-NIC (so that there is no need to use a
PCMCIA-NIC), you have to override the standard entry in /etc/rc.config.
You can do this by setting IFCONFIG_0:
<pre>
IFCONFIG_0="172.25.64.130 broadcast 172.25.64.255 netmask 255.255.255.0 up"
</pre>
If you want to use DHCP, the entry must read
<pre>
IFCONFIG_0="dhcpclient"
</pre>
Using netenv you may do this as follows:
<p>
At first the appropriate profile:
<pre>
elli:/etc/netenv> cat elli-ht
# Networkenvironment: DHCP
export USE_DHCP=yes
NETENV_SCRIPT=/etc/netenv/netenv_setup
</pre>
Furthermore you need a netenv_setup script with at least following
contents:
<pre>
elli:/etc/netenv> cat netenv_setup
edit_rc_config()
{
if [ ! -r /etc/rc.config ]; then
echo No /etc/rc.config, probably not a SuSE-System, giving up ...
return 1
fi
VARIABLE_TO_CHANGE=$1
shift
echo ${VARIABLE_TO_CHANGE}'="'$*'"' > /tmp/.netenv.tmp.$$
LINE=`awk '/^'$VARIABLE_TO_CHANGE'=/ {LINE=NR} END {print LINE}' /etc/rc.config`
awk -v LINE=$LINE 'NR /tmp/.rc.config.netenv
cat /tmp/.netenv.tmp.$$ >> /tmp/.rc.config.netenv
awk -v LINE=$LINE 'NR>LINE' /etc/rc.config >> /tmp/.rc.config.netenv
cat /tmp/.rc.config.netenv > /etc/rc.config
rm -f /tmp/.rc.config.netenv /tmp/.netenv.tmp.$$
echo netenv_setup: rc.config edited, Variable $VARIABLE_TO_CHANGE set to $*
}
if [ "$USE_DHCP" = yes ]; then
edit_rc_config IFCONFIG_0 dhcpclient
else
edit_rc_config IFCONFIG_0 "$IPADDR broadcast $BROADCAST netmask $NETMASK up"
fi
</pre>
<p>
SuSe uses the files /etc/route.conf for describing static routing. The
default-route looks like this:
<pre>
default 172.246.2.1
</pre>
Using the example where netenv edits /etc/hosts you may use e.g.:
<pre>
if grep SuSE /etc/issue 1>/dev/null; then
if [ ! -z "$GATEWAY" ]; then
(
echo "# route.conf autogenerated by netenv "`date`
echo default $GATEWAY 0.0.0.0 eth0
) > /etc/route.conf
echo netenv_setup: /etc/route.conf was modified ...
fi
fi
</pre>
<a href="#toc">Back to Table of Contents</a>
<h2><a name="alternatives"><i>netenv</i> Alternatives</h2>
As frequently in Linux there are other choices. Read
<a href="http://tuxmobil.org/Mobile-Guide.db/Mobile-Guide.html">Linux on the
Road - A Guide for Laptops and Mobile Devices</a> by Werner Heuser to
find alternative solutions.
<p>
Those I had a closer look at, try to find out the network environment by
sending arp requests. SuSe recently came up with System Configuration
Profile Management scpm, which is quite powerful but lacks an user
interface during boot which I feel to be important.
<p>
<a href="#toc">Back to Table of Contents</a>
<h2><a name="final">Conclusion</h2>
I hope <i>netenv</i> will be useful for you. Do not hesitate to send
questions and comments to <a href="mailto:bav@epost.de">bav@epost.de</a>.
<p>
<a href="#toc">Back to Table of Contents</a>
<hr>
<address><a href="mailto:bav@epost.de">Gerd Bavendiek</a></address>
<!-- Created: Mon Apr 13 21:25:07 CEST 1998 -->
<!-- hhmts start -->
Last modified: Tue Apr 1 20:55:37 CEST 2003
<!-- hhmts end -->
</body>
</html>
|