Google Plus

Change from DHCP to Static ip Fedora/Centos

Written by Mel Kham on . Posted in Linux tutorials


Static IP addresses are manually assigned to a computer by an administrator. The exact procedure varies according to platform. This contrasts with dynamic IP addresses, which are assigned either by the computer interface or host software itself, as in Zeroconf, or assigned by a server using Dynamic Host Configuration Protocol (DHCP).


Even though IP addresses assigned using DHCP may stay the same for long periods of time, they can generally change. In some cases, a network administrator may implement dynamically assigned static IP addresses. In this case, a DHCP server is used, but it is specifically configured to always assign the same IP address to a particular computer. This allows static IP addresses to be configured centrally, without having to specifically configure each computer on the network in a manual procedure.

In the absence of both an administrator (to assign a static IP address) and a DHCP server, the operating system may assign itself an IP address using state-less autoconfiguration methods, such as Zeroconf.

1. login as root

2. get your current IP address with this command:

ifconfig


The OUTPUT will look someting like this:
Unixmen-net:~ # ifconfig
eth0 Link encap:Ethernet HWaddr 00:0D:9D:57:44:90
inet addr:10.33.17.143 Bcast:10.33.17.255 Mask:255.255.255.0
inet6 addr: fe80::20d:9dff:fe57:4490/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:255590 errors:0 dropped:0 overruns:0 frame:0
TX packets:98902 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:124649019 (118.8 Mb) TX bytes:14457923 (13.7 Mb)
Interrupt:21

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:18 errors:0 dropped:0 overruns:0 frame:0
TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1060 (1.0 Kb) TX bytes:1060 (1.0 Kb)

OR you can also get the ip from the network configuration file with this command:
COMMAND to show configuration:

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

 


THe OUTPUT will look like this (i have it set to DHCP)

DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:D0:B7:08:09:BB
ONBOOT=yes

3. Ok, on step 3 we are going to change from DHCP to static ip. so send this command to edit the /etc/sysconfig/network-scripts/ifcfg-eth0 file:

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

(you can other editor if you want like gedit pico nano..emacs)


Change from this:


DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:D0:B7:08:09:BB
ONBOOT=yes


TO this:

# File: ifcfg-eth0
#
DEVICE=eth0
IPADDR=10.33.17.143
NETMASK=255.255.255.0

BOOTPROTO=static
ONBOOT=yes


4. now save your changes and reboot your server.

For questions please refer to our Q/A forum at : http://ask.unixmen.com

Mel Kham

Founder of Unixmen, Living in Amsterdam. Am working in my free time to help people to understand the Opensource and to explain them in easy way how to make the fist steps to the the light. Working day and night with my Co-founder Zinovsky to keep this website live even with less resources.
  • Scott D.

    This works fine for a local network but does not take into account routing, etc. So if you change this and don’t know how to manipulate the routing tables you will only be able to see 10.33.17.0/24.

    Unless I am missing something – I think you would get more mileage out of this.

    DEVICE=eth0
    BOOTPROTO=static
    HWADDR=00:00:00:00:00:00
    ONBOOT=yes
    IPADDR=10.1.1.2
    NETMASK=255.255.255.0
    GATEWAY=10.1.1.1
    TYPE=Ethernet
    USERCTL=no
    IPV6INIT=no
    PEERDNS=yes

  • tao

    my device is p5p1 not eho,and I can’t find the file cat /etc/sysconfig/network-scripts/ifcfg-p5p1 why? help

  • Pingback: Have to restart network on restart?

Like us on Facebook

This week Top Posts

Write for us

Recent Comments

DragonFartOutLoud

|

it went to china.

DragonFartOutLoud

|

great review! i’ve been using it as my main OS since Beta 1 release. its been a awesome ride so far :)

jet li

|

i try the method, and i unzip the image contain zip secret, i dont find the file that i was hide, where it go? and how to open it? :s

zinovsky

|

Yes, it is possible using Steganography, we will post another quick howto do that in the next few days

SK

|

Hey Abhishek

Yes there are many open source tools available to meet your requirements. They are easy to manage and has a decent web gui to configure. We will publish all of them one by one shortly. Stay tuned with us.

 
IDG Tech Network
Copyright © 2008-2013 Unixmen.com .
Maintained by Anblik .