source: chapter07/ethnet.xml@ 3a4d451

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 3a4d451 was 8ef599c, checked in by Simon Perreault <nomis80@…>, 23 years ago

Removed blank lines after <literallayout> and before </literallayout>

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

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