If your web browser formats this page incorrectly, try viewing the
page source. In netscape 4, click the view menu, then click page source.
setting up a simple ethernet with Linux
This is not the only way to set up a Linux network. Linux's networking
features are very flexible, so there are many possible ways to set up a
network. But it will take you years to evaluate all possible ways to set up
a network and choose the best method; most people will prefer to do
something quick that works, and get on with their lives.
A simple ethernet network is easy to set up and run. However, if you add a
gateway to another ethernet network, a PPP connection to the internet, and a
parallel port connection to a laptop computer; then you have a mess. If you
want a network that is easy to set up and run, THEN KEEP YOUR NETWORK
SIMPLE! Linux is capable of running insanely complicated networks, but only
a lunatic would want to.
Even if you do not have a network, you still should set the hostname and
activate the loopback device, because some programs require them for no
apparent reason. inn and kwm require the loopback device. xlock requires the
hostname.
You need an ethernet card in each computer, and cables and hubs to connect
the ethernet cards together. If you need more information about selecting
ethernet cards, hubs, or cables, see the Linux Documentation Project's
ethernet howto.
For each computer, you need to choose a driver for the ethernet card. The
ethernet howto lists which driver to use for many ethernet cards, although
it does not actually tell you the name of the driver module file; and there
is more information about drivers in /usr/src/linux/Documentation. Or you
can look in /lib/modules to see if you already have a net module with a name
similar to the name of your ethernet card. Or you could 'cd /usr/src/linux',
then 'make config' or 'make menuconfig', and look at the list of network
drivers.
For 1.x kernels, the driver for the ethernet card should be compiled into
the kernel. For 2.x kernels, you can either compile the driver into the
kernel, or compile the driver as a module; most people compile the driver as
a module. Find out if your linux distribution already includes a suitable
kernel and/or modules. If not, you will have to compile the kernel and/or
modules yourself.
If you plan to use the driver as a module, you should edit the file
/etc/conf.modules, and add a line like 'alias eth0 3c503' (do not include
the quotes), but replace '3c503' with the name of the driver for your
ethernet card. Note that Linux expects the name of the module file to be the
name of the driver plus '.o', and Linux expects the module file to be in
/lib/modules/_your_kernel_version_/net. For example, my module file
is '/lib/modules/2.0.32/net/3c503.o'.
You probably should add another line to /etc/conf.modules like
'options 3c503 io=0x310 irq=5 xcvr=0' (do not include the quotes),
but change '3c503' to the name of your driver, and change
'io=0x310 irq=5 xcvr=0' to the options for your driver.
/usr/src/linux/Documentation/networking/net-modules.txt lists
the possible options for the various driver modules.
Choose a hostname for each computer on the network. The hostname is the name
of the computer. Most people name their computer after a famous
mathmetician, a favorite cartoon character, a girlfriend, an imaginary
girlfriend, the work that the computer usually does, the person who usually
uses the computer, the manufacturer or seller of the computer, or the
location of the computer. Each computer on the network must have different
hostname. A computer may have the same hostname as a computer on a different
network. If you have a complicated network divided into subnetworks, a
computer may have the same hostname as a computer on a different subnetwork.
The hostname may include letters and numbers, but the first character should
not be a number. Most people use small letters only; I think capital letters
are the same as small letters. The hostname should not include any spaces or
punctuation except '_' and '-'. Some hostnames I have seen in the past:
pythagoras, anaximander, claudia, lydia, darkstar, gandalf, cs, www, ftp,
ftp2, telnet, gopher, simtel, sunsite, metalab, tsx, oak, gatekeeper,
altavista, granite, mousehouse
You need to tell each computer what its hostname is, using the hostname
command. Your computer will forget its hostname when you turn it off; thus
you should put the hostname command in your startup scripts. Slackware 2.3.0
suggests you put the hostname in the file /etc/HOSTNAME, and put the command
'hostname $(cat /etc/HOSTNAME)' in your startup scripts. Redhat 5.0 suggests
you put the command 'HOSTNAME=_your_hostname_here_' in
/etc/sysconfig/network, and put the command 'hostname ${HOSTNAME}' in
/etc/rc.d/rc.sysinit.
Choose an IP number for each computer on the network. Each IP number is like
x.x.x.x, where x is a number from 0 to 255. For example: '203.78.123.21'. Do
not pick numbers at random. Different numbers have different meanings; and
Linux expects computers on the same network to have similar but not
identical IP numbers. For a simple ethernet network which is not part of a
larger network, you probably want Linux to assume that the netmask is
255.255.255.0 and that your network is not part of the internet. Therefore
you should choose IP numbers like a.b.c.d; where a is 192; b is 168; c is a
number from 0 to 255, and c is the same for every computer on the network;
and d is a number from 1 to 254, and d is different for every computer on
the network. For example, you could assign 192.168.5.1 to the first
computer, 192.168.5.2 to the second computer, 192.168.5.3 to the third
computer, etc.
The netmask is used to divide the IP number into a network part and a host
part. For example, if the netmask is 255.255.255.0, then the network part is
the first three parts and the host part is the last part of the IP address;
if the IP number is 192.168.78.32, then the network part is 192.168.78, and
the host part is 32. All computers on a network must have the same network
part of their IP addresses, and each computer must have a different host
part. If the network parts are different, Linux assumes that the computers
are on different networks. Thus the netmask is used to determine if two
computers are on the same or different networks. If the netmask is
255.255.255.0, then 192.168.4.4 and 192.168.4.5 are on the same network, and
192.168.5.4 is on a different network. If the netmask was 255.255.0.0, then
all three computers would be on the same network. You can tell Linux to use
a different netmask, but 255.255.255.0 is a good netmask for a simple
ethernet network; there is no reason to use a different netmask.
If you have a complicated network which consists of more than one network
networked together, then the IP numbers for the various subnetworks need to
be different enough so that Linux recognizes that the computers are on
different networks. For example, you could assign IP numbers 192.168.0.1
through 192.168.0.254 to computers on the first network, 192.168.1.1 through
192.168.1.254 to computers on the second network, 192.168.2.1 through
192.168.2.254 to computers on the third network, etc.
The Linux Documentation Project's Network Administrator's Guide and net
howto have more information about selecting IP numbers.
If your network is part of a larger network like the internet, then you do
not choose your own IP numbers; you must ask the people who administer the
larger network to choose IP numbers for you.
Use a text editor to edit or create /etc/hosts. List the IP numbers and
names of every computer on your network. /etc/hosts should look like this:
#IP number hostname
127.0.0.1 localhost
192.168.1.1 apple
192.168.1.2 banana
192.168.1.3 carrot
Lines beginning with '#' are comments. That /etc/hosts lists three
computers: apple, banana, and carrot. Also note the line
'127.0.0.1 localhost'. It is not possible to give a short explanation of why
that line is there. Make sure that line is in /etc/hosts on every computer
on the network, and if you really want to know why it is there, go study
networking. For a simple ethernet network, the file /etc/hosts should be the
same for every computer on the network.
In a complicated network, computers might have more than one IP number or
hostname. If a computer has more than one IP number, it should be listed
more than once in /etc/hosts; there should be a seperate line for each IP
number. If a computer has more than one hostname, all the hostnames should
be listed with each IP number. If the network has a name, the network name
might be combined with the hostname, and the result is like an alternate
hostname (the result is the fully qualified domain name). For example, if a
computer has a hostname of 'dog', and the computer is on a network named
'x.net', then the /etc/hosts line might look like this:
192.168.54.8 dog dog.x.net
In a simple ethernet network, there is no reason to have more than one IP
number or hostname for each computer.
If you add another computer to the network, you need to add the new computer
to /etc/hosts on every computer on the network. If you expect to add more
computers in the future, it might be easier to assign hostnames and IP
numbers now, and add these hostnames and IP numbers to /etc/hosts; then when
you add a new computer, you will not have to go around your network and add
the new computer to all the /etc/hosts files because the new computer will
already be included. In other words, it is not a problem if /etc/hosts
includes computers which do not exist.
For a large or complicated network, it is a lot of work to edit all the
/etc/hosts files on the network. Thus large complicated networks usually do
not use /etc/hosts; they use a nameserver like named instead.
Some people choose names for their networks. If you have a large,
complicated network divided into subnetworks, and you have names for each of
the subnetworks; then when you set up routes you can use the network names
instead of the network numbers; this makes it easier to set up routes
because the names are easier to remember and understand than the numbers.
The network names with their corresponding network numbers are put in
/etc/networks. But for a simple ethernet network, there is no need for a
network name or for /etc/networks.
You need to have a file named /etc/host.conf. It should have two lines like
this:
order hosts,bind
multi on
Actually, for a simple ethernet network, you only need one line like this:
order hosts
But the longer version works in almost all computers in almost all networks,
so many people say to always use the longer version. If you use the shorter
version, and in the future your network becomes more complicated, then you
will probably have to change /etc/host.conf. But if you use the longer
version, you probably will not need to change /etc/host.conf if your network
becomes more complicated. For example, 'bind' will be needed if you add a
PPP connection to the internet.
Some people will tell you to create /etc/resolv.conf. But the main function
of /etc/resolv.conf is to tell Linux the IP numbers of your nameservers. In
a simple ethernet network, you will not have any nameservers; thus you do not
need /etc/resolv.conf.
You need to activate the loopback device. Put the following commands into
the startup scripts of every computer on the network:
ifconfig lo 127.0.0.1
route add 127.0.0.1
Very few programs use the loopback device, so you probably do not need the
loopback device. But you should always activate the loopback device anyway,
even if you do not have a network, because you never know when a program is
going to use the loopback device.
You need to activate the ethernet device. Put the following commands into
the startup scripts of every computer on the network:
ifconfig eth0 _IP_address_
route add _network_address_
But change '_IP_address_' to the IP address of the computer. Each computer
on the network should have a different IP address; therefore each computer
should have a different ifconfig command. Or you could use the hostname
instead of the IP address. Or you could set an environment parameter to the
IP address or the hostname, then use an ifconfig command like
'ifconfig eth0 $HOSTNAME'; then the ifconfig command would be the same on
every computer. For the route command, replace '_network_address_' with the
network address. To find the network address, use the netmask to split the
IP address into a network part and a host part, then replace the host part
with 0; the result is the network address. For example, if the IP address is
192.168.76.23 and the netmask is 255.255.255.0, then the network part of the
address is 192.168.76, and the network address is 192.168.76.0. The network
part of the address should be the same on every computer on the network;
therefore the network address should be the same on every computer on the
network; therefore the route command should be the same on every computer.
You may be thinking that ifconfig and route commands are silly. Surely it is
obvious that if some data needs to be sent to some other computer on the
network, then the data needs to be passed to the device driver for the
ethernet card and be sent out onto the network. Why do we need to tell Linux
that network data needs to be sent to the network? The answer is that
ifconfig and route commands are for complicated networks. If a computer has
more than one network connection, the computer is probably connected to more
than one network, and probably has more than one IP address. Which IP
address goes with which network connection? ifconfig determines which IP
address goes with which network connection. If some data needs to be sent to
some other computer, which network connection should be used? route
determines which network connection will be used, when to use a gateway,
what gateway to use, etc. Sometimes, in a complicated network, data is not
sent using the obvious route; that is why Linux does not set up the obvious
routes automatically. For example, suppose you have two PPP connections to
the internet, and you have some data to send to the internet. Which PPP
interface should you use? You should use neither; the data should be sent to
an equalizer interface, which should then divide the data in half and send
half to each PPP interface. In a simple ethernet network, routing is
obvious, but you still have to tell Linux how to set up the routes, because
Linux cannot tell if your simple network is a simple network, or if it is
the beginning of a complicated network.
Setting up routing for a complicated network is very complicated. Therefore,
complicated networks usually use a routing daemon like routed or gated. A
routing daemon finds out how many network connections the computer has, and
what networks they connect to; finds out if any other computers on any other
networks are running routing daemons; exchanges data with any other routing
daemons it finds; and then the routing daemon analyzes all the data it has
collected and sets the routes for you. Routing daemons are especially useful
for networks which change frequently. But for a simple ethernet network, it
is easier to set the routes yourself.
You should run inetd on every computer on the network. inetd requires
configuration files named /etc/inetd.conf and /etc/services. Most Linux
distributions include these files, so you probably already have them. So all
you have to do is put the command 'inetd' in the startup scripts of every
computer on the network. inetd allows other computers to use files and other
resources and services on the computer which is running inetd. A computer
should run inetd if it is going to provide services to other computers, but
a computer does not need to run inetd in order to use services from other
computers. If your network is a business network which consists of a few
main servers and many workstations, then you should run inetd on the
servers, but maybe you do not need to run inetd on the workstations; because
the workstations use services from the servers, but the servers probably
never use services from the workstations. Why would you want to telnet to
the computer in the next cubicle when it is exactly the same as the computer
in your cubicle? For a home network you probably want to run inetd on
every computer.
You may want to run NIS, Network Information Services, also called yp or
yellow pages. NIS allows you to have one password file for the network
instead of a seperate password file for each computer. This allows users to
use any of the computers on the network without having to have a different
account on each computer. It allows users to use the same home directory no
matter which computer they are using. NIS also allows you to have one
/etc/hosts file for the whole network, and also other configuration files;
this makes it easier to administer the network. To run NIS you need to run
programs like ypserv and ypbind. For more information see the NIS howto.
If you want a computer to share its files with other computers, edit
/etc/exports with a text editor. Each line lists a directory which can be
accessed from other computers, what other computers are allowed to access
the files in the directory, and options. The options must be enclosed in
paraentheses. If you do not list what computers are allowed to access the
directory, then all computers are allowed to access the directory; this is
probably what you want for a simple network. For example, for a home
network, you might want a line like '/ (rw,all_squash)'. If you are
setting up a central file server for a business network running NIS, you
might want something like '/usr (ro)' and '/home (rw)'. The quotes are
not part of the lines. You probably want to use the option all_squash if you
are not running NIS, because the UIDs and GIDs will be different on
different computers if you are not running NIS. You also need to run nfsd
and mountd from your startup scripts. For more information see man exports
and the NFS howto.
If you want a computer to access files from other computers, you
mount an NFS (Network File System) with a command like:
mount foo:/usr /usr_from_foo
which mounts directory /usr from computer foo as directory /usr_from_foo.
For email you need to run a mail transfer program like fetchmail, procmail,
sendmail, qmail, or smail to transfer mail between computers. Most people
use sendmail. Smail is the second most popular. Smail has fewer features
than sendmail. Some people say that smail is easier to configure than
sendmail; other people say it is not. To read and write email, you need a
mail reader like pine, elm, and mh.
To exchange usenet or other news between computers, you need to run a news
server like inn or cnews. To read and write news you need a news reader like
tin, trn, nn, etc.
Some people say you should create /etc/hosts.deny and /etc/hosts.allow for
security reasons. But for a simple ethernet network, the best security is to
keep all of the computers on the network in one building, and lock the door,
and do not let strange people into the building, and do not have any
connections to any other networks; and then you do not need /etc/hosts.deny
or /etc/hosts.allow.
If you want to keep your network simple, but need to have some things which
make the network complicated, then it may help to put all the complicated
connections on one computer; then only that computer needs to deal with the
complicated stuff, the other computers only need a default route to the
computer with the complicated connections. For example, if you have a
gateway to another network and a PPP connection to the internet, then the
gateway and the PPP connection to the internet could be on the same
computer.
You may want to add PPP internet access to one computer and share it with
the other computers on the network. The computer with internet access needs
IP masquerading, the others do not. PPP should be configured normally on the
computer with internet access, not on the others. The other computers need
to have the internet nameservers listed in /etc/resolv.conf. The other
computers need a default route to the computer with the internet access,
which is a gateway; thus each of the other computers would have a command in
the startup scripts like this: 'route add default gw 192.168.65.1', only
replace 192.168.65.1 with the IP number or hostname of the computer with the
internet access. However, security is a problem. If you have a small network
without internet access, security is not a problem; because on a small
network you can probably trust all users. If you have internet access but
not network, security is not a problem; because you probably do not have any
network services which could be abused. But if you have both internet access
and a network, then security is a problem; so you should use firewalling,
proxying, /etc/hosts.allow, /etc/hosts.deny, etc. For more information, see
man 5 hosts_access and the firewall and masquerade howtos.
If you want to have more than one ethernet card in your computer, Linux can
do it, but it makes your network more complicated. You have to tell Linux
which ethernet card is which; and when to use one and when to use the other.
And the cards should have different IRQs and IO addresses. Here is an example
of what you might put in /etc/conf.modules if both cards use the same driver:
alias eth0 3c503
alias eth1 3c503
options 3c503 io=0x310,0x330 irq=5,9 xcvr=0,0
Here is an example of what you might put in /etc/conf.modules if the cards
use different drivers:
alias eth0 3c503
options 3c503 io=0x310 irq=5 xcvr=0
alias eth1 driver_name
options driver_name driver_options
A computer with more than one ethernet card will have more than one ethernet
address, so you need to include 'multi on' in /etc/host.conf.
If you want to connect two simple ethernets together, you can either make
them into one big simple ethernet, or you can connect them with a gateway. A
gateway is a computer which is connected to more than one network, and can
read data from one network and write the data to another network. The
gateway needs to have two ethernet cards, one connected to each network; and
two IP numbers, one for each network. The two networks should have different
network addresses (remember, each computer has an IP address, you use the
netmask to find the network address from the IP address, each computer on
the first network should have the same network address, each computer on the
second network should have the same network address, but the network
addresses of the first network should be different from the network
addresses of the second network). Combine the /etc/hosts files from both
networks, and put the combined /etc/hosts file on every computer on both
networks (or use a nameserver). The gateway needs two ifconfig commands
and two route commands, one ifconfig command and one route command for each
network. The other computers need an ifconfig command and a route command
for the network they are connected to, plus a second route command for the
other network. The second route command might look like this:
route add 192.168.5.0 gw 192.168.6.1
That means that computer 192.168.6.1 is a gateway to network 192.168.5.0;
data for computers 192.168.5.1 to 192.168.5.254 will be sent to computer
192.168.6.1. You can use the hostname instead of the IP number and the
network name instead of the network number; using names might make the route
command easier to understand. On each network, the second route command will
be the same for every computer except the gateway; but each network will
have a different second route command. Or you could use a route command
like:
route add default gw 192.168.6.1
That means that computer 192.168.6.1 is a gateway to all other networks;
any data for any computer not on the local network will be sent to computer
192.168.6.1.
Some people think that your domain name is the same thing as your network
name. For example, you might think that a computer with the fully qualified
domain name of foo.bar.gleep.blub is a computer with a hostname of foo,
attached to network bar, which is a subnetwork of gleep, which is a
subnetwork of blub. Wrong! foo.bar.gleep.blub means there is a computer with
hostname foo; computer foo is listed in database bar; database bar is listed
in database gleep; and database gleep is listed in database blub. So if you
wanted to know the IP address of foo.bar.gleep.blub, you would contact the
root database and ask how to contact database blub, then you would contact
database blub and ask how to contact database gleep, then you would contact
database gleep and ask for the IP address of foo. The internet uses
databases of databases because there are too many computers on the internet;
it is not practical to list all the computers on the internet in one
database. Often one database will list the computers on one network; thus
the domain is the database about the network; thus some people become
confused and think the domain is the network. Your domain is the internet
database which lists your computer. If your computer is not listed in any of
the internet databases, then you do not have a domain. In other words, if
your computer is not part of the internet, you do not have a domain, even if
you have a network.
However, many people frequently use the word domain incorrectly, so the word
domain has several meanings. For example, suppose you have a computer in
your cubicle at the Drudge corporation. Your computer is connected to Drudge
Corporation's ethernet, drudge-net. Drudge-net is a private network; it is
not part of the internet but it does have internet access through an ISP
named acme.net. Your email address is you@drudge.com. What is your domain?
You have no domain because your computer is not listed in any of the
internet databases of computers. However, some people would say your domain
is acme.net, others would say your domain is drudge-net, others would say
your domain is drudge.com.