MandrakeUser.Org - Your Mandrake-Linux Knowledge Base!


 
 

* DocIndex - Connectivity

Building A Small Mixed Network I (Theory)

* Hardware
* Protocol
* Addresses I: Numbers
* Addresses II: Names
* Routing

Related Resources:

Daryl's TCP/IP Primer
Linux Ethernet HOWTO
Linux Networking-HOWTO
The Linux Networking Overview HOWTO

Revision / Modified: May 23, 2002
Author: Tom Berger

 

* Hardware

Cards and chips

You'll need some computers, an Ethernet card or chip each and some cables. Basically you have the choice between 10base2 / 10baseT (10 MBit/s transfer rate max) and 100baseT (100 MBit/s max). Go for the latter if possible. A bit more costly but when it comes to networks, faster is always better. Macs come with built-in 100baseT (or even faster) Ethernet anyway.
I've made good experiences with Intel's Ethernet Pro 100 cards. Do some research on network card Linux compatibility when buying new cards.

Other possibilities are networking via USB or IEEE1394('FireWire'), but you should rather stick with the true and tested when it comes to connecting your machines.

Cables and Connectors

Buy 'twisted pair' (UTP) cables with RJ45 connectors (look like phone connectors). Make sure those cables are 'Cat 5' (should be printed on the box). There's nothing more embarrassing trying to troubleshoot network problems for hours and then to discover they were due to shoddy cables.
An older variant are 'thinnet' cables with BNC connectors (look like silver 'T's). They are only capable of 10 MBit/s connections, but they don't require a router when connecting more than two machines. On the other hand the entire network will go down if just one connector is pulled off (not that easy, though). Laptops with built-in Ethernet almost never have BNC connectors, same goes for Macs.

Hubs and Switches

If you've only got two computers you want to connect with each other with twisted pair cables, you can do so with a special 'Twisted Pair Crossover' cable. For more than two computers you will require a hub or even better a switch (a switch does some load balancing). These days you can get switches the size of two matchboxes for about 30 bucks.

If you want to have it really easy, buy a hardware router or use an obsolete computer to work as a router. A router can act as a switch, a DHCP (or even DNS) server, a firewall, an uplink to the Internet etc.

* section index * top

* Protocol

In order to establish communication between your machines, you need a communication protocol which each machine understands. This communication protocol constitutes the foundation for all high level services such as FTP, HTTP or SMTP.

There have been multiple attempts by vendors to create proprietary communication protocols like NetBEUI by IBM / Microsoft or IPX/SPX by Netware. But in the end, all these attempts failed to replace the open TCP/IP (Transmission Control Protocol / Internet Protocol), first incorporated in 4.2BSD Unix in the early eighties. It's the same protocol which keeps the Internet working and there's barely an operating system these days which doesn't come with a TCP/IP stack. Perfect choice ;-).

* section index * top

* Addresses I: Numbers

A communication protocol alone however will get you nowhere. In order to establish communication, the sender has to know where the receiver is and the receiver the location of the sender, or it will be a very one-sided communication.

Computers love numbers, so it should be no surprise that numbers are used to specify the communicating network interfaces (Ethernet cards, modems etc). In short, these numbers are referred to as IP numbers or IPs. Surely you've encountered them before: 192.168.1.145, 62.53.168.6 etc. If a computer has got several network interfaces, it can have several IP numbers.

In Red Hat based Linux distributions like Mandrake Linux, these IPs are assigned via interface scripts in '/etc/sysconfig/network-scripts/', e.g. '/etc/sysconfig/network-scripts/ifcfg-eth0 ' for the first Ethernet interface. You usually do not need to edit these files directly, you do that via utilities like 'DrakNet'. But it's good to know where they are, just in case ...

Every system with a working TCP/IP stack has the internal IP 127.0.0.1, even if it's not connected to the outside world. Do a

ping 127.0.0.1

and you will get a response if the TCP/IP system is correctly configured. 127.0.0.1 is used for internal system purposes only (jargon: 'local loopback', configured via '/etc/sysconfig/network-scripts/ifcfg-lo'), you can not use it when communicating with other machines.

The IP number scheme is really messy and if you're not a math freak, you really don't want to know about the gory details if not absolutely necessary. The good news: you can reduce this scheme on small local networks to some basic rules:

  • There are ranges of IPs reserved for local area networks:

    • 10.0.0.0 - 10.255.255.255
    • 172.16.0.0 - 172.31.255.255
    • 192.168.0.0 - 192.168.255.255

    Always use numbers in these ranges when configuring machines to communicate over a local network.

  • Keep the first three fields the same, only change the last. If you've got three machines for example, assign 10.0.0.1, 10.0.0.2 and 10.0.0.3,not 10.0.0.1, 10.0.1.1 and 10.1.1.1. This keeps machines in the same 'compartment' and you can use the same subnetmask (don't ask) of 255.255.255.0 for every machine.

  • Do not assign IPs ending on 0 or 255. Choose numbers between 1 and 254. IPs ending on 0 and 255 are reserved for special purposes.

  • Do not assign the same number twice.

IP numbers can be assigned either statically via a system configuration file or dynamically via a DHCP (Dynamic Host Configuration Protocol) server.

* section index * top

* Addresses II: Names

Computers like numbers, (most) humans do not. You'd rather type 'http://slashdot.org' than 'http://64.28.67.150' although both lead to the same network interface. In order to allow you to enter a name, some system is needed which converts ('maps') these names to their IPs and vice versa.

Back in the old days, when the Internet was nothing but a bunch of university and laboratory main frames, this was done by maintaining a central 'HOSTS.TXT' file which was then transferred via FTP to all hosts. This file contained single line IP / name pairs. With the explosive growth of the number of machines connected to the Internet, this system became impractical and was substituted by the BIND DNS (Berkeley Internet Name Domain Domain Name System).

The 'HOSTS.TXT' system is still in use, though. Type

ping localhost

and you will get the response

PING localhost.localdomain (127.0.0.1) from 127.0.0.1 : 56(84) bytes of data.

The file responsible for this mapping is '/etc/hosts'. In its default configuration, it will look like this:

127.0.0.1               localhost.localdomain localhost
                  

First there's the IP number, the second field is the 'full name' of the machine and the third contains one or more aliases (short names) for this machine.

Now you might ask: 'If the system uses both, the hosts file for local lookups and DNS for name resolution on the Internet, what decides which is queried first?' '/etc/hosts.conf' does this:

order hosts,bind
multi on

Every name query results in a lookup in '/etc/hosts' first and if unsuccessful, the query is forwarded to one of the DNS servers listed in '/etc/resolv.conf'.

You can use the 'hosts' file for setting up name resolution in your network and that's what you will do in the practical part of this article. While this method is easy to implement, it has a drawback: it only works if IPs are assigned statically, that is if each network interface on the network always gets the same address. If you've got clients which have to use DHCP for some reasons (e.g. laptops which are often connected to other networks), you have three possibilities:

  • Do not use name resolution for these clients. Name resolution is optional, you can always address connected machines by their IPs. Make sure the IP range available to DHCP clients does not overlap with the statically assigned IPs.

  • Configure and use DNS. Cool project, but beyond the scope of this article.

  • Configure your router to always assign the same IP to the same network interface. Each network card or chip has a unique identifier, its MAC address. Many routers allow you to configure to always assign a certain IP to a certain MAC address. Check your router's documentation.

When it comes to naming the machines on your network, you can do pretty much want you want. These names are not visible from the outside, so they don't need to be Fully Qualified Domain Names (FQDN) consisting of the local hostname and its domain name, including a top-level domain. In fact, it's better if you explicitly avoid choosing existing FQDNs on the Internet as names for your hosts since this might cause unnecessary traffic for the machine whose FQDN you are using.

If you are at a loss what names to use, have a look at FYI/FYI5 which contains very good advice on this topic.

Keep in mind that naming machines is convenience, not a necessity.

* section index * top

* Routing

If you follow my advice and keep all machines in the same subnet, there isn't much to say here, except for the topic of routers.

Routers act as network gateways for all computers on a network. As you will see in the practical part of this article, these computers have to be configured to use the IP of the router as the destination address for all outgoing traffic.
In Red Hat based Linux distributions, gateways are set via the GATEWAY option in '/etc/sysconfig/network'.

It's important for your sanity to keep this in mind: all outward bound network traffic will go through a gateway if a gateway is configured. Donot configure a machine to use a gateway if

  1. There is no router on your network;
  2. the machine itself acts as the router for the network;
  3. you want to go online directly via an interface on this machine.

The last point may need some elaboration: A wrong gateway configuration is possibly responsible for about 90% of all 'I can connect to the Net but get nowhere' help messages out there. A typical route table of a wrongly configured network looks like this (output condensed):

# route -n

Kernel IP routing table
Destination Gateway Genmask Flags Iface
217.5.98.53 0.0.0.0 255.255.255.255 UH ppp0
192.168.1.0 0.0.0.0 255.255.255.0 U eth0
127.0.0.0 0.0.0.0 255.0.0.0 U lo
0.0.0.0 192.168.1.2 0.0.0.0 UG eth0

The interface with the IP 192.168.1.2 is configured as the gateway ('G' flag) for this machine. All network traffic (Destination 0.0.0.0) except for traffic going out to interfaces with IPs in the (local) 192.168.1. range, traffic going out to 217.5.98.53 and the local loopback is sent to this gateway machine.
If you now type a URL in the address bar of your web browser, the request is sent not to the 'ppp0' interface which is connected to the Internet, but to the machine with the IP 192.168.1.2. If that machine isn't connected to the Internet itself and configured to allow connection sharing, the request will inevitably fail.
A correct routing table for this system would look like this

Kernel IP routing table
Destination Gateway Genmask Flags Iface
217.5.98.53 0.0.0.0 255.255.255.255 UH ppp0
192.168.1.0 0.0.0.0 255.255.255.0 U eth0
127.0.0.0 0.0.0.0 255.0.0.0 U lo
0.0.0.0 217.5.98.53 0.0.0.0 UG ppp0

Morale: If you plan to connect the machines on your LAN to the Internet, do so via the machine which already acts as the local router / gateway. If your network doesn't have a local gateway / router, don't configure your machines to use one.

* section index * top

* Practice


 
Legal: All texts on this site are covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB (Tom Berger) and Mandrakesoft 1999-2002.