CTS 2333 (Unix/Linux Networking) Project #2
Static IP and Hostname Configuration

 

Due: by the start of class on the date shown on the syllabus

Description:

Each student has been assigned two hosts, one server and one client host.  In this project you will learn how to configure one of your hosts (we'll call it the server host, and your other system the client host) with static IP addresses, hostnames, and other networking parameters.  This setup will be used for the rest of the course.

Make sure you keep an accurate system journal of any and all changes you make to your system!  You will need to turn this in, along with the answers to the questions asked below.

For your static IP address to actually work, you must set other network parameters including a default gateway.  Other steps include setting a hostname and configuring the resolver (DNS libraries) with the IP address of your nameserver, and your default domain name.  Until you build a nameserver, you will need to update your /etc/hosts file with the names and IP addresses of all the hosts used in our classroom.  You can create this file from the information found at the Networking class wiki site, the “Networking Class Host Name List”.

The hostname and IP address you picked at the beginning of the term should be assigned to your server We won't be configuring your client host (your second computer) in this project, so it should continue to use DHCP as before.

Since version 11, Fedora doesn't enable the “network” service by default.  Instead the “NetworkManager” service is enabled.  This service doesn't support “static” IP configuration through Fedora 15 (even though it says it does; see bugzilla.redhat.com/show_bug.cgi?id=698199).

Before beginning this project you must disable NetworkManager and enable instead network.  Once you do this, you may (or may not) need to configure the network service for DHCP before networking will operate correctly.  You can use any GUI or other method to do this.

For Fedora 15, you use “systemctl disable NetworkManager.service”, then enable the older service with “systemctl enable network.service”.  You may need to install system-config-network with yum.  In addition, you can (and probably should) add “NM_CONTROLLED=no” to your ifcfg-<name-of-interface> file.

If you need help with this step, ask your instructor.

Directions:

Answer the following questions and perform the following tasks.  (For the answers to Solaris questions consult the man pages and the Solaris on-line documentation.)

Part I — Manually Setting Networking Parameters

In this part, you will learn how to change hostnames, addresses, and routes.  Since all networking parameters are stored in memory, any such changes will be lost after a reboot.

Before proceeding, make a copy of your current, working network setup: IP address and mask (output of “ifconfig” or “ip addr”), routing table (especially the default route), and the contents of /etc/resolv.conf, /etc/hosts, /etc/hostname, /etc/nsswitch.conf, and your NIC's config file /etc/sysconfig/network-scripts/ifcfg-nameOfNIC.  As usual, before you modify any files you should FIRST make a copy.  You can then record the output of “diff” to show your changes.

  1. From the command line (and without modifying any files), configure the NIC on your server with the static IP address assigned to you in class.  This step requires the use of the ifconfig command, or the ip addr add address/prefix-length dev interface command.  Here's an example using the new Linux ip command:
    # ip addr add 10.20.30.40/24 dev eth0
    # ip addr del your-current-IP-address dev eth0
    

    (Of course, you use the correct address, prefix length, and device, which may not be eth0.)  Note you should add first, then delete.  If you delete first, the NIC has no IP address and the default route may be deleted!

    Once set, verify your NIC has the correct address.  What command(s) can you use to verify the address assigned to a NIC?

    Make sure to keep track of all IP address assignments!  This is typically a separate document from any one system's journal.  This document should be kept current and include a “last revised” date.  However, with only two hosts to keep track of, you can just record the IP address assignments in your system journal.  (Consider putting that information in a table near the beginning of the journal, say near the partition map.)

  2. From the command line update your default route (or gateway).  This will be the same as your current gateway address as assigned by DHCP, so in the end you won't see any change.
    1. You can view the current routing table with the older “route -n” command, or the newer “ip route” command.  (While the newer Linux command does more and can show more, for this simple use I prefer the output format of the older command.)  What is your current (working) gateway (default route) IP address?
    2. First, set the default gateway to an invalid address.  Run the commands
      # ip route add default via 10.142.255.2 dev eth0
      # ip route del default via 10.142.255.1 dev eth0
      

      You now have no Internet access!  Take a look at your routing table to see the change you made.  However, you still have a route to the local network, so you can access other computers (and printers) in the room.  Run some commands to verify networking only works locally.  What commands did you run, and what were the results?

    3. You must reset your default route to the IP address of the classroom's gateway router (which should be 10.142.255.1).  This step is done using the same commands as in the previous step.  Once set, verify your system's routing table (make sure the default route shows and is correct).  What commands do you use to verify the default route?

      When checking the routing table, you make notice a long delay when displaying the default route.  This may happen when the network gateway doesn't have a DNS entry, and your system by default attempts to lookup the name for the gateway's IP address.  What is the option for the command to display the routing table, to cause it not to lookup DNS names?  (One way to fix this, is to add a name for the gateway IP address in the DNS system, or in /etc/hosts.  I often add a name such as “HCC-gateway” for this.)

  3. From the command line, assign your host a new hostname, using the hostname command.  (Don't use the new Linux command hostnamectl, as it will update files with your changes unless you use the right options.)  Use the name you picked previously and documented in the class wiki.  Note: the domain name is “GCAW.ORG”.

    What was the exact command line you used to set your system's hostname?

  4. Examine the current /etc/resolv.conf file.  This file is generated automatically when using DHCPWhat are the IP addresses of the DNS servers used?  What is the default domain name?

    Now examine the “hosts” line from the file /etc/nsswitch.confExplain in your own words what that line means.  (Hint:  Read the man page for that file.)

  5. Test your new IP configuration.  Try the command “traceroute YborStudent.hccfl.edu”.  This should show several hops, the first of which should be the classroom gateway.  If you don't get the expected output, verify your IP address, prefix (netmask), and default route again.  If necessary, you can start over by restarting networking (use "systemctl restart NetworkManager.service").  This should reactivate your DHCP configuration.  (Or you can simply reboot.)

Part II — Creating a Static IP Setup

At this point your hostname, routing, and your IP address are all set up and tested for a static configuration.  However, if you restart networking (or reboot), all your work will be lost.  You must now make your changes permanent by updating the various configuration files.  The files used vary by system; here we will configure your Fedora system, using the NetworkManager service installed by default.

Perform the following steps:

  1. Configure host names.  This is done on Red Hat systems by editing two files.  The first is /etc/hostname.  (The Linux command hostnamectl will update that file automatically if you use it.)  Contrary to Red Hat documentation, that file should not contain a fully-qualified DNS name.  Rather it should contain the host name without the domain name (so no periods).  With Red Hat-like systems, the name service looks up the fully qualified domain name or FQDN from the hostname you specify, in the file /etc/hosts.

    The whole concept of a hostname is confusing!  Before DNS or even Ethernet, a computer could be given a name, sometimes called the hostname or the nodename.  With DNS and NICs, a name is associated with each IP address assigned to each NIC on some computer.  This too is called the hostname.  So what is “the” hostname on a host with multiple IP addresses?  It is not well defined but is usually configured by the administrator to be one of the DNS hostnames.  Some systems will set the hostname by a reverse DNS lookup on the first NIC found with an IP address assigned (the first or last address).

    Next, you need to add some entries to the /etc/hosts file.  The format of that file can be found in the man pages.  Do not change or remove the entries already present (for localhost)!

    The domain name for our class is “gcaw.org”.  For a hostname of siegfried and an IP address of 172.16.0.10 the /etc/hosts entry you need to add should look like this:

        172.16.0.10  siegfried.gcaw.org  siegfried
    

    In addition to an entry for your own host, you need to add entries for all the host names for the whole class, including your instructor's.  The IP addresses and host names can be found on the class wiki site.  To avoid any DNS lookup problems, you can also add an entry for the gateway router.  (As mentioned above, I generally use a name such as “HCC-gateway” for the router.)  What is the final contents of your updated /etc/hosts file?

    What file(s) on Solaris are updated to contain the host's hostname and domain name?

  2. Configure your resolver library.  This is the name-to-IP-address lookup service. 
    1. Configure the resolver to use the /etc/hosts file before trying DNS.  (Your system is likely already setup this way.)  Examine and update if necessary /etc/nsswitch.conf (the hosts entry).  What changes did you need to make (if any)?  What is the output of the command “grep hosts /etc/nsswitch.conf”?
    2. Since the resolver is set to use DNS, you must update the /etc/resolv.conf file to include the correct default domain name(s) and DNS (nameserver) IP address(es).  This file was managed and routinely over-written by DHCP (and PPP), but now you must edit it manually.  What is the current contents of the /etc/resolv.conf file (as created by DHCP)?
    3. Now it is time to make changes to that file.  The default domain name to use for our class is “gcaw.org”.  Optionally you can specify a second search domain name of hccfl.edu, to allow commands such as “ssh ua00@YborStudent” to work.  The nameserver IP addresses to use are the same ones used when set by DHCP.  It is possible you may want to set some options.  For example, you may find it necessary to change the default DNS timeout from 5 seconds to a larger value.  See the resolv.conf man page for more information.

      The resolve.conf file might look like this:

      /etc/resolv.conf:

         search gcaw.org hccfl.edu
         nameserver 10.142.2.6  ⟵ not the real IP address!
      

      Notes:
      The DHCP version of resolv.conf is probably correct.  Use the DNS (nameserver) IP addresses you see there when making your own version of this file.
      When DHCP modifies the /etc/resolv.conf file, it first makes a copy of this file.  When the interface is brought down, the old resolv.conf file is restored.  So, after your next reboot any changes to this file may be lost!  This is a one-time thing; once you set your interface to static IP, the DHCP client won't over-write resolv.conf again.  Make a copy of your correct, updated resolv.conf file, so you can easily restore it later (if needed).

    4. Test your resolver setup.  Try using the ping command to ping hosts by name.  What is the results of each of the following commands:
      ping -vc 1 wpserver
      ping -vc 1 wpserver.gcaw.org
      ping -vc 1 your-hostname
      ping -vc 1 your-hostname.gcaw.org
      ping -vc 1 www
      ping -vc 1 www.hccfl.edu
      
    5. How many domains can be listed on the search directive in the resolv.conf file?  How did you find this out?
  3. At this point the resolver, routing, hostnames, and your IP address are are set up and tested for a static configuration.  However, if you restart networking (or reboot), your changes will be lost (not the changes you made to the /etc/hosts file).  You must now make your changes permanent by updating the various configuration files.  The files used vary by system; here we will configure your Fedora system, using the NetworkManager service installed by default.

    Red Hat-based systems (including Fedora) have always used the same files to configure each NIC.  The files are kept in the directory /etc/sysconfig/network-scripts and are named for the NIC.  What is the configuration file's absolute pathname that holds the network configuration for your NIC (e.g., “eth0”)?

    The descriptions of the various configuration files you need to edit are found in the file:
    /usr/share/doc/initscripts*/sysconfig.txt

  4. Turn off DHCP and set your NIC with the correct static configuration information:
    1. Change the boot protocol from dhpc to none
    2. Next, add entries to the file for the correct IP address and netmask (prefix) to use for your NIC
    3. Next, configure your default gateway. 
      GATEWAY=address  #IP address of gateway
      

      In Red Hat compatible Linuxes since version 7.2, the default gateway can be set in a manner similar to that used on Solaris, by creating the file /etc/default-route.  This file should just contain the IP address of your gateway.  What file should contain your gateway IP address on Solaris?

    4. Finally, add the DNS server IP addresses with the correct entries.  (While you put them in /etc/resolv.conf already, that file may get over-written so you should enter those values here as well.)

    What is the output of running diff on your modified file?

Part III — Optional Extra Steps

At this point, your system is now configured with a static IP address, and the change will persist even if you restart networking or reboot.  However, there are additional configuration steps you may wish to do:

  1. Update the greetings files with the hostname.  The file /etc/issue and /etc/issue.net contain system identification information that is displayed before a login prompt.  The default value contains information that is more useful to hackers than legitimate users.  You should update these files to contain a greeting which contains your system's hostname and no other information (except maybe a statement that unauthorized use prohibited).
  2. Another greeting file is used with the anonymous FTP server.  On Red Hat-compatible Linux distros since Red Hat 7.2, the default file is /var/ftp/welcome.msg.  This file too should only contain the hostname, something like “Welcome to the hostname Anonymous FTP Server!”.
  3. /etc/motd is a related file that is displayed to users just after a successful login, and often contains an acceptable use policy (AUP) statement.  All such files should display the correct name of your host.
  4. The file /etc/networks allows you to assign names for IP network numbers.  This file is optional, but if present will allow you to use the names in commands such as route and ifconfig.  A sample networks file might look like this:

    /etc/networks:

      gcaw-net   172.22.25.0
      hcc-net    10.41.0.0
      loopback   127.0.0.0
    
  5. Suppose one day your DNS stops working.  This is likely because the network administrator has updated the nameserver IP addresses to use.  No doubt if you were running DHCP you would automatically get the new DNS IP addresses.  How can you determine the new networking parameters (such as the DNS server IP address(es) to use)?  List two different ways.

Test your static IP setup by restarting networking.  Verify everything is correctly configured by using the hostname, ifconfig, route, traceroute, and ping commands as before.

If things are not working, carefully check all the steps you did by comparing the system journal with these directions.  (Also make sure the classroom is plugged into the campus network; sometimes, the uplink cable is pulled out!)  If you are unable to get things to work, you can attempt to use a GUI network setup tool.  You can also run the dhclient command to temporarily restore the DHCP configuration.

To be turned in:

The part of your system journal showing each and every change made as a result of completing this project, as well as the answers to the questions asked.  (And if you made changes to files other than the ones asked about, show the diff output showing those changes.)  You can send as email to (preferred).  If email is a problem for some reason, you may turn in a hard-copy.  In this case the pages should be readable, dated, and stapled together.  Your name should appear on the first page. 

Don't turn in your whole journal, you will need to add to it every day in class!  It is common in fact to keep the journal as a text file on the system (with a paper backup of course).

Please see your syllabus for more information about submitting projects.