Ip addr del linux

Ip addr del linux

NAME

ip-address - protocol address management

SYNOPSIS

ip [ OPTIONS ] address < COMMAND | help > ip address < add | del > IFADDR dev STRING ip address < show | flush > [ dev STRING ] [ scope SCOPE-ID ] [ to PREFIX ] [ FLAG-LIST ] [ label PATTERN ] IFADDR := PREFIX | ADDR peer PREFIX [ broadcast ADDR ] [ anycast ADDR ] [ label STRING ] [ scope SCOPE-ID ] SCOPE-ID := [ host | link | global | NUMBER ] FLAG-LIST := [ FLAG-LIST ] FLAG FLAG := [ permanent | dynamic | secondary | primary | tentative | deprecated | dadfailed | temporary ]

DESCRIPTION

The address is a protocol (IP or IPv6) address attached to a network device. Each device must have at least one address to use the corresponding protocol. It is possible to have several different addresses attached to one device. These addresses are not discriminated, so that the term alias is not quite appropriate for them and we do not use it in this document. The ip address command displays addresses and their properties, adds new addresses and deletes old ones. ip address add - add new protocol address. dev NAME the name of the device to add the address to. local ADDRESS (default) the address of the interface. The format of the address depends on the protocol. It is a dotted quad for IP and a sequence of hexadecimal halfwords separated by colons for IPv6. The ADDRESS may be followed by a slash and a decimal number which encodes the network prefix length. peer ADDRESS the address of the remote endpoint for pointopoint interfaces. Again, the ADDRESS may be followed by a slash and a decimal number, encoding the network prefix length. If a peer address is specified, the local address cannot have a prefix length. The network prefix is associated with the peer rather than with the local address. broadcast ADDRESS the broadcast address on the interface. It is possible to use the special symbols '+' and '-' instead of the broadcast address. In this case, the broadcast address is derived by setting/resetting the host bits of the interface prefix. label NAME Each address may be tagged with a label string. In order to preserve compatibility with Linux-2.0 net aliases, this string must coincide with the name of the device or must be prefixed with the device name followed by colon. scope SCOPE_VALUE the scope of the area where this address is valid. The available scopes are listed in file /etc/iproute2/rt_scopes. Predefined scope values are: global - the address is globally valid. site - (IPv6 only) the address is site local, i.e. it is valid inside this site. link - the address is link local, i.e. it is valid only on this device. host - the address is valid only inside this host. ip address delete - delete protocol address Arguments: coincide with the arguments of ip addr add. The device name is a required argument. The rest are optional. If no arguments are given, the first address is deleted. ip address show - look at protocol addresses dev NAME (default) name of device. scope SCOPE_VAL only list addresses with this scope. to PREFIX only list addresses matching this prefix. label PATTERN only list addresses with labels matching the PATTERN. PATTERN is a usual shell style pattern. up only list running interfaces. dynamic and permanent (IPv6 only) only list addresses installed due to stateless address configuration or only list permanent (not dynamic) addresses. tentative (IPv6 only) only list addresses which have not yet passed duplicate address detection. deprecated (IPv6 only) only list deprecated addresses. dadfailed (IPv6 only) only list addresses which have failed duplicate address detection. temporary (IPv6 only) only list temporary addresses. primary and secondary only list primary (or secondary) addresses. ip address flush - flush protocol addresses This command flushes the protocol addresses selected by some criteria. This command has the same arguments as show. The difference is that it does not run when no arguments are given. Warning: This command (and other flush commands described below) is pretty dangerous. If you make a mistake, it will not forgive it, but will cruelly purge all the addresses. With the -statistics option, the command becomes verbose. It prints out the number of deleted addresses and the number of rounds made to flush the address list. If this option is given twice, ip address flush also dumps all the deleted addresses in the format described in the previous subsection.

EXAMPLES

ip address show dev eth0 Shows the addresses assigned to network interface eth0 ip addr add 2001:0db8:85a3::0370:7334/64 dev eth1 Adds an IPv6 address to network interface eth1 ip addr flush dev eth4 Removes all addresses from device eth4

Источник

Читайте также:  Узнать версию python linux mint

Properly Remove IP From an Interface Using the ip Command

announcement - icon

The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.

To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.

Connect your cluster and start monitoring your K8s costs right away:

1. Introduction

As system administrators, we usually add multiple IP addresses on the network interface for various reasons such as improving redundancy, hosting multiple applications with DNS, avoiding firewalls, migration, and more.

In this tutorial, we’ll delve into the process of managing secondary IP addresses on Linux machines.

Now, let’s get into the nitty-gritty details of it.

2. Secondary IP Address

The Secondary IP Address is a bind address for the same hardware interface on the machine. It allows us to have two addresses in different subnets, ensuring that the interface is active on more than one subnet simultaneously. Furthermore, it can also facilitate easy and convenient migrations with the ability to grow the IP addressing of the infrastructure without re-numbering it. Sometimes, it’s also referred to as an IP alias:

server# ip addr show enp0s8 3: enp0s8: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:ef:c9:e7 brd ff:ff:ff:ff:ff:ff inet 192.168.56.110/24 brd 192.168.56.255 scope global dynamic noprefixroute enp0s8 valid_lft 531sec preferred_lft 531sec inet6 fe80::8260:b99f:e8d8:8e7/64 scope link noprefixroute valid_lft forever preferred_lft forever

2.1. Temporary IP Allocation

For the sake of demonstration, let’s take an Ubuntu Linux machine for allocating the secondary IP address. We’ll use the ip command to add the secondary address:

server# sudo ip addr add 192.168.56.200/24 dev enp0s8 [sudo] password for tools: server#
server# ip addr show enp0s8 3: enp0s8: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:ef:c9:e7 brd ff:ff:ff:ff:ff:ff inet 192.168.56.111/24 brd 192.168.56.255 scope global dynamic noprefixroute enp0s8 valid_lft 382sec preferred_lft 382sec inet 192.168.56.200/24 scope global secondary enp0s8 valid_lft forever preferred_lft forever inet6 fe80::8260:b99f:e8d8:8e7/64 scope link noprefixroute valid_lft forever preferred_lft forever

Both IP addresses are now reachable from their respective subnets. However, the newly allocated address will be removed once we reboot the machine. So, we’ve got to record the configuration into the network interfaces file for better persistence, which we’ll see in the next section.

Читайте также:  Deleting partitions in linux

2.2. Permanent IP Allocation

Let’s add the secondary interface configuration in the /etc/network/interfaces file:

server# cat /etc/network/interfaces auto enp0s8 iface enp0s8 inet static address 192.168.56.111 netmask 255.255.255.0 network 192.168.56.0 broadcast 192.168.56.255 gateway 192.168.56.1 auto enp0s8 iface enp0s8 inet static address 192.168.56.201 netmask 255.255.255.0

Next, we have to restart the networking services to activate the updated configuration:

server# sudo service networking restart [sudo] password for tools: server#
server# ip addr show enp0s8 3: enp0s8: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:ef:c9:e7 brd ff:ff:ff:ff:ff:ff inet 192.168.56.110/24 brd 192.168.56.255 scope global dynamic noprefixroute enp0s8 valid_lft 382sec preferred_lft 382sec inet 192.168.56.200/24 scope global secondary enp0s8 valid_lft forever preferred_lft forever inet6 fe80::8260:b99f:e8d8:8e7/64 scope link noprefixroute valid_lft forever preferred_lft forever

At times, we can also clear the allocated interface addresses if addresses are not allocated properly.

Lastly, we need to restart the networking services on the machine:

server# sudo ip addr flush dev enp0s8 server#

3. Safe Removal of IP Address

During the process of migration, we can either use the ip addr del command for quick removal of the address from the interface, or the address configurations from the /etc/network/interfaces file for permanent removal:

server# sudo ip addr del 192.168.56.110/24 dev enp0s8 server#
server# ip addr show enp0s8 3: enp0s8: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:ef:c9:e7 brd ff:ff:ff:ff:ff:ff inet 192.168.56.200/24 brd 192.168.56.255 scope global noprefixroute enp0s8 valid_lft forever preferred_lft forever inet6 fe80::8260:b99f:e8d8:8e7/64 scope link noprefixroute valid_lft forever preferred_lft forever

Furthermore, we can check the network packet drop during this activity by enabling continuous ICMP ping from the client side:

C:\Users\client>ping -t 192.168.56.200 Pinging 192.168.56.200 with 32 bytes of data: Reply from 192.168.56.200: bytes=32 time

4. Conclusion

In summary, we’ve explored ways to add secondary IP addresses temporarily on a network interface and permanently on the file. We’ve also learned how to use the ip command to safely remove the active IP address from the server interface without any network packets being dropped.

Источник

Оцените статью
Adblock
detector