Network Configuration on CentOS 5

Network configuration on Linux CentOS 5 is achieved through modifications on the following files:

 

DNS: /etc/resolv.conf
Default Gateway: /etc/sysconfig/network
IP and mask: /etc/sysconfig/network-scripts/ifcfg-eth0
Hostname: /etc/hosts, /etc/sysconfig/network, /proc/sys/kernel/hostname

 

The following steps describe how to change your network configuration on CentOS 5:

 

CHANGING DNS ON CENTOS 5

To change your DNS server just edit /etc/resolv.conf and add or modify the lines with the new DNS servers accordingly. You can see a configured file here:

#your domain
search training5.tm
#main DNS
nameserver 192.168.75.5
#secondary DNS
nameserver 8.8.8.8

If you just changed the DNS you don’t need to restart the network service, this change is applied automatically.

 

CHANGING THE DEFAULT GATEWAY ON CENTOS 5

To change the Default Gateway just modify the following line in /etc/sysconfig/network as shown below:
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=tmcent01.training5.tm
GATEWAY=192.168.75.2

After this change you have to execute “service network restart” and then execute “netstat –rn” just to check that your new gateway is updated. The line with the “UG” flag shows your default gateway:

[root@tmcent01 kernel]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.75.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.75.2 0.0.0.0 UG 0 0 0 eth0

 

CHANGING THE IP ON CENTOS 5

The IP modification is performed on /etc/sysconfig/network-scripts/ifcfg-eth0 as shown below:

# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
BOOTPROTO=static
IPADDR=192.168.75.70
NETMASK=255.255.255.0
BROADCAST=192.168.75.255
NETWORK=192.168.75.0
ONBOOT=yes
DEVICE=eth0
DHCPCLASS=
HWADDR=00:0c:22:f4:64:c7

After you make your changes execute “service network restart” to reload the configuration and then execute “ifconfig eth0” to check the IP is the correct one:

eth0 Link encap:Ethernet HWaddr 00:0C:29:F8:64:C7
inet addr:192.168.75.70 Bcast:192.168.75.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fef8:64c7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:85459 errors:0 dropped:0 overruns:0 frame:0
TX packets:6469951 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:18608485 (17.7 MiB) TX bytes:1163471936 (1.0 GiB)
Base address:0×2000 Memory:d8960000-d8980000

 

CHANGING THE HOSTNAME ON CENTOS 5

To change the hostname you have to edit three files:

/etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 tmcent01.training5.tm localhost.localdomain localhost

/etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=tmcent01.training5.tm
GATEWAY=192.168.75.2

/proc/sys/kernel/hostname
tmcent01.training.tm

If the system doesn’t allow you to change the last file because it is being used, you can run the following command which is an equivalent:

[root@tmcent01 kernel]# echo tmcent01.training5.tm > /proc/sys/kernel/hostname

After you make these changes execute “service network restart”. Execute the “hostname” command to check your new hostname is successfully updated.

You can send us your questions and comments to our Twitter account @redinskala where you’ll also find security information and tips.