3.6. Network Configuration

3.6. Network Configuration

When installed, Linux easily determines the installed network cards. I have never had any problems in this respect. But this is not enough for network operation. You can specify the main connection parameters during the installation. Afterward, however, the settings sometimes have to be modified. You will not reinstall the system to do this, will you?

To transfer data over the network, various protocols have to be installed and configured. In general, a protocol is a set of rules used by two remote devices to exchange data. The rules describe whether a connection has to be established, specify the method for checking the data integrity, decide whether the data transfer is reliable or unreliable, and so on. All this is implemented in the protocol, and your task is to configure it properly.

3.6.1. Linux Addressing

The main protocol used in Linux is the Internet standard TCP/IP. This protocol is installed during Linux installation and only has to be configured. If you have never worked with this protocol, I recommend that you obtain and read some information on this subject. I cannot consider all nuances of TCP/IP in this book and will only consider the fundamental concepts.

For the network to work properly, the following minimal parameters should be configured:

  • The address. Each device in the network must have its address to be able to communicate with other devices in the network. Imagine that there were no addresses for your house. How, then, would mailmen deliver your mail? Computer names cannot be used for this purpose for various reasons beyond the scope of this book.

    Devices in a network are addressed using 32-bit-long IP addresses. For convenience, an IP address is divided into four binary octets, each of which is further converted into a decimal number. The four groups of decimal numbers are delimited using periods (dots). The resulting format is called dotted decimal notation.

    It is obvious that each group can be no larger than 255. Your Internet interface may have an IP address assigned by the Internet provider.

    For local network connections, you have to assign the addresses yourself. I recommend using addresses of the 192.168.1. x format, where x is a number in the 1 to 254 range (numbers 0 and 255 are reserved). Each computer must be assigned a unique address in this format, with the uniqueness determined by the last number. The third number can be anything but must be the same for all computers in the network. I use the number 77; that is, the computer addresses have the format 192.168.77 x .

  • The subnet mask. In conjunction with the IP address, another dotted decimal notation number is used to divide the network into smaller segments. It is called the subnet mask. Whereas your home address can have several components (such as the house or apartment number, street, city, and zip code), a computer address has only two characteristics: the network ID (also called a network address) and the ID of the computer inside the network (also called a host address). The subnet mask determines, which part of the computer address defines the network and which defines the host.

    To understand how the mask does this, each of its numbers has to be converted into the binary format. Consider this using mask 255.255.255.0 as an example. In binary format it looks as follows :

     11111111.11111111.11111111.00000000 

    Now convert the 192.168.001.001 IP address into the binary format:

     11000000.10101000.00000001.00000001 

    Superimpose the mask on the IP address. The ones in the mask determine, which parts of the IP address are the network address, and the zeros specify the host address. Ones in the mask must always be located in the left part of the mask, and zeros must be in the right. Ones cannot alternate with zeros. For example, the following mask is correct:

     11111111.11111111.00000000.00000000 

    This one is wrong:

     11111111.11111111.00000000.11111111 

    There can be no ones to the right of zeros.

    Consequently, with the 255.255.255.0 mask, the first three octets of the IP address define the network ID, and the last octet defines the host ID in this network. Because the maximum value that this octet can assume is 255, this is also the maximum number of computers the particular network can have.

    Consider another example.

    192.168.001.001 IP address

    255.255.000.000 Subnet mask

    In this case, the first two groups define the network ID, and the last two are the host ID in this network. The number that can be expressed by two octets is much larger than 255; consequently, the network will be much larger.

This allows the following conclusion to be drawn. Hosts (computers) whose IP addresses share the same network ID that is, are in the same network can communicate among themselves directly. Computers in different networks cannot see each other. For them to be able to interact, a special device a router must be used to connect different networks by passing packets from one network to another.

3.6.2. Viewing Network Connection Information

Information about the current configuration of the network cards and TCP/IP can be obtained by executing the ifconfig command. An example of the execution results is shown in Listing 3.4.

Listing 3.4: Information about the network configuration and state
image from book
 eth0 Link encap:Ethernet  HWaddr 00:03:FF:06:A4:6C      inet addr:192.168.77.1  Bcast:192.168.77.255  Mask:255.255.255.0      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:108 errors:0 dropped:0 overruns:0 frame:0      TX packets:104 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:100      RX bytes:7687 (7.5 Kb)  TX bytes:14932 (14.5 Kb)      Interrupt:11 Base address:0x2000 lo   Link encap:Local Loopback      inet addr:127.0.0.1 Mask:255.0.0.0      UP LOOPBACK RUNNING  MTU:16436  Metric:1      RX packets:122 errors:0 dropped:0 overruns:0 frame:0      TX packets:122 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0      RX bytes:9268 (9.0 Kb)  TX bytes:9268 (9.0 Kb) 
image from book
 

You can see that Listing 3.4 provides information for two interfaces: eth0 and lo. The former is the actual network adapter. Network adapters are named using the ethX format, where X is the number of the device. Device numbering starts with zero. Thus, if there are two network cards installed in your computer, they will be named eth0 and eth1.

The second interface is always named lo (for loopback); its IP address is always 127.0.0.1 and its subnet mask is always 255.0.0.0. This interface is present in any system equipped with a network card. This address does not define any network or a computer. It is used for testing and debugging network applications. It is called loopback because it closes on itself. All packets sent to this address by your computer are also received by your computer.

In addition to the network interface configuration information, the ifconfig command provides lots of other useful information. For example, the RX and TX entries contain information about the number of sent and received packets, respectively.

Another interesting piece of information given for the eth0 network card is the HWaddr (hardware address) parameter. It is also often called the MAC address. This is a 48-bit unique number assigned to the card by the manufacturer. It is unique because each manufacturer has its own MAC address range. Because the lo interface is created by software and does not actually exist, it cannot have a MAC address.

3.6.3. Modifying Network Connection Parameters

The if config command can be used not only to view network connection parameters but also to modify them. For this, it is executed with two arguments:

  • The network interface whose parameters are to be modified

  • The parameters

    The overall command looks as follows:

     ifconfig ethX parameters 

    The main parameters and their functions are the following:

  • down Causes the driver for the given interface to be shut down. For example, the eth0 network card can be shut down by executing the ifconfig eth0 down command. If the ifconfig command is executed without arguments immediately afterward, the particular network interface will not be in the information displayed.

  • up Activates a disabled interface. For example, the eth0 network card can be put back into operation by executing this command: ifconfig eth0 up .

  • IP address If you want to change the IP address, specify its new value as the parameter. For example, if you want to change the current IP address to 192.168.77.3, execute the following command: ifconfig eth0 192.168.77.3 . With the IP address, the subnet mask can also be modified. This is done by executing the ifconfig command as follows: ifconfig eth0 192.168.77.3 netmask 255.255.0.0. The new netmask value is specified after the netmask keyword.

    With the IP address and subnet mask modification, the interface can also be started by executing this command: ifconfig eth0 192.168.77.3 netmask 255.255.0.0 up .

These are the functions of the ifconfig command that you will most likely need in your work. You can obtain more detailed information in the ifconfig man page.

3.6.4. Basic Network Tuning

You can find out the computer's (host's) name with the help of the hostname command. The same command can be used to change the computer name by executing it with the new name specified as the argument. For example, the following command sets the host name to "server":

 hostname server 

The desired network configuration settings are stored in the /etc/sysconfig/network file. Take a look at its contents by executing the following command:

 cat /etc/sysconfig/network 

This will display information similar to the following:

 NETWORKTNG-yes FORWARD_IPv4=true HOSTNAME=FlenovM 

There is no need to change the preceding parameters manually, this can be done with specialized utilities. The contents of the file were shown only to give you an idea what they are.



Hacker Linux Uncovered
Hacker Linux Uncovered
ISBN: 1931769508
EAN: 2147483647
Year: 2004
Pages: 141

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net