≡ Menu

Linux change ip address

Q. How do I change ip address in Linux?

A. There are different ways to change IP address in Linux
(a) Command Line tools

(b) Modify configuration files

(c) Use GUI tools

Task: Display current IP address and setting for network interface called eth0

Use ifconfig command:
# ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:30:48:5A:BF:46  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::230:48ff:fe5a:bf46/64 Scope:Link
          RX packets:728204 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1097451 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:62774749 (59.8 MiB)  TX bytes:1584343634 (1.4 GiB)

Task: Change IP address

You can change ip address using ifconfig command itself. To set IP address, enter command:
# ifconfig eth0 netmask up
# ifconfig eth0

To make permanent changes to IP address you need to edit configuration file according to your Linux distribution.

Change IP address under RedHat / CentOS / Fedora core Linux

=> Please read – Howto change and setup IP address in Redhat Linux

Change IP address under Debian / Ubuntu Linux

=> Please read – Howto change and setup IP address in Ubuntu / Debian based Linux distros

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 82 comments… add one }
  • Mike May 1, 2008, 5:15 pm

    Great. Very helpful.

  • Patrick September 25, 2008, 9:14 pm

    Thanx for giving Valuable suggestion !!!

  • selva December 10, 2008, 11:17 am

    Thanks its working

  • Mutturaj February 12, 2009, 6:51 am

    great excellent

  • JediTech February 18, 2009, 6:28 am

    Excellent, helped me out of a jam

  • anthony February 26, 2009, 1:22 am

    Excellent !!!

  • kamal February 26, 2009, 7:21 am

    thanks it was helpful

  • peteopp April 30, 2009, 5:18 am


  • mahendra patil May 5, 2009, 12:26 pm

    linux support
    Pls Give me More Command Ex. vmware esx server and Fedora server edition

    mahendra patil

  • al prince nofl May 27, 2009, 11:34 pm

    good idea

    i have know my ip

    but i cant change it, this is what i write:

    alprincenofl@alprincenofl-laptop:~$ ifconfig eth0 netmask up
    SIOCSIFADDR: Permission denied
    SIOCSIFFLAGS: Permission denied
    SIOCSIFNETMASK: Permission denied
    SIOCSIFFLAGS: Permission denied

    • nixCraft May 28, 2009, 12:04 am

      You must be root user to change IP address.

    • narender August 2, 2010, 8:02 am

      u has to type the command before u are in root
      then the ip will change.,

    • tawab December 27, 2011, 6:45 am

      write word ‘sudo’ at first as the following:
      sudo ifconfig eth0 netmask up

  • ameer June 4, 2009, 1:14 pm

    how to upgrade firefox in fedora

  • tutu June 17, 2009, 10:51 pm

    it doesn’t work. I don’t have the ifconfig!!
    what about the config files?

  • nixCraft June 17, 2009, 10:58 pm


    You must login as root and use full path /sbin/ifconfig

  • tutu June 18, 2009, 3:27 am

    Thanks. It worked. I thought I tried that already… Anyway, in order to make it permanent now, I saw the other link but when I launched the command sudo… it asks for a password and there I’m lost as the superuser password is not accepted. The user’s password also… Is that a different password?

  • Win June 29, 2009, 4:59 pm

    it’s working !

  • sidhu July 22, 2009, 7:47 pm

    This is sidhu, Thanks for your post.
    I want to learn linux, I completed my MCSE.
    But i dnt hve any idea on linux.
    I want ot learn CentOS – ViciDialNow.
    so i am searching linux commands.
    Please send me any tips or tutorial to my mail.
    Once again Thanks, Bye
    Have a nice day

  • nithin mk October 22, 2009, 6:52 am

    please try to post more tips than this

  • saki December 10, 2009, 6:29 am

    ifconfig eth1 netmask up
    SIOCSIFFLAGS: Cannot allocate memory
    SIOCSIFFLAGS: Cannot allocate memory

    • Pankaj Pal August 28, 2010, 7:21 am

      It seems that your vserver does not allow you to allocate enough memory to compile PHP. You have to talk with your hosting provider if they can set your memory limit to a higher value.
      You can also try to stop all daemons except the ssh (so you can administrate your server) and then try….hope it works…

  • Isuru December 26, 2009, 5:27 pm

    Thanks — good solid basics

  • cocu February 1, 2010, 6:06 am

    thank you so much. my computer always login in root user. and it so simple thing to change the ip address as i like. cuz my computer through a network

  • Rovshan February 5, 2010, 9:38 am

    i have to change my ip address in suse linux but any restarts give default ip

    P.S i’m use Sun Virtualbox

    • Pankaj Pal August 28, 2010, 7:13 am

      I give a simple solution to your query :
      add one line in /etc/rc.local of your system
      ifconfig eth0 netmask up

      • Chris Keil August 31, 2010, 3:46 pm

        Actually, OpenSuse does not have a file called rc.local in the /etc directory.

        Try editing /etc/sysconfig/network/ifcfg-ethX – where the X value is the ethernet port you want to change.

  • Unknown May 12, 2010, 4:19 am

    I tried changing my IP address and it worked, but when i tried accessing the internet it did not work.
    Can anyone help me?

    • Pankaj Pal August 28, 2010, 7:27 am

      If you successfully changed your IP address than try to ping your gateway(your LAN’s address)
      If the step went good. try to resolve some DNS name with ‘dig’ or with ‘nslookup’
      if the step went bad try to configure DNS info with some X app of your distro or check manually (if you are sure what you are doing) /etc/named.cof, /etc/resolve.conf and etc/sysconfig/network-scripts/ifcfg- files as a root.

      If that does not help let me know

  • oumaKarate May 24, 2010, 1:14 pm

    @Vivek Gite

    (Linux Nooby)

    I installed Ubuntu 9.10 (the Karmic Koala), and have not specified a root password
    and cannot log in as root because of this…is there a standard password?

    • naveen March 20, 2012, 12:19 pm


  • oumaKarate May 24, 2010, 1:21 pm

    App : @Vivek Gite

    (Linux Nooby)

    I installed Ubuntu 9.10 (the Karmic Koala), and have not specified a root password
    and cannot log in as root because of this…is there a standard password?

    I fixed :)
    sudo bash

  • levi August 20, 2010, 10:11 am

    i want to log on to the linux machine remotely using windows xp, please help me on this one.
    thank you

    • Pankaj Pal August 28, 2010, 7:01 am

      If you want to log on to the linux machine remotely using windows xp, you just installed Putty. In Host Name type the address of the remote machine and load it…
      If not able to take remote than check that openssh service is running on the remote machine.

  • Strike September 29, 2010, 6:17 am

    How do you remove it, i put in the wrong ip and want to take it out, cheers.

  • Abhilash October 7, 2010, 10:29 am

    Dear Sir,

    I have installed fedora 10 on my machine. it contains two ethernet port.
    i installed cable with eth1 and give a static ip address xxx.xxx.xxx.xxx through Gnome. its working fine. but when i restart the machine it again need to configure. how do i save it permanently.
    please help.

  • gggg November 14, 2010, 7:59 am

    I get an error saying no such device.

  • Nandakishore November 14, 2010, 1:19 pm

    Many thanks. It was very helpful and I would otherwise have had to go through Richard Stevens book on TCP/IP without much of a chance of finding this information.

    Excellent show.

  • siva 9791991185 November 27, 2010, 7:37 am


  • Rahul December 3, 2010, 8:26 am


    Other way of changing ip address is to edit a file ” /etc/sysconfig/network-scripts/ifcfg-eth0 ” and change the settings.

  • SirshaK Das February 18, 2011, 4:54 am

    how to change the dns server in command prompt

  • Aca February 28, 2011, 9:58 am

    install and use webmin for change ip addres!!!!

  • soundarapandian March 30, 2011, 10:12 am

    echo ‘Thanks’

  • Maat May 12, 2011, 9:46 pm

    Not working on opensuse 11.2
    Which is the best linux to use

  • hans June 29, 2011, 2:07 pm

    Excellent!! Thank you!

  • SPEK HITAM July 6, 2011, 4:34 am

    nice! thanks!

  • indra July 28, 2011, 10:15 am

    nicely done :)
    Thanks !!!

  • ramulu ponnam July 28, 2011, 11:33 am

    how can i add the same for ipv6?
    can u send the command for related to that?i am looking for add ipv6 address to linux.
    any reply is appreciable,thanks in advance.

  • rajesh August 15, 2011, 9:23 am

    i m using ubuntu 10.10 it s giving me error as below…..

    raja@ubuntu:~$ ifconfig eth0
    eth0 Link encap:Ethernet HWaddr 00:19:d1:a7:28:49
    inet6 addr: fe80::219:d1ff:fea7:2849/64 Scope:Link
    RX packets:1817829 errors:0 dropped:0 overruns:0 frame:0
    TX packets:89850 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:345456581 (345.4 MB) TX bytes:11011030 (11.0 MB)

    raja@ubuntu:~$ ifconfig DSL
    DSL: error fetching interface information: Device not found
    raja@ubuntu:~$ ifconfig eth0 netmask up
    SIOCSIFADDR: Permission denied
    SIOCSIFFLAGS: Permission denied
    SIOCSIFNETMASK: Permission denied
    SIOCSIFFLAGS: Permission denied

    • BALAJI August 30, 2011, 8:22 am

      Mr Rajesh
      First You will login root or supervisor user.
      how to login root or su?
      just type in your prompt #su password
      you don’t known password means
      type #sudo passwd enter
      type new password
      and again type su
      type password
      and after change the command using ip addres

  • leapkh September 12, 2011, 7:23 am


  • FAROUK October 13, 2011, 3:02 pm


    • Naresh October 27, 2011, 1:30 pm

      You can add gateway at path —> /etc/sysconfig
      you can add DNS information at —-> /etc/resolv.conf
      search yourname.com

      • Belal April 22, 2012, 8:56 pm

        Thank u

  • Zatnaktel November 23, 2011, 6:37 pm

    When I change IP, access on internet is denied. Why?

  • meliron November 30, 2011, 9:13 am

    Thanks…it is very helpful

  • will551 March 6, 2012, 4:28 am

    great! this helped me on the road to getting my windows box hooked up to the wireless internet using a (ethernet) cable… :-)

  • alex March 28, 2012, 4:59 pm

    To make permanent changes to IP address you need to edit configuration file according to your Linux distribution.

    Wow that is totally not helpful

  • shammi May 15, 2012, 7:52 am

    we are university student in developing country that is Sri Lanka
    . so we are poor in knowledge. your effort for helping us is grateful. thanx a lot.

  • Jason May 15, 2012, 8:43 pm

    You know, if a user uses the terminal method listed, and they are changing IP ranges (example: from to, and they are doing so remotely, this method will BREAK connectivity completely, until the person goes to the physical location of the computer and fixes it… Why? Because you don’t even touch on changing the gateway.

    Also, the terminal method you use is NOT a permanent change. It only changes it until the next time the computer is restarted. The smarter way is to edit the config files…

  • AADI May 21, 2012, 8:18 pm

    Thanks for command.

  • Ivans Muhasa Enock June 21, 2012, 11:35 am

    Was so helpful thank you guys

  • vinod August 6, 2012, 6:27 am

    thanks guys was helpful.

  • murugan August 10, 2012, 4:11 am

    very very useful to us.thanks you. very good job

  • slJedi October 11, 2012, 6:55 pm

    Out put of # ifconfig eth0
    eth0 Link encap:Ethernet HWaddr 00:23:8b:48:34:21
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
    Interrupt:44 Base address:0x8000

    So how can I change IP.

    • Jason October 12, 2012, 11:21 pm

      Try reading the full article

  • Confused December 26, 2012, 10:11 am

    didn’t work I entered what if said, needs to be exactly clear.

  • Praveen January 13, 2013, 7:54 pm

    in /etc/sysconfig/network/scripts directory “ifcfg-eth0” file is missing, why it is missing? what shud i do to get that file?

  • vynz February 5, 2013, 5:28 pm

    i already change my ip address on my linux server i follow the instruction but when restart my server no effect the ip is not change

  • Sagubar sathik March 2, 2013, 3:55 pm

    Hi All,

    It is not working for me.

    without throwing any message, the server goes to unreachable state.

    #ifconfig eth0 A.B.C.D netmask A.B.C.D up.

    when i ping old server ip as well as new server IP. it is not reachable

    Please any one send the workaround to my mail id “sathikhaja@gmail.com.

  • hasan March 29, 2013, 7:31 am

    thanks helful command

  • Anonymous July 4, 2013, 7:09 pm

    This s not working in backtrack
    it change ip but after change ip i cant access internet
    plz help me to solve this problem,,

  • Abdelkader August 22, 2013, 7:29 pm

    thank you

  • bheem January 22, 2014, 6:16 pm


  • jan April 28, 2014, 7:22 am

    not working.i got an error that permission denied

  • jan April 28, 2014, 7:23 am

    SIOCSIFADDR: Permission denied
    SIOCSIFFLAGS: Permission denied
    SIOCSIFNETMASK: Permission denied
    SIOCSIFBROADCAST: Permission denied
    SIOCSIFFLAGS: Permission denied
    ……………..this is the error what i got

  • Raj June 19, 2014, 10:30 am

    Thanks its working and very helpful

  • Nadeem November 11, 2014, 5:10 am

    Hi friends
    Can anybody explain and help me find output of the following command

    IP= echo${IP:0:4}

    • Harm November 26, 2014, 12:51 pm

      IP= will save in a temporary variable named IP.

      echo${IP:0:4} will print that temporary variable starting from character 0, over a length of 4 characters.

      Output: 192.

  • tohid February 13, 2015, 3:47 am

    thanks for help :)

  • Morteza May 11, 2015, 7:15 am

    Thanks a lot.

  • mikicat May 27, 2016, 5:50 pm

    Thanks, it helped a lot :)

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , ,