Linux change ip address

Posted on in Categories , , , , , , last updated September 25, 2007

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
Output:

eth0      Link encap:Ethernet  HWaddr 00:30:48:5A:BF:46  
          inet addr:10.5.123.2  Bcast:10.5.123.63  Mask:255.255.255.192
          inet6 addr: fe80::230:48ff:fe5a:bf46/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          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)
          Interrupt:177 

Task: Change IP address

You can change ip address using ifconfig command itself. To set IP address 192.168.1.5, enter command:
# ifconfig eth0 192.168.1.5 netmask 255.255.255.0 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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 82 comments/add one below):

82 comment

  1. good idea

    i have know my ip

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

    [email protected]:~$ ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up
    SIOCSIFADDR: Permission denied
    SIOCSIFFLAGS: Permission denied
    SIOCSIFNETMASK: Permission denied
    SIOCSIFFLAGS: Permission denied

  2. 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?

  3. Hi
    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.
    [email protected]
    Once again Thanks, Bye
    Have a nice day

    1. 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…

      1. 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.

    1. 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

  4. @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?

  5. 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

    1. 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.

  6. 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.

  7. 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.

  8. 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.

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

    [email protected]:~$ ifconfig eth0
    eth0 Link encap:Ethernet HWaddr 00:19:d1:a7:28:49
    inet6 addr: fe80::219:d1ff:fea7:2849/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    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)
    Interrupt:44

    [email protected]:~$ ifconfig DSL
    DSL: error fetching interface information: Device not found
    [email protected]:~$ ifconfig eth0 172.100.127.93 netmask 255.255.0.0 up
    SIOCSIFADDR: Permission denied
    SIOCSIFFLAGS: Permission denied
    SIOCSIFNETMASK: Permission denied
    SIOCSIFFLAGS: Permission denied
    [email protected]:~$

    1. 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

    1. You can add gateway at path —> /etc/sysconfig
      Ex:
      NETWORKING=yes
      HOSTNAME=xyz.youname.com
      GATEWAY=10.100.100.1
      you can add DNS information at —-> /etc/resolv.conf
      Ex:
      search yourname.com
      nameserver 10.100.100.5
      nameserver 10.100.100.6

  10. You know, if a user uses the terminal method listed, and they are changing IP ranges (example: from 192.168.1.3 to 192.168.2.3), 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…

  11. Out put of # ifconfig eth0
    eth0 Link encap:Ethernet HWaddr 00:23:8b:48:34:21
    UP BROADCAST MULTICAST MTU:1500 Metric:1
    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.

  12. 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 “[email protected]

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

    1. IP=192.168.100.1 will save 192.168.100.1 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.

Leave a Comment