source: chapter07/ethnet.xml@ 8e0b0f3

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 6.0 6.1 6.1.1 6.3 6.4 6.5 6.6 6.7 6.8 7.0 7.1 7.2 7.3 7.4 7.5 7.5-systemd 7.6 7.6-systemd 7.7 7.7-systemd 7.8 7.8-systemd 7.9 7.9-systemd 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk v3_0 v3_1 v3_2 v3_3 v4_0 v4_1 v5_0 v5_1 v5_1_1 xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 8e0b0f3 was 3229c6b, checked in by Gerard Beekmans <gerard@…>, 23 years ago

Changed literallayout's to screen's

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@771 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 4.6 KB
Line 
1<sect1 id="ch07-ethnet">
2<title>Creating the /etc/init.d/ethnet script</title>
3
4<para>
5This section only applies if a user is going to configure a network card.
6If not, this section can be skipped.
7</para>
8
9<para>
10A new file <filename>/etc/init.d/ethnet</filename> is created containing the
11following:
12</para>
13
14<para>
15<screen>
16<userinput>cat &gt; /etc/init.d/ethnet &lt;&lt; "EOF"</userinput>
17#!/bin/sh
18# Begin /etc/init.d/ethnet
19#
20# Main script by Gerard Beekmans - gerard@linuxfromscratch.org
21# GATEWAY check by Jean-François Le Ray - jfleray@club-internet.fr
22# "Specify which IF to use to reach default GATEWAY" by
23# Graham Cantin - gcantin@pacbell.net
24#
25
26#
27# Include the functions declared in the /etc/init.d/functions file
28# and the variables from the /etc/sysconfig/network file.
29#
30
31source /etc/init.d/functions
32source /etc/sysconfig/network
33
34case "$1" in
35 start)
36
37#
38# Obtain all the network card configuration files
39#
40
41 for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
42 grep -v ifcfg-lo)
43 do
44#
45# Load the variables from that file
46#
47
48 source $interface
49#
50# If the ONBOOT variable is set to yes, process this file and bring the
51# interface up.
52#
53
54 if [ "$ONBOOT" == yes ]
55 then
56 echo -n "Bringing up the $DEVICE interface..."
57 /sbin/ifconfig $DEVICE $IP broadcast $BROADCAST \
58 netmask $NETMASK
59 evaluate_retval
60 fi
61 done
62
63#
64# If the /etc/sysconfig/network file contains a GATEWAY variable, set
65# the default gateway and the interface through which the default
66# gateway can be reached.
67#
68
69 if [ "$GATEWAY" != "" ]; then
70 echo -n "Setting up routing for $GATEWAY_IF interface..."
71 /sbin/route add default gateway $GATEWAY \
72 metric 1 dev $GATEWAY_IF
73 evaluate_retval
74 fi
75 ;;
76
77 stop)
78
79#
80# Obtain all the network card configuration files
81#
82
83 for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
84 grep -v ifcfg-lo)
85 do
86#
87# Load the variables from that file
88#
89
90 source $interface
91#
92# If the ONBOOT variable is set, process the file and bring the
93# interface down
94#
95
96 if [ $ONBOOT == yes ]
97 then
98 echo -n "Bringing down the $DEVICE interface..."
99 /sbin/ifconfig $DEVICE down
100 evaluate_retval
101 fi
102 done
103 ;;
104
105 restart)
106 $0 stop
107 sleep 1
108 $0 start
109 ;;
110 *)
111 echo "Usage: $0 {start|stop|restart}"
112 exit 1
113 ;;
114esac
115
116# End /etc/init.d/ethnet
117<userinput>EOF</userinput>
118</screen>
119</para>
120
121<sect2>
122<title>Adding default gateway to /etc/sysconfig/network</title>
123
124<para>
125If a default gateway is required to be setup, the following command does that:
126</para>
127
128<para>
129<screen>
130<userinput>cat &gt;&gt; /etc/sysconfig/network &lt;&lt; "EOF"</userinput>
131GATEWAY=192.168.1.2
132GATEWAY_IF=eth0
133<userinput>EOF</userinput>
134</screen>
135</para>
136
137<para>
138GATEWAY and GATEWAY_IF need to be changed to match the network setup.
139GATEWAY contains the address of the default gateway, and GATEWAY_IF
140contains the network interface through which that default gateway can
141be reached.
142</para>
143
144</sect2>
145
146<sect2>
147<title>Creating NIC configuration files</title>
148
149<para>
150Which interfaces are brought up and down by the ethnet script depends on
151the files in the /etc/sysconfig/nic-config directory. This
152directory should contain files in the form of ifcfg-x where x is an
153identification number (or whatever a user named it).
154</para>
155
156<para>
157First the nic-config directory is created by running:
158</para>
159
160<para>
161<screen>
162<userinput>mkdir /etc/sysconfig/nic-config</userinput>
163</screen>
164</para>
165
166<para>
167
168Now, new files are created in that directory containing the following.
169This creates a sample file ifcfg-eth0:
170</para>
171
172<para>
173<screen>
174<userinput>cat &gt; /etc/sysconfig/nic-config/ifcfg-eth0 &lt;&lt; "EOF"</userinput>
175ONBOOT=yes
176DEVICE=eth0
177IP=192.168.1.1
178NETMASK=255.255.255.0
179BROADCAST=192.168.1.255
180<userinput>EOF</userinput>
181</screen>
182</para>
183
184<para>
185Of course, the values of those four variables have to be changed
186in every file to
187match the proper setup. Usually NETMASK and BROADCAST will remain the
188same, just the DEVICE IP variables will change per network interface. If
189the ONBOOT variable is set to yes, the ethnet script will bring it up
190during boot up of the system. If set to anything else but yes it will be
191ignored by the ethnet script and thus not brought up.
192</para>
193
194</sect2>
195
196</sect1>
197
Note: See TracBrowser for help on using the repository browser.