Este contenido no está disponible en el idioma seleccionado.
Chapter 29. Starting a service within an isolated VRF network
With virtual routing and forwarding (VRF), you can create isolated networks with a routing table that is different to the main routing table of the operating system. You can then start services and applications so that they have only access to the network defined in that routing table.
29.1. Configuring a VRF device Copiar enlaceEnlace copiado en el portapapeles!
To use virtual routing and forwarding (VRF), you create a VRF device and attach a physical or virtual network interface and routing information to it.
To prevent that you lock out yourself out remotely, perform this procedure on the local console or remotely over a network interface that you do not want to assign to the VRF device.
Prerequisites
- You are logged in locally or using a network interface that is different to the one you want to assign to the VRF device.
Procedure
Create the
vrf0connection with a same-named virtual device, and attach it to routing table1000:nmcli connection add type vrf ifname vrf0 con-name vrf0 table 1000 ipv4.method disabled ipv6.method disabled
# nmcli connection add type vrf ifname vrf0 con-name vrf0 table 1000 ipv4.method disabled ipv6.method disabledCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the
enp1s0device to thevrf0connection, and configure the IP settings:nmcli connection add type ethernet con-name enp1s0 ifname enp1s0 controller vrf0 ipv4.method manual ipv4.address 192.0.2.1/24 ipv4.gateway 192.0.2.254
# nmcli connection add type ethernet con-name enp1s0 ifname enp1s0 controller vrf0 ipv4.method manual ipv4.address 192.0.2.1/24 ipv4.gateway 192.0.2.254Copy to Clipboard Copied! Toggle word wrap Toggle overflow This command creates the
enp1s0connection as a port of thevrf0connection. Due to this configuration, the routing information are automatically assigned to the routing table1000that is associated with thevrf0device.If you require static routes in the isolated network:
Add the static routes:
nmcli connection modify enp1s0 +ipv4.routes "198.51.100.0/24 192.0.2.2"
# nmcli connection modify enp1s0 +ipv4.routes "198.51.100.0/24 192.0.2.2"Copy to Clipboard Copied! Toggle word wrap Toggle overflow This adds a route to the
198.51.100.0/24network that uses192.0.2.2as the router.Activate the connection:
nmcli connection up enp1s0
# nmcli connection up enp1s0Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display the IP settings of the device that is associated with
vrf0:ip -br addr show vrf vrf0
# ip -br addr show vrf vrf0 enp1s0 UP 192.0.2.1/24Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display the VRF devices and their associated routing table:
ip vrf show
# ip vrf show Name Table ----------------------- vrf0 1000Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display the main routing table:
ip route show
# ip route show default via 203.0.113.0/24 dev enp7s0 proto static metric 100Copy to Clipboard Copied! Toggle word wrap Toggle overflow The main routing table does not mention any routes associated with the device
enp1s0device or the192.0.2.1/24subnet.Display the routing table
1000:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
defaultentry indicates that services that use this routing table, use192.0.2.254as their default gateway and not the default gateway in the main routing table.Execute the
tracerouteutility in the network associated withvrf0to verify that the utility uses the route from table1000:ip vrf exec vrf0 traceroute 203.0.113.1
# ip vrf exec vrf0 traceroute 203.0.113.1 traceroute to 203.0.113.1 (203.0.113.1), 30 hops max, 60 byte packets 1 192.0.2.254 (192.0.2.254) 0.516 ms 0.459 ms 0.430 ms ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow The first hop is the default gateway that is assigned to the routing table
1000and not the default gateway from the system’s main routing table.
29.2. Starting a service within an isolated VRF network Copiar enlaceEnlace copiado en el portapapeles!
You can configure a service, such as the Apache HTTP Server, to start within an isolated virtual routing and forwarding (VRF) network.
Services can only bind to local IP addresses that are in the same VRF network.
Prerequisites
-
You configured the
vrf0device. -
You configured Apache HTTP Server to listen only on the IP address that is assigned to the interface associated with the
vrf0device.
Procedure
Display the content of the
httpdsystemd service:systemctl cat httpd ... [Service] ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND ...
# systemctl cat httpd ... [Service] ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow You require the content of the
ExecStartparameter in a later step to run the same command within the isolated VRF network.Create the
/etc/systemd/system/httpd.service.d/directory:mkdir /etc/systemd/system/httpd.service.d/
# mkdir /etc/systemd/system/httpd.service.d/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
/etc/systemd/system/httpd.service.d/override.conffile with the following content:[Service] ExecStart= ExecStart=/usr/sbin/ip vrf exec vrf0 /usr/sbin/httpd $OPTIONS -DFOREGROUND
[Service] ExecStart= ExecStart=/usr/sbin/ip vrf exec vrf0 /usr/sbin/httpd $OPTIONS -DFOREGROUNDCopy to Clipboard Copied! Toggle word wrap Toggle overflow To override the
ExecStartparameter, you first need to unset it and then set it to the new value as shown.Reload systemd.
systemctl daemon-reload
# systemctl daemon-reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow Restart the
httpdservice.systemctl restart httpd
# systemctl restart httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display the process IDs (PID) of
httpdprocesses:pidof -c httpd
# pidof -c httpd 1904 ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display the VRF association for the PIDs, for example:
ip vrf identify 1904
# ip vrf identify 1904 vrf0Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display all PIDs associated with the
vrf0device:ip vrf pids vrf0
# ip vrf pids vrf0 1904 httpd ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow