Which interfaces are brought up and down by the network script
depends on the files and directories in the /etc/network.d
hierarchy. This directory should
contain a file for each interface to be configured, such as
interface.xyz
, where
“xyz” is a network interface
name. Inside this file we would be defining the attributes to this
interface, such as its IP address(es), subnet masks, and so forth.
The following command creates the network.conf
file for use by the entire system:
cat > ${CLFS}/etc/network.conf << "EOF"
# /etc/network.conf
# Global Networking Configuration
# interface configuration is in /etc/network.d/
# Based on QEMU userland networking
# set to yes to enable networking
NETWORKING=yes
# set to yes to set default route to gateway
USE_GATEWAY=yes
# set to gateway IP address
GATEWAY=10.0.2.2
# Interfaces to add to br0 bridge
# Leave commented to not setup a network bridge
# Substitute br0 for eth0 in the interface.eth0 sample below to bring up br0
# instead
# bcm47xx with vlans:
#BRIDGE_INTERFACES="eth0.0 eth0.1 wlan0"
# Other access point with a wired eth0 and a wireless wlan0 interface:
#BRIDGE_INTERFACES="eth0 wlan0"
EOF
The GATEWAY
variable should contain the
default gateway IP address, if one is present. If not, then comment
out the variable entirely.
The following command creates a sample interface.eth0
file for the eth0 device:
mkdir ${CLFS}/etc/network.d &&
cat > ${CLFS}/etc/network.d/interface.eth0 << "EOF"
# Network Interface Configuration
# network device name
INTERFACE=eth0
# set to yes to use DHCP instead of the settings below
DHCP=no
# IP address
IPADDRESS=10.0.2.15
# netmask
NETMASK=255.255.255.0
# broadcast address
BROADCAST=10.0.2.255
EOF
The INTERFACE
variable should contain
the name of the interface interface.
The DHCP
variable if set to yes will
allow you to use dhcp. If set to no, you will need to configure the
rest of the options.
The IPADDRESS
variable should contain
the default IP address for this interface.
The NETMASK
variable should contain the
default Subnet Mask for the IP address for this interface.
The BROADCAST
variable should contain
the default Broadcast Address for the Subnet Mask of the IP Range
being used on this interface.
For DHCP to work properly a configuration script is needed. Create a sample udhcpc.conf:
cat > ${CLFS}/etc/udhcpc.conf << "EOF"
#!/bin/sh
# udhcpc Interface Configuration
# Based on http://lists.debian.org/debian-boot/2002/11/msg00500.html
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
RESOLV_CONF="/etc/resolv.conf"
RESOLV_BAK="/etc/resolv.bak"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
case "$1" in
deconfig)
if [ -f "$RESOLV_BAK" ]; then
mv "$RESOLV_BAK" "$RESOLV_CONF"
fi
/sbin/ifconfig $interface 0.0.0.0
;;
renew|bound)
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ] ; then
while route del default gw 0.0.0.0 dev $interface ; do
true
done
for i in $router ; do
route add default gw $i dev $interface
done
fi
if [ ! -f "$RESOLV_BAK" ] && [ -f "$RESOLV_CONF" ]; then
mv "$RESOLV_CONF" "$RESOLV_BAK"
fi
echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
for i in $dns ; do
echo nameserver $i >> $RESOLV_CONF
done
;;
esac
exit 0
EOF
chmod +x ${CLFS}/etc/udhcpc.conf
If the system is going to be connected to the Internet, it will
need some means of Domain Name Service (DNS) name resolution to
resolve Internet domain names to IP addresses, and vice versa. This
is best achieved by placing the IP address of the DNS server,
available from the ISP or network administrator, into /etc/resolv.conf
. Create the file by running the
following:
cat > ${CLFS}/etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf
nameserver 10.0.2.3
nameserver 127.0.0.1
# End /etc/resolv.conf
EOF
Replace [IP address of the
nameserver]
with the IP address of the DNS most
appropriate for the setup. There will often be more than one entry
(requirements demand secondary servers for fallback capability). If
you only need or want one DNS server, remove the second
nameserver line from the
file. The IP address may also be a router on the local network.