jump to navigation

Changing hostname and IP on a CentOS server December 12, 2010

Posted by Tournas Dimitrios in Linux.
trackback

This article just outlines a four steps procedure to change the hostname and IP address of a  Red Hat based Linux box . A future article will go in more detail how to configure and troubleshoot  network adapters .Here are a few things you need to change :

Step 1 : RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot. This is set using the init script /etc/rc.d/rc.sysinit  . My favorite editor is vi  , so I use the following command to edit the file  : vi  /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=”plain.domainname.com”
GATEWAY=”192.168.1.1″
GATEWAYDEV=”eth0″
FORWARD_IPV4=”yes”

Step 2 : TCP/IP Network Configuration Files . This configures Linux so that it knows which DNS server will be resolving domain names into IP addresses :  vi  /etc/resolv.conf

nameserver XXX.XXX.XXX.XXX(IP address of primary name server )
nameserver XXX.XXX.XXX.XXX(IP address of secondary name server)

Step 3 : Locally resolve node names to IP addresses :  vi /etc/hosts

::1             localhost6.localdomain6 localhost6
# Do not remove the following line, or various programs
# that require network functionality will fail.
1×1.2×2.3×3.4×4            yourname.server.com yourname
127.0.0.1               localhost

Step 4 : Configuration settings for your first ethernet port . I never remember the path of this file , so  “locate” is my best reminder ( locate ifcfg-eth0)  .  vi /etc/sysconfig/network-scripts/ifcfg-eth0

For a static IP :

DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.1.255
IPADDR=192.168.1.50
NETMASK=255.255.255.0
NETWORK=111.222.333.0
ONBOOT=yes

For a Dynamicly asigned IP :

DEVICE=eth0
BOOTPROTO=dhcp
TYPE= Ethernet
USERCTL=yes
IPV6INIT=yes
PEERDNS=yes
ONBOOT=yes
DHCP HOSTNAME=yournameserver

And to finalize , you need to restart your network :  service network restart

Of course there is alway the graphical GUI interface :  system-config-network

Hopefully those steps will help you to get you on the road 🙂

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s