Jump to content

  •  

Photo
- - - - -

Set a Static IP Address

CentOS 6.5

  • Please log in to reply
No replies to this topic

#1 Wilson18

Wilson18

    Administrator

  • root
  • 112 posts
  • LocationUniversity of Birmingham

Posted 28 May 2014 - 09:48 PM

In this tutorial, I will be showing you how you can set up a Static IP Address on CentOS 6.5. Once logged in to your server as the root user. The first thing we are going to be doing is to stop the Network manager from trying to automatically handle the network for us. This will stop all of our settings been overridden at a later date. To do this, we can type

service NetworkManager stop

After this, we will permanently turn this off and stop it been enabled again on startup. 

chkconfig NetworkManager off

Once we have done this, we can go through and edit the configuration file for the network adapter so that we can tell it which address to use. 

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

In this file, you should see something like the following:

  

DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="00:0C:29:C2:97:CD"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="95befdbb-d66f-4565-8f4a-d62292304ec6"

The thing we need to change in this is to set the BOOTPROTO to static instead of dhcp. This should look like this. 

BOOTPROTO="static"

Once we have done this, we can set up our new IP at the bottom of the file. To do this, you will need to add the following three lines but make sure to put in the information which is appropriate to your network configuration. 

IPADDR=10.0.0.109      #The new ip you would like to use
GATEWAY=10.0.0.1       #The ip of your router
NETMASK=255.255.255.0  #The subnet mask which is normally 255.255.255.0

The completed file should look like this

[attachment=80:network config.PNG]

 

Once you have done this, you can save and close the file using Ctrl + O and Ctrl + X.

 
We are now just going to add the gateway to another network config file just to make sure the system knows where to send the data when connecting to the web. 
 
nano /etc/sysconfig/network

In this, we just need to add the following: 

GATEWAY=10.0.0.1  #Your gateway

Once you have done this, saved and closed the file, we can go to add the name servers we would like to use to resolve dns. The file we will need to edit is

nano /etc/resolv.conf

You can clear the current file and enter the following

nameserver 8.8.8.8 #Your first nameserver
nameserver 8.8.4.4 #Your second nameserver

You can add as many nameservers as you would like. Again, save and close this file. Once we have done all this, everything should be done. We can now restart our network interface to make sure our changes have been taken into account.

service network restart 
Once you have restarted the network, you can check to see if the network is using the new address. If you type in ifconfig, it should look something a little like this: 
[attachment=81:ifconfig.PNG]
We can then also ping google to make sure we have network connectivity and that our namesevers are working.
ping google.com

If you go ahead and restart your server, you should see that everything is still working and using the details you used. If this is not the case, please make sure you follow the first few steps to disable the NetworkManager.

 


List what you read?

Check me out on: YouTube, Twitter, Facebook, Google+






Also tagged with one or more of these keywords: CentOS 6.5