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

81

24

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?

jackhab

Posted 2010-06-17T07:49:54.313

Reputation: 2 176

1@Andy: I think you misunderstood the question. @jackhab wants to unassign an address from the interface, not set it to 0.0.0.0 -- it's just how it is done with ifconfig. – user1686 – 2010-06-17T10:36:10.670

@grawity Cheers. Unassigning an address is switching the NIC off to all intents and purposes? – Andy – 2010-06-17T11:03:03.400

@Andy: Not necessarily. One could still watch incoming packets. Also, a NIC can have multiple addresses (though it doesn't apply in this case). – user1686 – 2010-06-17T21:33:10.277

Answers

142

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

user1686

Posted 2010-06-17T07:49:54.313

Reputation: 283 655

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 – Housemd – 2017-04-11T02:22:57.767

23

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

jackhab

Posted 2010-06-17T07:49:54.313

Reputation: 2 176

11

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

eri

Posted 2010-06-17T07:49:54.313

Reputation: 246

1

Perhaps you are just looking to get a new IP from the [DHCP-enabled] router? In this case call

dhclient eth0

CodyBugstein

Posted 2010-06-17T07:49:54.313

Reputation: 1 174

THAT worked, whereas assigning an IP didn't somehow get the network working. Thank you. – Rich_F – 2019-09-25T11:56:04.290