Linux change ip address

by Vivek Gite on April 15, 2007 · 54 comments

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

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 54 comments… read them below or add one }

1 Mike May 1, 2008

Great. Very helpful.

Reply

2 Patrick September 25, 2008

Thanx for giving Valuable suggestion !!!

Reply

3 selva December 10, 2008

Thanks its working

Reply

4 Mutturaj February 12, 2009

great excellent

Reply

5 JediTech February 18, 2009

Excellent, helped me out of a jam

Reply

6 anthony February 26, 2009

Excellent !!!

Reply

7 kamal February 26, 2009

thanks it was helpful

Reply

8 peteopp April 30, 2009

EXCELLENT!!!!

Reply

9 mahendra patil May 5, 2009

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

Regards
mahendra patil

Reply

10 al prince nofl May 27, 2009

good idea

i have know my ip

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

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

Reply

11 Vivek Gite May 28, 2009

You must be root user to change IP address.

Reply

12 narender August 2, 2010

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

Reply

13 tawab December 27, 2011

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

Reply

14 ameer June 4, 2009

how to upgrade firefox in fedora

Reply

15 tutu June 17, 2009

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

Reply

16 Vivek Gite June 17, 2009

@tutu

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

Reply

17 tutu June 18, 2009

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?

Reply

18 Win June 29, 2009

thanks
it’s working !

Reply

19 sidhu July 22, 2009

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.
sidhu_sir2@yahoo.co.in
Once again Thanks, Bye
Have a nice day

Reply

20 nithin mk October 22, 2009

please try to post more tips than this

Reply

21 saki December 10, 2009

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

Reply

22 Pankaj Pal August 28, 2010

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…

Reply

23 Isuru December 26, 2009

Thanks — good solid basics

Reply

24 cocu February 1, 2010

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

Reply

25 Rovshan February 5, 2010

Hi,
i have to change my ip address in suse linux 192.168.0.77 but any restarts give default ip 10.0.2.15

P.S i’m use Sun Virtualbox

Reply

26 Pankaj Pal August 28, 2010

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

Reply

27 Chris Keil August 31, 2010

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.

Reply

28 Unknown May 12, 2010

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

Reply

29 Pankaj Pal August 28, 2010

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

Reply

30 oumaKarate May 24, 2010

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

Reply

31 oumaKarate May 24, 2010

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

Reply

32 levi August 20, 2010

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

Reply

33 Pankaj Pal August 28, 2010

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.

Reply

34 Strike September 29, 2010

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

Reply

35 Abhilash October 7, 2010

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.

Reply

36 gggg November 14, 2010

I get an error saying no such device.

Reply

37 Nandakishore November 14, 2010

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.

Reply

38 siva 9791991185 November 27, 2010

thanks……………

Reply

39 Rahul December 3, 2010

Hi

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

Reply

40 SirshaK Das February 18, 2011

how to change the dns server in command prompt

Reply

41 Aca February 28, 2011

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

Reply

42 soundarapandian March 30, 2011

echo ‘Thanks’

Reply

43 Maat May 12, 2011

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

Reply

44 hans June 29, 2011

Excellent!! Thank you!

Reply

45 SPEK HITAM July 6, 2011

nice! thanks!

Reply

46 indra July 28, 2011

nicely done :)
Thanks !!!

Reply

47 ramulu ponnam July 28, 2011

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.

Reply

48 rajesh August 15, 2011

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

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

Reply

49 BALAJI August 30, 2011

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

Reply

50 leapkh September 12, 2011

Thanks!

Reply

51 FAROUK October 13, 2011

HOW CAN I CHANGE DEFAULT GETWAY AND DNS ADDRESS

Reply

52 Naresh October 27, 2011

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

Reply

53 Zatnaktel November 23, 2011

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

Reply

54 meliron November 30, 2011

Thanks…it is very helpful

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 2 + 2 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: