slitaz-doc-wiki-data view pages/en/guides/network-script.txt @ rev 7

Add pages/en folder.
author Christopher Rogers <slaxemulator@gmail.com>
date Sat Feb 26 12:17:18 2011 +0000 (2011-02-26)
parents
children
line source
1 ====== Secrets of /etc/init.d/network.sh ======
3 ===== Introduction =====
5 SliTaz launches the /etc/init.d/network.sh at startup to initialize the network. It configures the hostname, loopback interface, and internet connection.
7 It's also possible to call the script when SliTaz is started, and use it to open or close internet connections. For example netbox and any software linking get-wifi-firmware (get-ipw2100-firmware, get-b43-firmware...) use it.
9 ===== Usage =====
11 By default, /etc/init.d/network.sh uses /etc/network.conf as the conf file. Parameters written in that file are made for the default network connection.
13 To start the default connection, as when booting:
15 <code>
16 # /etc/init.d/network.sh start
17 </code>
19 The start arg should be used only at boot. To stop the connection:
21 <code>
22 # /etc/init.d/network.sh stop
23 </code>
25 To stop and restart:
27 <code>
28 # /etc/init.d/network.sh restart
29 </code>
31 But, most interestingly, is that ///etc/init.d/network.sh// may also use another config file. It's useful if you're using a laptop, as you can configure multiple connections for multiple access points.
33 For example, we can create a directory /etc/network, containing some config files, named:
35 * Home, for home, using an ethernet connection and a static ip.
36 * Desktop, for the desktop, with a wep encryption, and a static ip.
37 * Univ, wifi without encryption, and with dhcp.
39 Now to get connected at Home, later at a Desktop and finally at Univ, before stopping connection, we only have to:
41 <code>
42 # /etc/init.d/network.sh restart /etc/network/Home
43 # /etc/init.d/network.sh restart /etc/network/Desktop
44 # /etc/init.d/network.sh restart /etc/network/Univ
45 # /etc/init.d/network.sh stop
46 </code>
48 ===== Sudo =====
50 Since /etc/init.d/network.sh/ can only be used by root, if you want a normal user to use it, you should install sudo:
52 <code>
53 # tazpkg get-install sudo
54 </code>
56 And then configure it:
58 <code>
59 # visudo
60 </code>
62 For user tux, which must use network.sh from every host; without a password you should add:
64 <file>
65 tux ALL=NOPASSWD: /etc/init.d/network.sh,
66 </file>
68 For user tortux, which may only get connected from localhost, and which should use a password each time, you should add:
70 <file>
71 tortux my_hostname=PASSWD: /etc/init.d/network.sh,
72 </file>
74 If you forgot your hostname, just run:
76 <code>
77 $ cat /etc/hostname
78 </code>
80 Here is some help to use visudo:
82 * i insertion mode (to write).
83 * Escape exit insertion mode.
84 * :wq record and quit.
85 * :q! quit without recording.
87 ===== Openbox =====
89 All this is not that really user friendly...
91 That's why I'll give you a perfect treat: A way to integrate all this in an openbox menu! Create a script /usr/lib/openbox/network-menu.sh, and add this to it:
93 <code bash>
94 #!/bin/sh
95 #
96 # openbox pipe menu to start network connections
97 # (This script is only useful if sudo is installed, and correctly configured)
99 echo ''
101 # for default file:
102 echo ''
103 echo ''
104 echo 'sudo /etc/init.d/network.sh restart'
105 echo ''
107 # for others files:
108 for file in $(ls /etc/network/)
109 do
110 echo -e ""
111 echo ''
112 echo "sudo /etc/init.d/network.sh restart /etc/network/$file"
113 echo ''
114 done
116 # To stop connections:
117 echo ''
118 echo ''
119 echo 'sudo /etc/init.d/network.sh stop'
120 echo ''
122 echo ''
123 </code>
125 Make it executable:
127 <code sh>
128 # chmod +x /usr/lib/openbox/network-menu.sh
129 </code>
131 And now you only have to add these lines in //~/.config/openbox/menu.xml//:
133 <file>
134 menu id="network-menu" label="Network"
135 execute="/usr/lib/openbox/network-menu.sh" />
136 </file>
138 Then reconfigure openbox:
140 <code>
141 $ openbox --reconfigure
142 </code>
144 Enjoy!
146 ----
147 \\
148 ^ Page Review Section ^^
149 |Quality| Good |
150 |Review| Minor Updates |
151 |Priority| Medium |
152 |Problems| add a [[http://forum.slitaz.org|forum post link]]|
153 |::: | OR add a [[http://labs.slitaz.org/issues |lab issue tracker link ]]|
154 |How to Improve| Suggest briefly|
155 |::: | |
157 \\
158 ----