3

When I need to create a temporary bridge with interface on Linux I would use the following:

brctl addbr br0
brctl addif br0 eth0
ifconfig eth0 0.0.0.0
ifconfig br0 192.168.10.100 netmask 255.255.255.0
ifconfig br0 up

I have been updating my process to use the ip command, However, I do not find the equivalent for removing the IP stack (ifconfig eth0 0.0.0.0) via the ip command

I have tried the following:

ip addr add 0.0.0.0 dev eth0
ip addr add 0.0.0.0/24 dev eth0

but it does not work to remove the existing ip on that device.

would anyone happen to know if this is possible with the ip command

1

On Linux, the old ifconfig command and its old Linux kernel API is limited to one IPv4 address per interface (and so interface aliases, which are really additional addresses rather than interfaces, are used to work around this limitation). This explains why to remove the IPv4 address, the method was to set it to (not really add) 0.0.0.0.

With iproute2 tools, if you want to remove any address from an interface (always a good idea for a bridge port) without caring what address(es) are there, you can use ip address flush, which is a bulk removal command:

ip address flush - flush protocol addresses

This command flushes the protocol addresses selected by some criteria.

[...]

Warning: This command and other flush commands are unforgiving. They will cruelly purge all the addresses.

[...]

So in the end you can use:

ip address flush dev eth0

(you could add -4 to limit the effect to IPv4).


There are other uses. For example this command:

  ip address flush to 10.1.0.0/16

would remove from any interface any address matching the block 10.1.0.0/16 whatever its netmask.

# ip -s -s address flush to 10.1.0.0/16
2: lxcbr0    inet 10.1.3.1/24 brd 10.1.3.255 scope global lxcbr0
       valid_lft forever preferred_lft forever
158: eth0    inet 10.1.1.1/8 scope global eth0
       valid_lft forever preferred_lft forever

*** Round 1, deleting 2 addresses ***
*** Flush is complete after 1 round ***
1
  • Great answer, thank you for giving such a complete response – marshelgot Dec 4 '20 at 13:41
0

You can't delete an IP address with the add command!

If you want to delete an IP address from an interface, you del it.

ip addr del 203.0.113.187 dev eth0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.