Revision / Modified: May 23, 2002
Author: Tom Berger
Original documents:
http://www.mandrakeuser.org/docs/connect/cmlan.html
http://www.mandrakeuser.org/docs/connect/cmlan2.html
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.
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.
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.
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 ;-).
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:
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.
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.
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. Do not configure a machine to use a gateway if
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.
In order to reach each of the machines on a network by a name rather than by the IP number of its network interface, you have to write a 'hosts' file.
The example network consists of four machines, each with a different operating system:
For this setup, you would write a 'hosts' file like this:
# hosts file
127.0.0.1 localhost.localdomain localhost
10.0.0.10 terra.sol.lan terra linux
10.0.0.11 pluto.sol.lan pluto win98
10.0.0.12 saturn.sol.lan saturn winxp
10.0.0.13 venus.sol.lan venus macx
The first entry denotes the standard local loopback interface.
If there's a router on the network, it will get the IP 10.0.0.1 in this
example.
I assume that your router does DNS forwarding / caching (most do). If it
doesn't, you will have to use your provider's DNS addresses instead of the
IP number of your router when configuring DNS on the clients.
Save this file under the name 'hosts' and put it on a removable medium. The name of the file must be 'hosts', not 'hosts.txt' or 'Hosts' or similar. Keep in mind that every IP number and name on the network must be unique.
Copy the 'hosts' file to the 'c:\windows' directory.
Go to 'control panel - network'. An entry for your network card should
already appear in there (if not, install the driver for the card).
Look if you see an entry for a protocol that points to
that card. Unless this protocol is TCP/IP, remove it.
Mark the entry of the card, click 'Add', choose
'Protocol - Microsoft - TCP/IP'. Approve. Now you should have an entry in the
network panel like 'TCP/IP -> [your network card]' (or vice versa).
Highlight this entry, click 'Properties'. Set the IP for this machine (10.0.0.11) and the subnet mask (255.255.255.0).
If you are going to use a router, set its IP (10.0.0.1) in the 'Gateway' tab.
If you are going to use a router, click on the 'DNS configuration' tab and check 'Enable DNS'. Enter 'pluto' into the 'host' field and 'sol.lan' into the 'domain' field. Enter the IP of your router (10.0.0.1) into the 'DNS Server' field.
Close the network dialog and follow the system instructions.
After rebooting the system, open a DOS window and type
ping 10.0.0.11
You should get something like:
Pinging 10.0.0.11 with 32 bytes of data:
Reply from 10.0.0.11: Bytes=32 time<10ms TTL=128
(repeated three times)
Run
ping pluto
You should get:
Pinging pluto.sol.lan [10.0.0.11] with 32 bytes of data:
Reply from 10.0.0.11: Bytes=32 time<10ms TTL=128
(repeated three times)
Congratulations, you just configured your first machine! Three more to go.
Windows XP stores the 'hosts' file in the 'windows\system32\drivers\etc\' directory. You can safely overwrite the existing 'hosts' file in that directory (it just contains the local loopback interface).
Click 'Start' > 'Control Panel'. Click
'Network and Internet Connections'. Click
'Network Connections'. Double-click
'Local Area Connection'. Click
'Properties' (I love this).
If Internet Protocol (TCP/IP) is not already
installed, click 'Install', double-click
'Protocol', highlight 'Microsoft' in the
left window, and 'Internet Protocol (TCP/IP)' in the right window. Click
'OK'.
Click 'Internet Protocol (TCP/IP)' and then click 'Properties'.
Check 'Use the following IP address'. Enter '10.0.0.12' in the 'IP Address'
field, hit TAB key to auto-complete the 'Subnet mask' field.
If you are
using a router, enter its IP number (10.0.0.1 in our example) into the 'Default
gateway' and 'Preferred DNS server' field. Click 'OK'.
Open a terminal window and do the same tests as above with the IP and the name of the current machine ('10.0.0.12' and 'saturn') as well as with the IP and the name of the machine you've already configured. If both works, you've already got a working local area network!
Copy the 'hosts' file to the '/etc' directory as 'root'.
Open the Mandrake Control Center. Click 'Network & Internet', click 'Connection', click 'Wizard...', click 'Next'.
Check if 'LAN connection' is marked. Click 'Next', click 'OK'.
Enter IP address (10.0.0.10 in our example) and netmask (255.255.255.0). Click 'Next'.
Enter the hostname (terra.sol.lan). If you are using a router, enter its IP (10.0.0.1) in the 'DNS address' and the 'Gateway' field. If you are not using a router, enter your ISPs DNS address in the DNS address field. Unlike MS Windows, Linux does not accept dynamically assigned DNS addresses. If you enter no DNS address here, you might run into routing trouble later.
Click 'Next' and confirm.
Run the same checks as for the previous machines. If the shell can't find the 'ping' command, install the 'iputils' package. If it doesn't work, check '/etc/resolv.conf' and '/etc/sysconfig/network' for correct values.
Copy the contents of your 'hosts' into the '/etc/hosts' file of Mac OS X.
Set the hostname by editing '/etc/hostconfig' and setting HOSTNAME to 'venus.sol.lan':
HOSTNAME=venus.sol.lan
By default, Mac OS X does not use the '/etc/hosts' file for name resolution in all other runlevels than 1 (single user). To change this, you have to change the lookup order of 'lookupd':
Create a directory /etc/lookupd, e.g. with sudo mkdir /etc/lookupd
Create a new file in that directory called 'hosts' (e.g. with pico -w /etc/lookupd/hosts) and put this line in there:
LookupOrder FFAgent DNSAgent NIAgent
Restart 'lookupd' with
sudo kill -USR1 $(cat /var/run/lookup.pid)
Perform tests as above.
If you can 'ping' each machine on your network, you are set. You can now go on and configure such services as Samba or NFS.
If you run into trouble along the way or afterward, read this article again,
especially the page on theory, which should cover (almost) all potential
pitfalls.
If you can't figure it out on your own and ask others for help, you
can speed up things immensely by providing the output of the commands
route -n, ifconfig and the content of the files
'/etc/sysconfig/network' as well as '/etc/resolv.conf' along with your
question. If your problem is related to MS Windows, provide the output of the
Windows console command ipconfig /ALL.
Happy LANing! :-)