Tuesday, 7 June 2011

Configure networking and hostname resolution statically or dynamically

Let's start with configuration hostname resolution first:

Static Name Resolution:

This refers to your /etc/hosts file, which is really only practical for a network of a few machines, as you would need to modify the hosts file on each machine so that name resolution works effectively. This is not very practical.

Dynamic Name Resolution:

This refers to the use of a name server, this is configured in the /etc/resolv.conf file, see sample below:
search dev.com sams.org
The file /etc/host.conf controls how name resolution is configured, see default below:
multi on
order hosts,bind
The first entry means that all valid addresses on /etc/hosts will be returned for a host whereas the second entry specifies that name resolution should first attempt to look at the hosts file and then at the name server specfied in resolv.conf.

In a somewhat analogous situation to hostname resolution, ip addresses can be set either dynamically or statically.

Before we move on, let's have a look at /etc/sysconfig/network
If you need to change the hostname, this is where you need to start. The easiest way is to change the name here and reboot, as otherwise you will need to go through all places in the system where the hostname needs to be changed.

Static IP:

This is fairly simple, just edit the following file /etc/sysconfig/network-scripts/ifcfg-eth0:
 The lines in bold are the lines you are interested on, nothing much to say here really.

Dynamic IP:

This is fairly simple as well, in my case I just edit the configuration file for the other nic, /etc/sysconfig/network-scripts/ifcfg-eth1:
Needless to say that you need a dhcp server for the latter to work. The MAC Address is not necessary.

Note that you will  need to restart the interface for the configuration changes to take place, this applies to both the static and the dynamic case. You can do this with the following command:
service network restart
In practice, you really only want to restart the interface that you have changed so you should do:
ifdown eth1
ifup eth1

1 comment: