If you do not have a copy of netconfig with your Linux distribution so that you have to configure your network software manually, or if you need to configure your machine to run on a network via an ethernet card, then you wiH need more information than just the hostname and domain name for your system.
As before, the hostname is just a single word to identify your machine connection to the network. If you are adding your machine to an existing network then there could be some local naming convention that you may be required to follow. If you are in this situation then the existing network administrator will be able to advise you.
Here again, if you are connecting to an existing network, there will be an existing domain name which you will be required to use when you add your machine. Again, the local administrator is the person to contact for advice.
Data is moved around a TCP/IP network using the Internet Protocol where each machine connection to the network (the network covers the whole world in the case of the Internet) has a unique number which is used to address it, called its IP address. These IP addresses are just 32-bit numbers, which are usually given as four separate bytes, and written as four decimal numbers separated by periods (full stops). For example, 199.38.231.66. The first part of the IP address specifies to which network the address refers (network address), and the rest specifies a particular machine connection (host number) on that network.
This is a 4-byte number which specifies how much of an IP address is the network address and how much is the host number on that network. The first part of the network mask (netmask) contains binary 1 bits to indicate the bit positions that specify the network address, and the remainder contains binary 0 bits to indicate the bit positions that specify the host number.- By default, it is possible to work out what the netmask value should be, just from the first byte of the IP address, as follows:
IP range netmask up to 127 255.0.0.0 128 to 191 255.255.0.0 192 on 255.255.255.0
This is a 4-byte number which can be calculated just as the bitwise AND of the IP address and its netmask value. For example, if the IP address is 195.123.48.12 and the netmask, from the previous table, is 255.255.255.0, then the network address is 195.123.48.0.
This is also a 4-byte value, calculated as the bitwise OR of the network address and the inverse of the netmask. Continuing with the previous example, the network address is 195.123.48.0 and the inverse of the netmask is 0.0.0.255, which gives a broadcast address of 195.123.48.255.
This is the IP address of the machine connection on your net-work through which you can gain access to machines that don't share your network address. These gateway machines will have connections to at least two networks and have the ability to transfer network traffic between the networks, as required. You will need to get this address from your local administrator if you are connecting your machine to an existing network.
A name server is a machine, one of whose functions is to provide the service of translating hostname and domain name pairs into IP addresses. The setup of a small network doesn't need a name server and adding a new machine to an existing network just means getting the name server IP address from the local administrator.
Armed with all these names and numbers you are now ready to do some network setup. Still the easiest option if you have netconfig available is to use it, providing the necessary details as it asks for them. But now, if you don't have netconfig available, it is a fairly simple task to configure the networking yourself.
Don't forget, when you add a network card to your machine, you will need to rebuild the Linux kernel and add your particular card type to the kernel configuration, which you supply when you run make config.
When your system first boots, one of the things it needs to do, if you want to run networking software, is to start up the networking system.
This involves setting up the machine's network interfaces with the ifconfig command, setting up the kernel's routing tables with the route command, and then executing the daemons that will provide the various network services.
Unfortunately, when it comes to setting up the files needed to start up networking, there is no single standard to which all Linux distributions adhere to dictate where the files should be stored or even what the files should be called. However, most distributions do store these files in the directory hierarchy, somewhere under /etc and the files of interest are given names like rc.net, rc.inet or rc.inet1 and rc.inet2.
The execution of these and other rc files is performed at system boot time. The first process to run when the system boots is process number 1, called init. This process periodically consults the file /etc/inittab to find out what it should do under various sets of circumstances, and executing appropriate rc files is one of its tasks. Sometimes init will be configured to execute the network setup files directly, sometimes it will just execute another rc file, which will in turn execute the network setup files instead. Either way, when the files execute there are several specific tasks to be performed.
The first task is set up your machine's hostname. This is done with the hostname command. What you need is for this command to be executed for you each time your machine boots. Normally, the command will be executed by one of the rc files run by init. The command itself has the format:
# hostname Hawklord
where, in this example, Hawklord is the hostname to be set up. Instead of setting the hostname directly like this, some Linux distributions use a line like the following:
# hostname 'cat /etc/HOSTNAME | cut -fi -d
and then put the fully qualified host and domain name into the file /etc/HOSTNAME, as the following example shows:
$ cat /etc/HOSTNAME Hawklord.varteg.co.uk
This is a rather simpler arrangement for an automatic configuration program, which only has to re-write the contents of /etc/HOSTNAME when the hostname is set up rather than editing the hostname line in the middle of some other configuration file.
From this point on, the discussion assumes that your system uses the network startup files:
/etc/rc.d/rc.inet1 /etc/rc.d/rc.inet2
Even if this is not the case, the same tasks need to be performed but just using different files.
The first task (in rc.inet1) is to configure the loopback device, with the following command sequence, which involves the ifconfig and route commands:
#!/bin/sh /sbin/ifconfig lo 127.0.0.1 /sbin/route add -net 127.0.0.0
Obviously, if your ifconfig and route commands are not in the directory /sbin then you will need to modify these lines to suit your own directory layout.
The first line here is just to specify which shell should be used to execute the rest of the commands. The ifconfig command is used to specify the name of the local loopback interface (10) and its IP address of 127.0.0.1. The route command adds the network to which the local loopback address belongs to the kernel's routing table, so that IP packets sent to the local loopback address will be routed correctly.
After this, if you have an ethernet card fitted then this also needs to be configured by adding lines to the rc.inet.1 file like the following:
IPADDR="ip.ip.ip.ip" NETMASK="nm.nm.nm.nm" NETWORK="nw.nw.nw.nw" BROADCAST="bc.bc.bc.bc" GATEWAY="gw.gw.gw.gw" /sbin/ifconfig eth0 ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK} /sbin/route add -net ${NETWURK} netmask ${NETMASK} /sbin/route add default gw ${GATEWAY} metric 1
Obviously, you need to replace the ip, nm, nw, bc and gw values above with your own, proper address values.
The ifconfig command associates an IP address with the first ethernet interface, called ethO. After that, the route command that follows adds an entry to the kernel routing table specifying that network traffic bound for the local network should be sent through this interface. The final line is the routing information for all network traffic outside the local network. It just specifies that this traffic should take the default route through the gateway machine. If you only have a local network so that there is no gateway machine, then this last line should be omitted.
Once the network interfaces and routes are set up the next thing to do is execute the daemons and servers associated with network applications. In our example, these things are arranged by the file rc.inet2.
In a simple arrangement, only two servers need to be run from rc.inet2. These are syslogd which is used to log system messages and error reports (usually into the file /var/log/messages), and inetd, which makes a number of services available from your machine, including telnet, ftp, finger and rlogin, of which more later. An rc.inet2 file to run these daemons could be:
# Start the syslogd daemon. if [ -f /usr/sbin/syslogd ] then /usr/sbin/syslogd fi # Start the INET SuperServer if [ -f /usr/sbin/inetd ] then /usr/sbin/inetd fi
In some Linux distributions the syslogd and inetd programs may not reside in /usr/bin so you will have to make the appropriate changes to the contents of rc.inet2 to match the arrangement of your system.
All that now remains is to create and/or populate a few simple files to specify some IP names and addresses. Once again, if you have and use the netconfig command these files will be set up for you. The four files are called:
/etc/networks /etc/hosts /etc/host.conf /etc/resolve.conf
Taking each of these files in turn, let us sort out what each is for and also examine their typical contents.
This file contains a list of network names and their associated network numbers. The file is used by the route command in the situation where you want to add a route to a complete network to your kernel's routing table, and you want to specify the network by name rather than by number. In this case, the route command will use the file /etc/networks to look up the network number from the name. Typical contents for this file could be:
loopback 127.0.0.0 phil-net 194.61.21.0
Obviously, you would use your own network numbers in your /etc/networks file in place of the ones above. If you specify a network number directly to the route command rather than a network name, then that entry need not appear in the networks file.
This file contains a list of machine IP numbers and their associated IP address names. For large private networks and for the Internet, the names of network hosts are translated into the appropriate IP numbers by requesting the information from a name server. However, for small networks without a name server, or on larger networks, to cover the time at system boot before the name servers are running, you can put a small number of IP numbers and names in /etc/hosts and arrange for the system to look in the hosts file for IP name and address translations before it tries to contact a name server. Typical file contents would be:
127.0.0.1 localhost 194.61.21.50 Hawklord.varteg.co.uk Hawklord
This just says that the IP address for the localhost is 127.0.0.1 (which is allways the case) and that the IP address for the host Hawklord.varteg.co.uk is 194.61.21.50. The lines of this file also allow you to specify alias names for the given hostnames. The second line shows the specification of an alias of Hawklord which can subsequently be used as an abbreviated hostname.
For small, stand alone networks there need not be a name server, and then each machine on the network would just rely on the contents of its own hosts file for hostname to IP address translation.
This file controls how and in what order the system will try to use the various name services. A typical /etc/host.conf file would be:
order hosts, bind multi on
The first line specifies that when a process requests a hostname to IP number lookup, the request will be ordered as follows: first the file /etc/hosts will be consulted and only if the required information is not found there will the bind service be used, that is, the local name server will be contacted for the information. The second line in the example specifies that hosts detailed in /etc/hosts are allowed to have multiple IP address numbers for the same host.
The main uses for the file resolv.conf are to specify a list of name servers to try when looking up IP address numbers from hostnames, and to specify a domain name which will be appended to a hostname when bind fails to resolve the name with the first lookup. The latter facility allows you to specify hostnames in the local domain as just machine names and still have their IP address numbers correctly resolved, albeit on the second attempt.
A typical /etc/resolv.conf file could be:
domain varteg.co.uk nameserver 194.61.21.1
When specifying multiple name servers, each one has its own nameserver line in the file /etc/resolv.conf and the order of the lines is used to determine the order in which the name servers are contacted.
Whilst this section cannot hope to cover all there is to know about network setup, the previous instructions should cover most simple network configurations. But, if you are adding your machine to a more complex network setup then there will, in all probability, be an existing network guru on hand to help you out anyway.