Creating network boot scripts

Creating the /etc/init.d/localnet bootscript

Create a new file /etc/init.d/localnet containing the following:



#!/bin/sh
# Begin /etc/init.d/localnet

check_status()
{
  if [ $? = 0 ]
  then
    echo "OK"
  else
    echo "FAILED"
  fi
}

echo -n "Setting up loopback device..."
/sbin/ifconfig lo 127.0.0.1
check_status

echo -n "Setting up hostname..."
/bin/hostname --file /etc/hostname
check_status

# End /etc/init.d/localnet

Setting up permissions and symlink

Set the proper file permissions and create the necessary symlink by running the following commands:



root:~# cd /etc/init.d
root:/etc/init.d# chmod 755 /etc/init.d/localnet
root:/etc/init.d# cd ../rcS.d
root:/etc/rcS.d# ln -s ../init.d/localnet S03localnet

Creating the /etc/hostname file

Create a new file /etc/hostname and put the hostname in it. This is not the FQDN (Fully Qualified Domain Name). This is the name you wish to call your computer in a network. An example:


# Begin /etc/hostname

lfs

# End /etc/hostname

Creating the /etc/hosts file

If you want to configure a network card, you have to decide on the IP-address, FQDN and possible aliases for use in the /etc/hosts file. An example is:



<my-IP> myhost.mydomain.org aliases

Make sure the IP-address is in the private network IP-address range. Valid ranges are:



Class Networks
A     10.0.0.0
B     172.16.0.0 through 172.31.0.0
C     192.168.0.0 through 192.168.255.0

A valid IP address could be 192.168.1.1. A valid FQDN for this IP could be www.linuxfromscratch.org

If you're not going to use a network card, you still need to come up with a FQDN. This is necessary for programs like Sendmail to operate correctly (in fact; Sendmail won't run when it can't determine the FQDN).

If you don't configure a network card, create a new file /etc/hosts containing:



# Begin /etc/hosts (no network card version)

127.0.0.1 www.linuxfromscratch.org <contents of /etc/hostname> localhost

# End /etc/hosts (no network card version)

If you do configure a network card, create a new file /etc/hosts containing:



# Begin /etc/hosts (network card version)

127.0.0.1 localhost
192.168.1.1 www.linuxfromscratch.org <contents of /etc/hostname>

# End /etc/hosts (network card version)

Of course, change the 192.168.1.1 and www.linuxfromscratch.org to your own liking (or requirements if you are assigned an IP-address by a network/system administrator and you plan on connecting this machine to that network).

Creating the /etc/init.d/ethnet file

This section only applies if you are going to configure a network card. If you're not, skip this section.

Create a new file /etc/init.d/ethnet containing the following:



#!/bin/sh
# Begin /etc/init.d/ethnet

check_status()
{
  if [ $? = 0 ]
  then
    echo "OK"
  else
    echo "FAILED"
  fi
}

IPADDR="209.83.245.12" # Replace with your own IP address
NETMAKSK="255.255.255.0" # Replace with your own Netmask
NETWORK="209.83.245.0" # Replace with your own Network address
BROADCAST="209.83.245.255" # Replace with your own Broadcast addr.
GATEWAY="209.83.245.1" # Replace with your own Gateway address

echo -n "Setting up eth0..."
/sbin/ifconfig eth0 $(IPADDR) broadcast $(BROADCAST) netmask $(NETMASK)
check_status

echo "Setting up route..."
/sbin/route add -net $(NETWORK) netmask $(NETMASK) eth0
check_status

echo "Adding default gateway..."
/sbin/route add default gw $(GATEWAY) metric 1
check_status

# End /etc/init.d/ethnet

Setting up permissions and symlink

Set the proper file permissions and create the necessary symlink by running the following commands:



root:~# cd /etc/init.d
root:/etc/init.d# chmod 755 /etc/init.d/ethnet
root:/etc/init.d# cd ../rc2.d
root:/etc/rc2.d# ln -s ../init.d/ethnet S10ethnet