source: chapter07/ethnet.xml@ 38e8642

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 38e8642 was 2dff95b, checked in by Gerard Beekmans <gerard@…>, 23 years ago

white space matters...

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