IT Blog

Centos

How to Enable Static IP on Centos 6

Enable Networking:

This obviously varies from one networking setup to another. We will be setting a static IP on our setup and reccommend you do too on eth0 from the local console.

I will be recording now every step straight after the Installation reboot.

This is via a monitor or local Console.

Backup01 Login:

root

Enter Password

I wanted to ensure that the ethernet cable I plugged in was detected by my BackupPC server

Enable the interface:

[root@backup01~]# ifup eth0

It will now get an IP from DHCP.[root@backup01~]# ethtool eth0

This will display information like speed of the interface and if the link is detected.[root@backup01~]# ifconfig

This displays the IP address received from DHCP. I will now use putty to ssh into the server remotely for ease of access from my laptop / workstation (or you can carry on working locally)

Open up putty and connect | After connecting we will set a static IP address by editing the config file for eth0. This is wil visual editor called “vi”[root@backup01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

You will see something like this:

DEVICE=eth0
HWADDR=6MORE MAC
TYPE=Ethernet
UUID=a1e40f15-316MORE  UUID
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp

1) Change ONBOOT to =yes                   | This enables the interface at bootup

2) Change BOOTPROTO to =static        | This changes it from Dynamic to Static

3) Add the following lines to the bottom and change as desired for static IP:

IPADDR=10.0.0.11
NETMASK=255.255.255.0                       | This is a /24 subnet
GATEWAY=10.0.0.1

The result is like so:

DEVICE=eth0
HWADDR=6C:MORE MAC
TYPE=Ethernet
UUID=a1e40f15MORE UUIDD
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.0.0.11
NETMASK=255.255.255.0
GATEWAY=10.0.0.1

Press ESC thne type in “wq” to Write and Quit

Restart the Network service after changes

[root@backup01 ~]# service network restart

and SSH with the NEW IP address of the Server instead like so:

root@10.0.0.11

If you are local on the server you can just type in[root@backup01~]# ifconfig

again to check the given IP address.