source: chapter07/ethnet.xml@ 9b3c02c

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 9b3c02c was 9b3c02c, checked in by Gerard Beekmans <gerard@…>, 23 years ago

Added option to select the network interface through which the default
gateway can be reached

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

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