How can I clear the IP address of Ethernet interface without cycling the interface up/down or restarting it

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

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 
2

As simple as ifconfig eth0 0.0.0.0. They should have put it in the manual.

0

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

2

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

2

You Might Also Like