LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-23-2012, 03:25 PM   #1
ohlookpie
LQ Newbie
 
Registered: Apr 2012
Posts: 20

Rep: Reputation: Disabled
Using the ip command to change IP address


If I do an "ifconfig <iface> <IP>" it changes the IP address for my device. If I do an "ip addr change dev <iface> <IP/mask>" it adds a secondary IP to device (same happens with an "ip addr add dev <iface> <IP/mask>"). So, how do I actually change the IP address associated with then interface using the ip command?

Code:
[root@money ~]# ip addr show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:ca:49:04 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.100/24 brd 192.168.122.255 scope global eth1
    inet6 fe80::5054:ff:feca:4904/64 scope link 
       valid_lft forever preferred_lft forever
[root@money ~]# ifconfig eth1 192.168.122.105
[root@money ~]# ip addr show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:ca:49:04 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.105/24 brd 192.168.122.255 scope global eth1
    inet6 fe80::5054:ff:feca:4904/64 scope link 
       valid_lft forever preferred_lft forever
[root@money ~]# ip addr change dev eth1 192.168.122.102/24
[root@money ~]# ip addr show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:ca:49:04 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.105/24 brd 192.168.122.255 scope global eth1
    inet 192.168.122.102/24 scope global secondary eth1
    inet6 fe80::5054:ff:feca:4904/64 scope link 
       valid_lft forever preferred_lft forever
 
Old 06-23-2012, 05:32 PM   #2
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,980

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
"ip addr change dev eth1 192.168.122.102/24" Seems odd to me to use the change dev.

ip command is almost too much for anyone. Why they did it I don't know. http://linux.die.net/man/8/ip has the command way done in a confusing place. And it can't be searched by any web search either.

This is a more compact version. http://linux-ip.net/gl/ip-cref/node3.html
 
Old 06-23-2012, 05:39 PM   #3
ohlookpie
LQ Newbie
 
Registered: Apr 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jefro View Post
"ip addr change dev eth1 192.168.122.102/24" Seems odd to me to use the change dev.

ip command is almost too much for anyone. Why they did it I don't know. http://linux.die.net/man/8/ip has the command way done in a confusing place. And it can't be searched by any web search either.

This is a more compact version. http://linux-ip.net/gl/ip-cref/node3.html
Exactly my issue: I could not search the web for the ip command and get any useful documentation. The ip command is preferred by Redhat over the ifconfig command for those doing the RHCSA/RHCE exams. However, I have tried many different things, and I can find no decent way of changing the IP address for a device. The only thing I have discovered is that if I either do an "ip del" and delete the primary IP address, or an "ip flush" and flush all settings, then I can change the IP; but this seems a ridiculous way of doing things.
 
Old 06-23-2012, 06:25 PM   #4
cospengle
Member
 
Registered: Feb 2008
Location: Armidale, NSW, Australia
Distribution: Fedora 8
Posts: 32

Rep: Reputation: 6
I'm not sure if there is a convenient way to change the address as you describe, but adding a new address and removing an old address doesn't seem rediculous to me.

If you had an interface with ten IP addresses how would you know which one you were changing? I think it's better to just add another and remove the one you don't want.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change ip address rust8y Solaris / OpenSolaris 2 11-22-2009 09:35 AM
CentOS command-line Program to Randomly change my MAC address? kexpert Linux - Newbie 3 11-08-2009 12:18 AM
change the PC ip address? malli42108 Linux - Newbie 1 08-14-2009 08:38 AM
OpenBSD: Adding a "lladdr" command to netstart to change MAC address at boot Voltar *BSD 2 04-14-2006 12:41 AM
Need command to change server IP address dimmu Linux - General 3 11-03-2003 04:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration