Computer
Networking
and
Practical
Security

Fall 2006
course
navigation

GettingStarted

Or, "No I Will Not Fix Your Computer"

This section provides an introduction to some common tools and two command line processes for setting up a Linux machine's networking. The first, using DHCP, is trivial and should be familiar to most students even if this is their first time doing it from the command line. The second requires using many of the network tools and files introduced in UnixRefresher.

Contents

Introduction to DHCP

DHCP stands for Dynamic Host Configuration Protocol and allows new computers on a local network to have their networking preferences configured automatically. This is incredibly convenient for administrators because it means they don't have to manually assign addresses or explain how to configure computers to a few hundred people, and convenient for users because they don't have to wait or scrounge up instructions. DHCP usually does more than just assign an IP address. It sets netmask, DNS server(s), and a default gateway as well.
When a device is configured to use DHCP, on network startup it broadcasts a DHCP request. If a DHCP server is on the local network, it will broadcast an offer, which has the device's MAC address, an IP assignment, lease time (after this time the device will need to make another request), the server's IP address, and additional information if requested[1].

Configuring Network Settings Via DHCP

First, become super user. Before we start modifying things, we want to disable the network, so in the /etc/init.d/ directory, run the "network" script with the option "stop". You should see output similar to the following:
# cd /etc/init.d/ # ./network stop Shutting down interface eth0 [ OK ] Shutting down interface eth1 [ OK ] Shutting down loopback interface [ OK ] #
We then modify the correct device config file in /etc/sysconfig/networking/devices/ (in this case we're setting up eth1, so this is ifcfg-eth1) to read as follows:
DEVICE=eth1 BOOTPROTO=dhcp IPADDR= NETMASK= ONBOOT=yes PEERDNS=yes GATEWAY= DHCP_HOSTNAME= HWADDRESS=**:**:**:**:**:**
The last three are optional. DHCP_HOSTNAME allows us to specify a server to accept offers from, in case there are more than one on the network. Depending on the type of interface, we may need additional lines as well. Wireless cards for example also require the following lines:
TYPE=Wireless ESSID= CHANNEL= MODE= RATE=
The technicalities of wireless networking are significantly more complex than their wired counterparts, and we'll limit ourselves to ethernet networks for the time being. Once we've saved the config file, we return to /etc/init.d/ and run the network script again, this time with the "start" option. The output should look something like this:
# ./network start Bringing up loopback interface: [ OK ] Bringing up interface eth0: [ OK ] Bringing up interface eth1: [ OK ] Determining IP information for eth1... done. [ OK ]
If we now run ifconfig, the eth1 section should now include a valid IP address and netmask, and if we try connecting to something, everything should function normally. That's it, we're done. Behind the scenes, this process calls the dhclient script, which follows exactly the protocol description above. If we desire, we can call this script directly, which can be useful if we want a new DHCP lease or to make sure our current information is still valid. The man page for dhclient is fairly extensive, and should provide ample instruction for its use.

Configuring Network Settings Manually

This time assume we don't have a DHCP server on our network, or we don't wish to use it. In this situation we'll need some additional information, as we need to set our address, subnet mask, default gateway, and DNS servers all by hand. The best way to do this, if it isn't provided by a sysadmin, is to inspect the settings of a computer already on the network. In fact, they can be copied over almost verbatim.
Like last time, start by stopping all interfaces (or at least the one you're setting). Edit the ifcfg-eth1 file as before, but with the following differences:
BOOTPROTO=none IPADDR=<IP address> NETMASK=<netmask> GATEWAY=<default gateway>
Naturally any line relating to DHCP configuration can be deleted or commented out with a "#" at the start of the line. The third and fourth lines above should be filled out with the information we gathered beforehand and the IP address must fall within our local network. The GATEWAY line can be ignored, but if so, each time you start up networking, we'll need to use route to add the gateway information like the following:
# route add default gw 10.1.2.1
Next, add our DNS server address(es) to the resolv.conf file in /etc/, one per line:
nameserver 10.1.2.2 nameserver 216.158.162.126 nameserver 10.2.0.2
If we have more than one, when a DNS lookup is necessary, they will be tried in order until either a result is returned or the list runs out. At this point we're ready to reactivate our device, so run "./network start" like last time.
If we were unlucky enough to choose an address that's already in use, a number of things might happen. If our network is smart it may ignore us completely and switches/routers may drop all traffic we send out. If not, we run the risk of getting the other device's intended traffic or it getting ours. If networking does not work properly after the above steps, it's worth trying another address or two before looking for other problems.

Sources and Further Reading

1) http://en.wikipedia.org/wiki/Dhcp
http://cs.marlboro.edu/ courses/ fall2006/networking/ private/ tableofcontents/ GettingStarted
last modified Wednesday December 6 2006 12:39 am EST