Monday, May 24, 2010

Redhat Client Networking & DNS

Networking in Centos/Redhat is pretty straight forward. First we will look at our ip address configuration and the files used to edit this information. Each network interface has its own config file that follows the format ifcfg-ethX where X is the number of the network card. We can use any editor to make changes to the configuration file.

# cd /etc/sysconfig/network-scripts/
# nano ifcfg-eth0

Our config file looks like the following:

DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:11:22:33:44:55
ONBOOT=yes
TYPE=Ethernet

We can see here that the DHCP protocol is in use and that it is active during the boot process. We can determine then that this client is using DHCP to obtain an ip address from a DHCP server. We can verify this with:

# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:11:22:33:44:55  
          inet addr:172.168.1.203  Bcast:172.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe30:74aa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:19942 errors:8 dropped:0 overruns:0 frame:0
          TX packets:966 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2056708 (1.9 MiB)  TX bytes:176542 (172.4 KiB)
          Interrupt:10 Base address:0xd020

Perhaps though we want to change this network interface to have a static ip address that will never change. We can edit the network interface config file to look like the following:

DEVICE=eth0
BOOTPROTO=none
HWADDR=00:11:22:33:44:55
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
IPADDR=172.168.1.1
NETMASK=255.255.255.0
GATEWAY=172.168.1.1

Once complete you will need to restart the networking service for the changes to take effect.

# service network restart

or bring down just the eth0 interface (if you have multiple adapters):

# ifdown eth0
# ifup eth0

You can verify with the ifconfig command again to make sure that your static ip address is set correctly. Aside from ip addresses you might also want to specify the DNS server for the client to use. This config file is contained in /etc/resolv.conf.

# cat /etc/resolv.conf
search mydomain.com
nameserver 172.168.1.1
nameserver 172.168.1.2

This config file is pretty easy to understand. The first line is the domain which we want the client to search when making requests (the domain that the client belongs too). The nameserver directive tells the client what the primary and secondary DNS servers are that it should use when making queries.

Editing config files by hand however is not always the most efficeint way of doing things. We can use some built in tools to help us configure ip addresses, gateways, and DNS information faster.

# system-config-network-tui

This will open a menu driven configuration utility on the command line, which will allow you to configure the network interfaces, add a new network interface, and edit the client DNS information. This method is much faster and easier to use. You still will need to restart the networking service in order for these changes to take effect. You can verify these changes however by checking the contents of the config files.

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# cat /etc/resolv.conf
# ifconfig eth0

0 comments:

Post a Comment