Changing Hostname and IP in Red Hat linux

So I am new to administrating Linux servers so I am going to post about all the simple things that a noob Linux admin would want to know.

I built a base Linux vm in Microsoft Virtual Server 2005. If I copy the vhd file from that base install, what do I need to change before I add it to the production environment?

** Note: I am using a Red Hat Linux OS (CentOS v5.3).

Change the Hostname

First we need to change the computer’s Hostname.

To change the computer’s Hostname, edit these files:

/etc/hosts:

[code lang=”html”]
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
10.10.81.46 server01.theitguyrox.com
[/code]

/etc/sysconfig/network:

[code lang=”html”]
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=server01.theitguyrox.com
[/code]

For the Hostname change to take effect, you need to reboot the computer.

Change the IP Address

To change the IP address of a CentOS 5.3 server, edit:

/etc/hosts:

[code lang=”html”]
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
10.10.81.46 server01.theitguyrox.com
[/code]

/etc/sysconfig/network-scripts/ifcfg-eth*:

[code lang=”html”]
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:03:ff:05:46:7f
NETMASK=255.255.0.0
IPADDR=10.10.81.46
GATEWAY=10.10.1.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
[/code]

Add DNS Servers

Finally we need to add some DNS servers since we won’t get them from DHCP any more.

To add the DNS Servers, edit:

/etc/resolv.conf:

[code lang=”html”]
nameserver 10.10.10.10
nameserver 10.10.10.20
[/code]

To make the changes take effect, you need to either reboot, or restart the network service.

To restart the network service:

[code lang=”html”]
/etc/init.d/network restart
[/code]

or:

[code lang=”html”]
service network restart
[/code]

Well that’s it for today.

This entry was posted in linux. Bookmark the permalink.