[Courses] [Networking] Lesson 4 - Phase 2 - DEBIAN

Hamster hamster at hamsternet.org
Wed Jul 23 16:40:59 EST 2003

## Phase Two - For Debian ##

# Step One -  Hostname #

First thing we'll do is tell the computer what its own name is. This is the 
name you thought of in Step 1 of Phase 1.

The file we need to edit is

This file should contain nothing more than the hostname you've chosen for 
the machine. If need be, remove any existing text so the hostname you add is
the only existing line.


Activate this setting by running the following two commands as root:

hostname --file /etc/hostname
su -

The hostname command manually sets the name of your computer to the value
present in the /etc/hostname file. Now you know why I was adamant that file
should only contain one line! 

Logging in again (the su -) makes the computer's new hostname appear in the 
bash prompt.


# Step Two - IP Address and Gateway #

Now we enter the information gathered in Steps 2 and 4 of Phase 1. They're
combined because they both get entered into the same file. 

The first thing we need to work out is the name of the interface that we're 

If your computer only has one network card, then there's a 99.99% chance the
interface's name is eth0. However if your machine has multiple cards, (as is
possibly the case with the gateway machine), you'll first need to determine
which network interface is the one connected to your internal network. If
you're not sure how to do this, email and we can work it out.

We need to edit the file:

This file is divided into sections, one for each network interface, and
contains the configuration data for those interfaces. You'll see at the very
top of the file an entry for the loopback interface, added by the
installation process.

We need to add a new section for the interface we're configuring. Before you
begin, just take a minute to look the file over. There's a chance there's
already an entry for the interface present, in which case you can either
delete the existing entry or modify it with its new details. Just make sure
the interface is not listed twice, and there are no conflicting entries for
it, such as two IP addresses. When in doubt, ask.

Below is what the section for the interface needs to look like. Any time you
see a # symbol (in any file), whether it be at the start of a line or in the
middle, all the text that follows is simply a comment and is ignored by the
computer. The comments below don't need to be typed in, but I do hope you
read them! 

# Excerpt from /etc/network/interfaces -------------------------------------

auto eth0 
# This line causes the interface to be initialised on booting. Without this
# line you'd need to manually start the network card every time you switch
# the computer on. Dont forget to replace the eth0 with the right interface
# name if required.

iface eth0 inet static
# This signifies the start of the entry for this interface. Replace eth0
# with the right name if required.

	address <IP address>
	# This is the IP address you chose for this machine.
	netmask <netmask>
	# This is the subnet netmask that goes with the range of IP
	# addresses you're using. It's vitally important that all computers
	# on your network have the same  netmask.
	gateway <gateway>
	# This is the IP address of the gateway machine from step 4. It too
	# needs to be the same for all your computers. This line does not
	# need to be included on the gateway machine itself, but it does no
	# harm if you leave it in.

# End of excerpt -----------------------------------------------------------

If you're curious as to how this file works, all you need to know should 
be included in the document:
and the command:

man interfaces


Activate your network card with this new IP address using the following
commands (as root):

ifdown eth0
ifup eth0
ifconfig -a

Don't forget to substitute eth0 with the correct interface name if need be.

The first command halts eth0 and clears out its settings. The second command
starts eth0 working again with the new settings. The last command displays
the current settings of your network card. Use it to check everything is as
it should be.


# Step Three - Name Resolution #

In this, the last step, we use the data gathered at Step 3 of 
Phase 1 to enable name resolution.

# Step 3 - Stage 1  - DNS Servers #

If your ISP dynamically assigns you an IP address when you connect to the
internet, do not complete this DNS Server stage on the gateway computer. You
still need to finish it on all the other machines on your network, but NOT
on the gateway. The file we edit in this stage is automatically updated on
your gateway machine every time you connect to the internet.

The file to edit (be careful of the correct spelling) is

All you need to do is add the following lines:

nameserver=<1st dns server>
nameserver=<2nd dns server>   

You can add as many nameserver= lines as you have DNS servers.

The file may contain a few lines in addition to your nameserver= entries. In
all probability you can leave those lines alone, but as before, just use
your common sense, and ask if you're not sure.

# Step Three - Stage 2  - Computers on our Private Network #

In this last stage we edit the file:

We need to make two changes to this file.

The first is the addition of the computer's hostname to the line that begins
with the text This is the same hostname you entered into the
/etc/sysconfig/network file, which should also be the hostname that appears
in your bash prompt if you activated the changes made in Step 1.

This line is quite probably the very first line of the file. It
will already have some other names in it, including localhost. You need to
add your hostname to this line. It doesn't matter if it's the first name or
the last, but make sure it's on this line. 

Your completed line should look similar to the one below.	localhost <hostname>

The second change we need to make to the hosts file is to add the list of
computers and their IP addresses that we created in Step 3 of Phase 1. If
you want to do this the hard way, then you can type them all in manually,
copying from your diagram. Or we can do it the easy way, by simply appending
the mynet.txt file we created to the end of the hosts file.

If you choose the easy route, you can add the contents of your mynet.txt 
file to the end of /etc/hosts by running the following command. Don't forget
to the include the full path to the mynet.txt file if needed.

cat mynet.txt >> /etc/hosts  

The double >> is very important. If you only type one ">", then you will 
wipe out your existing hosts file. You've got a backup right?


Neither the hosts file nor resolv.conf need activation. They get examined
anew each time a computer needs to look up a name.


Technically that's the end of Step Three. I suspect though a good many
people are wondering just how they're meant to get a copy of their mynet.txt
file to each machine on their network. You have several options, including
the following:

* Sneakernet. This is a fancy way of saying copy it onto a floppy disk.

* scp. Use scp (a component of ssh) to copy the file over the network.

* nc. (also called netcat). Another method of copying over the network.

If you need more detailed instructions on any of these methods, you know the
drill. ASK!


As promised, here is a copy of the config files on one of my machines. 

constantinople:~# cat /etc/hostname

constantinople:~# cat /etc/network/interfaces
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
auto lo
iface lo inet loopback

# This is the interface going to the internet.
auto eth1
iface eth1 inet dhcp

auto eth0 
iface eth0 inet static

constantinople:~# cat /etc/resolv.conf
search arnhem.chello.nl
nameserver 212.142.xxx.yyy
nameserver 212.142.zzz.aaa

constantinople:~# cat /etc/hosts             localhost constantinople

# The following lines are desirable for IPv6 capable hosts
# (added automatically by netbase upgrade)

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
# mynet.txt ------------------        constantinople      mushu      kokomo      sadie      tris      sooty      bob


We're ready to move on to Phase Three, in which we test to see if our
network is working properly. There is no point at all commencing Phase Four
(setting up the gateway to allow our computers to access the internet) if
our computers can't communicate with each other.

More information about the Courses mailing list