4.3. Stop and Start Networking

4.3.1. From the command line

The main tool used to bring up the network interface is /sbin/ifconfig. Once initialised the kernel module aliased to eth0 in /etc/modules.conf (e.g tulip.o) is loaded and assigned an IP and netmask value.

As a result the interface can be switched on and off without losing this information as long as the kernel module is inserted.

Example 4.2. Using ifconfig

/sbin/ifconfig eth0 192.168.10.1 netmask 255.255.128.0
/sbin/ifconfig eth0 down
/sbin/ifconfig eth0 up

Another tool is /sbin/ifup. This utility reads the systems configuration files in /etc/sysconfig/ (or /etc/network/interfaces) and assigns the stored values for a given interface. The script for eth0 is called ifcfg-eth0 and has to be configured. If a boot protocol such as DHCP is defined then ifup will start the interface with that protocol.

Example 4.3. Using ifup

/sbin/ifup eth0
/sbin/ifup ppp0
/sbin/ifdown eth0

4.3.2. Using the network script

At boot time the ethernet card is initialised with the /etc/rc.d/init.d/network script. All the relevant networking files are sourced in the /etc/sysconfig/ directory. Similary, under Debian, the /etc/init.d/network script uses configuration from the /etc/network/ directory.

In addition the script also reads the sysctl options in /etc/sysctl.conf, this is where you can configure the system as a router (allow IP forwarding in the kernel). For example the line:

net.ipv4.ip_forward = 1

will enable IP forwarding [2] and the file /proc/sys/net/ipv4/ip_forward will contain a one.

The network script is started with the following command

/etc/rc.d/init.d/network restart

4.3.3. Renewing a DHCP lease

The following tools can query the DHCP server for a new IP:

  • pump

  • dhcpclient

A client daemon exists called dhcpcd (do not confuse this with the DHCP server daemon dhcpd)



[2] The line ip_forward=yes in the /etc/network/options file on Debian-based distributions has the same effect.