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
nameserver 10.168.20.1
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
NETWORKING=yes
HOSTNAME=Subversion
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:
DEVICE="eth0"
BOOTPROTO="static"
DNS1="10.168.20.1"
HOSTNAME="Subversion"
HWADDR="00:50:56:88:18:A4"
IPADDR="10.168.20.228"
MTU="1500"
NETMASK="255.0.0.0"
NM_CONTROLLED="yes"
ONBOOT="yes"
 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:
DEVICE="eth1"
BOOTPROTO="dhcp"
HWADDR="00:50:56:88:72:2B"
ONBOOT="yes"
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

No comments:

Post a Comment