HOW TO NETWORK TWO OR MORE COMPUTERS USING ETHERNET
Copyright (C) 2005 Daniel Brodzik
This document is free software; you may distribute and/or modify it under the terms of the GNU Free Documentation License; either version 1.2 of the license or, at your option, any later version, with no Front Cover Texts, no Back Cover Texts, and no Invariant Sections.
INTRODUCTION
The world of Linux networking is both frustrating and fun. It is frustrating trying to get everything to work if you don't already know how, but it's very fun when everything works. I never really knew much about networking until ten months after I started using Linux. However, a combination of a class I took and my ability to try out networking fairly inexpensively and with a reasonable speed helped me immensely.
This guide explains how to set up a home network with a hub or switch with the modern RJ45 (UTP) cabling, two computers and a crossover cable, the 10base2 "Thinnet" coaxial cabling with the BNC connectors, or the 10base5 thick coaxial cable, in Linux. In addition, I will explain how to set up printing support over the network. Also, taken directly from my parallel-port network guide, I explain how remote log-ins and the remote X Window System capabilities work, and how to use them. There will be no servers on the network; just file sharing, printer sharing, remote log-ins, and remote X will be involved. If you are a Linux sysadmin, and your job depends on whether you know how to network or not, please do not hold me responsible if these directions (or lack thereof) gets you fired.
This guide explains how to set up a network with these characteristics:
Two through 254 computers on the network
Cabled Ethernet
Either coaxial (10base5 or 10base2) or RJ-45 (10baseT or 100baseT) cabling. The coaxial types do not require a hub/switch, but the RJ-45 types do require either a hub or switch. The software set-up is exactly the same for each type of cable.
A hub or switch if you're using normal RJ-45 cables (this is not necessary with coaxial networks or Ethernet networks with crossover cables)
Optionally, you can read about how to share printers over the network with CUPS, (now) the most common print system under Linux
No dedicated servers
No name servers (also known as DNS servers). Because of this, you will need a list of hosts stored on each computer, but that's not hard to do. A name server could run on one computer, but that computer would have to be running every time you want to use the network.
No gateways
TCP/IP protocol
Manual IP address assignment. This is the easiest method to set up a small network. (Setting up DHCP is, in my opinion, too complicated for a home network. You would need one computer running 24/7, and if it's off, the whole network will go down after a while, when the other computers try to renew their IP address leases periodically.)
The most important characteristic: file sharing among all the computers on the network. The fact that I can do this is very convenient because, without it, transferring files between my basement computer and my computers in my bedroom upstairs would get very tiring very quickly. :)
Depending on the type of Ethernet cabling your Ethernet cards require, your requirements will vary slightly. No matter what your Ethernet cards are, you will need to use all Ethernet cards that use the same cable type. Their ports should look exactly the same.
If your Ethernet cards use a coaxial cable (round with a pin in the middle; also known as 10base5) or a BNC (like coaxial but you push in and twist it to lock it; also known as 10base2) cable, you will need the following:
Multiple computers capable of running Linux
All your Ethernet cards must use the same kind of coaxial cable. All your Ethernet cards must support the same cable type! The Ethernet cards must also be supported by Linux, of course.
A T piece for each computer. You should plug the T pieces directly into your Ethernet cards for best performance.
Two terminators. Put one on each end of the network.
Enough cables. You will need to take the number of computers on the network and subtract one to find the number of cables you will need. Use the right cable type. When you plug each T piece into the computers and terminate both, connect the two free ends of the T pieces using the cable.
A console-based text editor (I recommend ne or nano for beginners)
The root passwords for all systems
A normal user account with the SAME name on both machines is HIGHLY recommended to allow file transfer as a non-root user using NFS. If you have KDE, you can use "fish" to access the other computer's files; in this case, you don't need an account on the other computer. I don't think NFS will work unless you have the same user name on both machines because, by default, Linux 'squashes' root access to files over any kind of a network to prevent someone who, for example, connects to your computer over a wide-area network, such as the Internet, using their root account on their computer without you knowing about it and messing up your files. Disabling the 'rootsquash' option is NOT recommended! If you want to do remote administration, do a remote log-in instead, preferably using SSH (as described in this guide).
NOTE: The coaxial and BNC methods never require hubs because, in this type of Ethernet network, each computer is connected in a bus topology. This means that the cable runs down the middle or back and acts as a backbone. Each computer connects to the cable. The cable gets terminated at both ends.
If your Ethernet cards use an RJ45 connector (looks like a fat phone jack; known as 10baseT or 100baseT, depending on the maximum speed of the cable), which is most commonly used today, you will need the following:
Multiple computers capable of running Linux. Of course, some form of Linux must already be installed and operational on each computer. You don't need to have the same Linux distribution on all computers, but it can help. In this guide, I will focus on my two favorites, Debian GNU/Linux 3.0 and Mandrake 10.1.
Multiple Ethernet cards that use RJ45 connectors and are supported by Linux. I recommend the Realtek 8139 or a compatible card like the D-Link DFE-538TX if you're buying a new card. This is the chip that my laptop uses, and I recently bought a card at Radio Shack with that chip on it. It is very fast (supports up to 100 Mbps full-duplex connections), very inexpensive, and very well-supported under Linux. I recommend 100 Mbps cards because they're now inexpensive, but a 10 Mbps card may be required, especially if one or more computers on the network must use an ISA card. (Adding a 10 Mbps card to an otherwise 100 Mbps network that uses a hub may slow down the entire network to 10 Mbps, but using a switch to connect it to 100 Mbps computers will not slow down communications between/among the faster network cards.)
One cable for each computer. If the hub or switch will be in a different room, make sure the cable is long enough! Get regular cables, not crossover cables, unless you intend to connect only two computers together. With a crossover cable, get only one cable.
A hub or switch if you are not using a crossover cable. A hub and a switch connect and operate the same from the users' point of view, but a switch is much faster than a hub in most cases. You can get a five-port switch at Radio Shack for about $30 US. (The Ethernet HOWTO says that it costs $50 US, but mine was only about $30 US.) Make sure that the hub or switch you get supports the maximum speed of your Ethernet cards! If you plan on mixing 10 and 100 Mbps cards on the network, get a 100 Mbps switch.
A console-based text editor (I recommend ne or nano for beginners)
The root passwords for all systems
A normal user account with the SAME name on both machines is HIGHLY recommended to allow file transfer as a non-root user using NFS. If you have KDE, you can use "fish" to access the other computer's files; in this case, you don't need an account on the other computer. I don't think NFS will work unless you have the same user name on both machines because, by default, Linux 'squashes' root access to files over any kind of a network to prevent someone who, for example, connects to your computer over a wide-area network, such as the Internet, using their root account on their computer without you knowing about it and messing up your files. Disabling the 'rootsquash' option is NOT recommended! If you want to do remote administration, do a remote log-in instead, preferably using SSH (as described in this guide).
These instructions were tested on a mixture of Debian 3.0 and Mandrake 10.1 systems. If you already have a network set up, talk to your administrator to find out if the IP addresses given in both methods and the host names ("one" and "two") in the temporary method need to be changed. If you have an Internet connection, you should be fine because the IP addresses in this guide are in the 'private network' range.
DEBIAN GNU/LINUX 3.0 CONFIGURATION:
Under the X Window System, get to a terminal/shell window, and type "su".
After entering your root password, type "cd /etc".
Type "nano hosts" to edit your hosts file. You will need to give each machine a name and IP address, put each one in this file, and copy this file to each computer on your network. I recommend using the 192.168.0.x addresses because they don't interfere with the Internet. The format for this file is:
IP address hostname hostname.domain.suffix
For example, I have three computers on my network. My domain name is dbrodzik.home. The computers are "laptop", "pentiumtwo", and "ibmmmx". My entries look like this:
127.0.0.1 localhost localhost.localdomain
192.168.0.1 laptop laptop.dbrodzik.home
192.168.0.2 pentiumtwo pentiumtwo.dbrodzik.home
192.168.0.3 ibmmmx ibmmmx.dbrodzik.home
Replace as appropriate for each name you choose. Note that most distributions prompt you for a hostname when you're installing them. If you did specify unique names for each computer, they will probably be on the 127.0.0.1 line, the so-called "loopback" address. If that's the case, and you wish to use those names for the network, you must move the name from that line to one of the two "192.168.0.x" lines. CAUTION: Do NOT move "localhost" or "localhost.localdomain" from that line, and do not use it as a name for either 192.168.0.x address! Doing that could screw up your system! Sending data to 127.0.0.1 will make it return as a network request to the local host, which is why it's called a "loopback" address. Because of this, you should not use "localhost" for the networked name of a computer. CAUTION: Make sure the first IP address you choose doesn't have 0 or 255 as the last number! 0 is used to denote a network address, not a host on the network, and 255 is used for so-called "broadcast" addresses. (A broadcast address is used for packets that go to every computer on the network. For example, my network address is 192.168.0.0. If I ping 192.168.0.255, I will get responses from every computer that's on and connected to my network.) CAUTION: Use the same domain on each computer! The localhost address should have the domain name "localdomain", as my example illustrates.
Type "nano hostname" to set the default hostname on each computer to the ones you chose for the network. This helps when doing remote log-ins.
Type "cd network". If that gives you an error message (meaning you somehow left /etc), type "cd /etc/network" instead. :)
Type "nano interfaces". On the first computer, put this at the end:
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
On the second computer:
iface eth0 inet static
address 192.168.0.2
netmask 255.255.255.0
network 192.168.0.0
And so on for the rest of the computers on your network. Note that the network interfaces could be something other than eth0.
We will now set up the directories that you wish to make accessible on the other computer. Still as root, type 'nano /etc/exports'. Then, use these lines as a guide to add your own lines. This example gives read & write permission to the /home directory. (Replace remotename with the other computer's name.)
# <directory> <machine and options>
/home remotename(rw)
Type 'exportfs -r' to make the changes to '/etc/exports' to take effect immediately. You will have to do this after modifying that file. If you don't, the changes will not take effect until you reboot, which is the Windows way of doing things...
Type "mkdir -m 777 /mnt/net" to make a mount point for your network.
If you want normal users to be able to mount and unmount the remote file system, add a line like this to your /etc/fstab using "nano /etc/fstab":
remotename:/home /mnt/net nfs user,noauto 0 0
where remotename is the other computer.
Plug in the cable and reboot all systems. To test the network, try pinging the other computer. For example, type "ping -c 10 remotename", where remotename is the remote computer's host name (again). If you see some lines appear every second for 10 seconds, and they're not error messages, your network is okay. To mount the other computer's file system, use "mount /mnt/net" as a normal user (if you set this up). You're done! Check the end of this guide for some cool network tricks you can perform. If it didn't work, check the Trouble section.
MANDRAKE 10.1 CONFIGURATION:
Under the X Window System, get to a terminal/shell window, and type "su".
After entering your root password, type "cd /etc".
Type "nano hosts" to edit your hosts file. You will need to give each machine a name and IP address, put each one in this file, and copy this file to each computer on your network. I recommend using the 192.168.0.x addresses because they don't interfere with the Internet. The format for this file is:
IP address hostname hostname.domain.suffix
Make up the host names and a domain name. It really doesn't matter exactly what you choose. For example, I have three computers on my network. My domain name is dbrodzik.home. The computers are "laptop", "pentiumtwo", and "ibmmmx". My entries look like this:
127.0.0.1 localhost localhost.localdomain
192.168.0.1 laptop laptop.dbrodzik.home
192.168.0.2 pentiumtwo pentiumtwo.dbrodzik.home
192.168.0.3 ibmmmx ibmmmx.dbrodzik.home
Replace as appropriate for each name you choose. Note that most distributions prompt you for a hostname when you're installing them. If you did specify unique names for each computer, they will probably be on the 127.0.0.1 line, the so-called "loopback" address. If that's the case, and you wish to use those names for the network, you must move the name from that line to one of the two "192.168.0.x" lines. CAUTION: Do NOT move/remove "localhost" or "localhost.localdomain" from that line, and do not use it as a name for either 192.168.0.x address! Doing that could screw up your system! Sending data to 127.0.0.1 will make it return as a network request to the local host, which is why it's called a "loopback" address. Because of this, you should not use "localhost" for the networked name of a computer. CAUTION: Make sure the first IP address you choose doesn't have 0 or 255 as the last number! 0 is used to denote a network address, not a host on the network, and 255 is used for so-called "broadcast" addresses. (A broadcast address is used for packets that go to every computer on the network. For example, my network address is 192.168.0.0. If I ping 192.168.0.255, I will get responses from every computer that's on and connected to my network.) CAUTION: Use the same domain on each computer! The localhost address should have the domain name "localdomain", as my example illustrates.
Mandrake 10.1 has a nice graphical network configuration utility. To use it, click the icon in your KDE or GNOME panel that looks like a blue monitor screen with a wrench by it. You will need your root password for this.
Click "Network & Internet", "New connection".
In the wizard, select the type of connection. In this case it's a "LAN connection", so select that and click "Next".
Select your Ethernet device. Click "Next".
Select "Manual configuration". Click "Next".
Depending on what you selected in your "hosts" file, select the IP address you assigned to the computer you're using now. Your netmask is 255.255.255.0. You can set the three checkboxes according to what you want. Click "Next".
Enter the host and domain names you put in your /etc/hosts file. You will need to match the host name and IP address pairs you entered in "hosts". Leave the rest of the text boxes blank. If there's anything in them already, erase it.
We will now set up the directories that you wish to make accessible on the other computer. Still as root, type 'nano /etc/exports'. Then, use these lines as a guide to add your own lines. This example gives read & write permission to the /home directory. (Replace remotename with the other computer's name.)
# <directory> <machine and options>
/home remotename(rw)
Type 'exportfs -r' to make the changes to '/etc/exports' to take effect immediately. You will have to do this after modifying that file. If you don't, the changes will not take effect until you reboot, which is the Windows way of doing things...
Type "cd /mnt".
Type "mkdir -m 777 directory" to make mount points for your network. You will make one directory for each other computer on the network. That is, make one for each computer on your network except the one you're currently sitting in front of.
If you want normal users to be able to mount and unmount the remote file system, add a line like this to your /etc/fstab using "nano /etc/fstab":
remotename:/home /mnt/net nfs user,noauto 0 0
where remotename is the other computer.
Plug in the cable and reboot all systems. To test the network, try pinging the other computer. For example, type "ping -c 10 remotename", where remotename is the remote computer's host name (again). If you see some lines appear every second for 10 seconds, and they're not error messages, your network is okay. To mount the other computer's file system, use "mount /mnt/net" as a normal user (if you set this up). You're done! Check the end of this guide for some cool network tricks you can perform. If it didn't work, check the Trouble section.
Yes, you can safely mix Debian and Mandrake machines on the same network. I do it a lot. To do that, choose which directions given here to follow based on which computer you are running on.
TROUBLE?
If you can't connect at all, check the cable. If you have the RJ45 type of port, there is usually a light that lights up on the cards and the hub/switch when the right kind of cable is connected on both ends. If you don't see this light lit on a computer with the cable securely attached at both ends, you are probably not using the right kind of cable.
Are you getting a connection that you think is too slow? I was able to boost my speed quite a bit by double-checking my 3com Ethernet card's driver settings. When I did this, I found that the default module parameters were forcing it to use the slowest speed available, 10 Mbps. While this is much faster than a parallel port network, it wasn't the highest speed both Ethernet cards could handle. (I found out the 3com card actually did support 100 Mbps connections when I looked at the lights on the back that told me what speed the connection was.) So, I adjusted the settings to remove the forced connection speed, and now both my Pentium II's 3com Boomerang card and my laptop's Realtek 8139 card connect at the full 100 Mbps they support. So, check your driver settings.
If one node on the network uses a token ring card, that node will not work on an Ethernet network. Some token ring cards, such as the IBM Tropic, have an RJ45 port that looks like an Ethernet port, but it really isn't compatible with Ethernet. You can usually tell a token ring card by its ports on the back; most (all?) token ring cards have a female nine-pin D-shaped connector that looks like an Apple II series mouse/joystick port or a CGA/EGA video connector.
COOL TRICKS
Here's how to do remote logins and how to use the remote access features of the X Window System.
Doing a remote login (using one computer as a terminal to another)
At a command prompt as any user, type 'ssh name_of_remote_computer', substituting the name of the computer you want to take over for name_of_remote_computer. This will prompt you for your account password on the other computer if you have an identically-named account on the other computer. If not, use the '-l' option with 'ssh' to specify which account you want to log in to with 'ssh'. If you get a 'ssh: command not found' error, go to http://www.openssh.org and download OpenSSH. If you received an error message about not being allowed to connect, and you're running Debian on the remote computer, you need to type 'dpkg-reconfigure ssh' as root on the remote computer and tell it to start 'sshd'. If you use Mandrake, make sure the "ssh-server" package is installed.
If all went well, have fun! To quit the remote shell, type 'exit'.
Sharing your X session part 1: starting your programs from the computer on which it's going run
Start up an X session on the computer on which you want the programs to display. You do not need X running on both computers, though it is fun to play with this when both are running X! You should be running this as a normal user!
In a terminal window, such as the Konsole or an xterm, you will need to use 'xhost'. If you want to share your X display with anyone (NOT recommended for security reasons if you're connected to the Internet or another large network), type 'xhost +' ('xhost -' undoes this).
From a command prompt as a normal user on the computer that is going to run the program, use this syntax: 'DISPLAY=name:0 command', replacing name with the name of the computer that is going to display the program and replacing command with the command you are going to run. For example, to run xterm on 'one' but to display it on 'two', type this on 'one': 'DISPLAY=two:0 xterm'.
Sharing your X session part 2: combining the remote login with sharing your X session (starting the program from the computer you wish to display it on, but the program is actually running on the other computer)
As usual, start the network.
On (what's going to be) the remote computer, become root (su), and type “nano /etc/ssh/sshd_config” and change the “X11Forwarding no” line to “X11Forwarding yes”. Run “/etc/init.d/sshd restart” to make the setting take effect.
On the client computer, run “ssh -X” as a normal user to log into the computer and have X programs show up on the desired computer. Yes, the “-X” has to be uppercase.
Type the command to run the program you want to run over the network. If you want to keep the terminal window free (for example, to run multiple programs from the same shell), you can put an & at the end of the command.
Note that programs that require the 'xvidmode' and/or the 'xshm' extensions will probably not work over the network!
Easy File Access if you use KDE (or, "fish"ing your files to/from networked computers)
If you use KDE 3.0 or later, you can use Konqueror to access your files using a shell account on another computer. However, it is still 100% graphical, and you don't have to type a single command (except the initial address). You navigate and operate on it just like any other file system. For this to work, you will need the following:
OpenSSH properly installed and configured on both computers
KDE 3.0 or later on the client computer
A sh-compatible shell on the server. GNU Bash, which is included in every major Linux distribution, will work. Other shells that might work include ash, zsh, pdksh, and ksh.
The standard Unix commands on the server, like cp, mv, sed, ls, and others. You should already have these!
A network connection, of course
To use this feature, type "fish://remotehost" in Konqueror's address bar, replacing remotehost with the name of the server. You will be prompted for the user name and password of the remote shell account you wish to use. Note that, unlike NFS, you do not need to have an account with the same name on both computers. If you successfully log in, you should be able to access the remote computer's files.
SHARING A PRINTER USING CUPS
Setting up a networked printer is very easy using CUPS. CUPS is an advanced print spooler that offers everything most other print spoolers support, and more. If you have a modern version of Debian, you should have it (install the "cupsys" packages). Mandrake and Fedora use CUPS as their default print spooler.
If you're using an HP printer, please visit http://hpinkjet.sourceforge.net first and download and install the drivers for your printer. If you don't do this, your printer may not work to its full capacity. (Besides, the folks at HP are very supportive of Linux, so you should not have trouble with this. Their drivers are under a GPL-compatible BSD-type license, so you won't pollute your system.)
SETTING UP THE COMPUTER THAT THE PRINTER IS ATTACHED TO ON DEBIAN OR ANY OTHER LINUX DISTRIBUTION
To set up a local printer, get on the computer that the printer is attached, go into a Web browser and go to the address "http://localhost:631" (or you can just click this link that was generated by OpenOffice.org automatically). This will work on any computer with CUPS, even if that particular machine has no Internet connection. If you already have your printer set up with CUPS and it works, you may skip to step 6.
Next, click on "Do administration tasks". You will be prompted for your root password, so use "root" as the user name and your root password as the password.
Click "Add Printer". Enter a printer name (the one that will uniquely identify it to CUPS) and a description. "Location" is optional; it's just a comment field. Click "Continue".
Select the port your printer is plugged in to. If it's a USB printer, it will only show up if you had it plugged in on start-up. To get CUPS to recognize a USB printer in the wizard, you need to reboot with the printer connected. (They should fix that...) However, after the printer is set up, you can plug and unplug the printer as you please. Anyway, click "Continue".
The rest is self-explanatory. When you've finished the set-up, proceed with step 6.
Take note of the name (not description) of the printer you want to share.
Become root in a console session (hint: "su").
We need to allow the client computer to send print requests over the network. Type "cd /etc/cups" and then "nano cupsd.conf". Towards the end, you should see a line that says "<Location />". That's the section we're interested in. At the end of that section, add a line that says
Allow From 192.168.0.1
if the printer is attached to the second computer, or
Allow From 192.168.0.2
if it's attached to the first.
Save and exit.
Type "/etc/init.d/cups" immediately followed by the Tab key, immediately followed by " restart". This is necessary because the CUPS script is called different things on different distributions. This should allow print requests from the other computer without a reboot.
SETTING UP A CLIENT COMPUTER THAT RUNS DEBIAN, ET AL
Go to the other computer. Again, go into the web browser to the URL "http://localhost:631". (Hint! You can click the link that OpenOffice.org generated when I typed this!) =)
Click on "Do administration tasks". You will be prompted for your root password, so use "root" as the user name and your root password as the password.
Click "Add Printer". Enter a printer name (the one that will uniquely identify it to CUPS) and a description. To make things easy, I use the same identifier as the other computer uses with "net" added to the end of it. For example, my HP DeskJet 3845 is known as "dj3845" on the computer it is attached to, and it is "dj3845net" on my laptop, the client. "Location" is optional; it's just a comment field. Click "Continue".
When asked for the interface, select "Internet Printing Protocol (ipp)". Click "Continue".
In the text box, I'd use the format of "ipp://hostname/printers/name", replacing "hostname" with the name of the other computer and "name" with the name of the printer on the other computer. Leave "printers" as-is! Type the required information, and then click "Continue".
For the "Make" of the printer, select "Raw". Click "Continue".
For the "Model", use "Raw Queue". Click "Continue". (The necessary print driver should already be installed on the other computer, so you should just use the raw queue driver. The raw queue driver is a dummy driver that means "no driver".)
You should be finished. Try printing a test page. This may take a while. If it works, congratulations! You have just set up a networked printer. Note that in order to print, you must have both the client and the server up and running and the network must be up.
SETTING UP THE COMPUTER THAT THE PRINTER IS ATTACHED TO ON MANDRAKE
Most of the printer set-up on Mandrake is automatic, so you won't have to do much here. Make sure all your printers are connected and turned on, and go into the control center (Star menu, System, Configuration, Configure Your Computer), and go to Hardware, then Printers. It's pretty self-explanatory. Make sure you allow other computers to access the printer!
SETTING UP A CLIENT COMPUTER THAT'S RUNNING MANDRAKE
It's easy here, too. Go into the control center, and go to Hardware, then Printers. It may auto-detect the printer, but it may not. If it doesn't detect the printer, go into the printer configuration, and turn on networked printer support. You may also want to disable the "local CUPS daemon" to save resources on the client. Also, if you're having trouble, make sure the server is set to allow access from the computers you're using.
Well, that's it for now. Networking is quite fun, but it can get a bit annoying at times. When I started using Linux in early February, 2004, I never would have guessed that I'd have a complete home network a year later.