What is the Linux command to clear IP address of an interface without bringing it down and/or restarting network services. Seems strange ifconfig is able to change IP address but has no option to clear it, or am I wrong?
5 Answers
Use ip
from iproute2. (You need to also specify the prefix length though.)
ip addr del 10.22.30.44/16 dev eth0
To remove all addresses (in case you have multiple):
ip addr flush dev eth0
-
Works, but when I do want to a non-dev permanent change, I get an error saying "eth0 is garbage" (lol). i guess i need to manually edit that file, just can't remember the name right now– The OninApr 11, 2017 at 2:22
-
When setting up a kubernetes cluster I accidently ran a command that created an interface and used an IP address that was being used so I needed to delete that IP address but leave the interface around. This command fixed my problem. I used
sudo ip addr del 192.168.0.1/24 dev weave
. See unix.stackexchange.com/questions/646326/…– PatSApr 23, 2021 at 2:45
To remove all adreses from all interfaces i used for loop:
for i in $(ls /sys/class/net/) ; do
/usr/sbin/ip addr flush $i &
done
Perhaps you are just looking to get a new IP from the [DHCP-enabled] router? In this case call
dhclient eth0
-
THAT worked, whereas assigning an IP didn't somehow get the network working. Thank you.– Rich_FSep 25, 2019 at 11:56
-
1The only problem here is that now you coulld have two ips assigned as
dhclient
just asks for one more IP not checking if one is already there nor deleting the old ips. So delete the unused IP first before you calldhclient
– sebisnowJul 1, 2020 at 8:08
the MAN-Page (BANN-pages for me) makes it not easy to get the DELETE COMMAND! In BSD-world it would be a bug, and even me as newbie have heard of it ...
All the other parameters are listed but the COMMAND part is a sentence, which can easily be "overlooked" in which it says it is commands are possible or NOT!!!!
Very detailed on a very essential function: namely command! Should be rewritten by a pro! (11.2021 - deb 11 - net installed in VBox for LPIC lab of a noob!)
-
I don't understand this answer at all. The sentences seem to be full a hints that I don't understand. An answer to this question should be specific for each operating system which is not mentioned in the question. The excessive use of exclamation marks does not make it easier to understand. Please edit your answer to make it more understable.– r2d3Nov 25, 2021 at 23:40
-
sorry it was only a comment about the man page. I think the thread owner has also tried too use ip-command and overlooked the part in MAN-page about the commands as this part is almost badly described in the man-page.– WebNov 26, 2021 at 9:42
0.0.0.0
-- it's just how it is done withifconfig
.up
you can useip addr flush up