Chapter 13. Reusing the same IP address on different interfaces
With Virtual routing and forwarding (VRF), administrators can use multiple routing tables simultaneously on the same host. For that, VRF partitions a network at layer 3. This enables the administrator to isolate traffic using separate and independent route tables per VRF domain. This technique is similar to virtual LANs (VLAN), which partitions a network at layer 2, where the operating system uses different VLAN tags to isolate traffic sharing the same physical medium.
One benefit of VRF over partitioning on layer 2 is that routing scales better considering the number of peers involved.
Red Hat Enterprise Linux uses a virtual vrt
device for each VRF domain and adds routes to a VRF domain by adding existing network devices to a VRF device. Addresses and routes previously attached to the original device will be moved inside the VRF domain.
Note that each VRF domain is isolated from each other.
13.1. Permanently reusing the same IP address on different interfaces
You can use the virtual routing and forwarding (VRF) feature to permanently use the same IP address on different interfaces in one server.
To enable remote peers to contact both VRF interfaces while reusing the same IP address, the network interfaces must belong to different broadcasting domains. A broadcast domain in a network is a set of nodes, which receive broadcast traffic sent by any of them. In most configurations, all nodes connected to the same switch belong to the same broadcasting domain.
Prerequisites
-
You are logged in as the
root
user. - The network interfaces are not configured.
Procedure
Create and configure the first VRF device:
Create a connection for the VRF device and assign it to a routing table. For example, to create a VRF device named
vrf0
that is assigned to the1001
routing table:# nmcli connection add type vrf ifname vrf0 con-name vrf0 table 1001 ipv4.method disabled ipv6.method disabled
Enable the
vrf0
device:# nmcli connection up vrf0
Assign a network device to the VRF just created. For example, to add the
enp1s0
Ethernet device to thevrf0
VRF device and assign an IP address and the subnet mask toenp1s0
, enter:# nmcli connection add type ethernet con-name vrf.enp1s0 ifname enp1s0 master vrf0 ipv4.method manual ipv4.address 192.0.2.1/24
Activate the
vrf.enp1s0
connection:# nmcli connection up vrf.enp1s0
Create and configure the next VRF device:
Create the VRF device and assign it to a routing table. For example, to create a VRF device named
vrf1
that is assigned to the1002
routing table, enter:# nmcli connection add type vrf ifname vrf1 con-name vrf1 table 1002 ipv4.method disabled ipv6.method disabled
Activate the
vrf1
device:# nmcli connection up vrf1
Assign a network device to the VRF just created. For example, to add the
enp7s0
Ethernet device to thevrf1
VRF device and assign an IP address and the subnet mask toenp7s0
, enter:# nmcli connection add type ethernet con-name vrf.enp7s0 ifname enp7s0 master vrf1 ipv4.method manual ipv4.address 192.0.2.1/24
Activate the
vrf.enp7s0
device:# nmcli connection up vrf.enp7s0
13.2. Temporarily reusing the same IP address on different interfaces
You can use the virtual routing and forwarding (VRF) feature to temporarily use the same IP address on different interfaces in one server. Use this procedure only for testing purposes, because the configuration is temporary and lost after you reboot the system.
To enable remote peers to contact both VRF interfaces while reusing the same IP address, the network interfaces must belong to different broadcasting domains. A broadcast domain in a network is a set of nodes which receive broadcast traffic sent by any of them. In most configurations, all nodes connected to the same switch belong to the same broadcasting domain.
Prerequisites
-
You are logged in as the
root
user. - The network interfaces are not configured.
Procedure
Create and configure the first VRF device:
Create the VRF device and assign it to a routing table. For example, to create a VRF device named
blue
that is assigned to the1001
routing table:# ip link add dev blue type vrf table 1001
Enable the
blue
device:# ip link set dev blue up
Assign a network device to the VRF device. For example, to add the
enp1s0
Ethernet device to theblue
VRF device:# ip link set dev enp1s0 master blue
Enable the
enp1s0
device:# ip link set dev enp1s0 up
Assign an IP address and subnet mask to the
enp1s0
device. For example, to set it to192.0.2.1/24
:# ip addr add dev enp1s0 192.0.2.1/24
Create and configure the next VRF device:
Create the VRF device and assign it to a routing table. For example, to create a VRF device named
red
that is assigned to the1002
routing table:# ip link add dev red type vrf table 1002
Enable the
red
device:# ip link set dev red up
Assign a network device to the VRF device. For example, to add the
enp7s0
Ethernet device to thered
VRF device:# ip link set dev enp7s0 master red
Enable the
enp7s0
device:# ip link set dev enp7s0 up
Assign the same IP address and subnet mask to the
enp7s0
device as you used forenp1s0
in theblue
VRF domain:# ip addr add dev enp7s0 192.0.2.1/24
- Optional: Create further VRF devices as described above.
13.3. Additional resources
-
/usr/share/doc/kernel-doc-<kernel_version>/Documentation/networking/vrf.txt
from thekernel-doc
package