Manually Configuring IPv4 and IPv6 Policy-based Routes for a Linux ECS with Multiple Network Interfaces (Huawei Cloud EulerOS)
Scenarios
This section describes how to configure policy-based routes for an ECS with two network interfaces running Huawei Cloud EulerOS 2.0 Standard 64 bit.
- IPv4: If IPv4 communication between ECSs with multiple network interfaces is required, you need to configure IPv4 routes by referring to Configuring Policy-based Routes for Linux ECSs Using IPv4 Addresses (Huawei Cloud EulerOS).
- IPv6: If IPv6 communication between ECSs with multiple network interfaces is required, you need to configure IPv6 routes by referring to Configuring Policy-based Routes for Linux ECSs Using IPv6 Addresses (Huawei Cloud EulerOS).
- IPv4/IPv6 dual stack: If both IPv4 and IPv6 communications between ECSs with multiple network interfaces are required, you need to configure both IPv4 and IPv6 routes by referring to Configuring Policy-based Routes for Linux ECSs Using IPv4 Addresses (Huawei Cloud EulerOS) and Configuring Policy-based Routes for Linux ECSs Using IPv6 Addresses (Huawei Cloud EulerOS).
For details about the background knowledge and networking of an ECS with two network interfaces, see Overview.
Configuring Policy-based Routes for Linux ECSs Using IPv4 Addresses (Huawei Cloud EulerOS)
- Collect the ECS network interface information required for configuring policy-based routes.
For details, see Collecting ECS Network Information.
In this example, the network information of the ECS is shown in Table 1.
Table 1 Linux ECSs using IPv4 addresses (Huawei Cloud EulerOS) Type
Primary Network Interface
Extended Network Interface
Source
- Network interface IP address: 10.0.0.125
- Subnet: 10.0.0.0/24
- Subnet gateway: 10.0.0.1
- Network interface IP address: 10.0.1.16
- Subnet: 10.0.1.0/24
- Subnet gateway: 10.0.1.1
Destination
Network interface IP address: 10.0.2.180
N/A
- Log in to the source ECS.
For details, see How Do I Log In to My ECS?
- Check whether the source ECS can use its primary network interface to communicate with the destination ECS:
Before configuring policy-based routes, ensure that the source ECS can use its primary network interface to communicate with the destination ECS.
ping -I IP-address-of-the-primary-network-interface-on-the-source-ECS IP-address-of-the-destination-ECS
Example command:
ping -I 10.0.0.125 10.0.2.180
If information similar to the following is displayed, the source ECS can use its primary network interface to communicate with the destination ECS.[root@ecs-s ~]# ping -I 10.0.1.125 10.0.3.180 PING 10.0.3.180 (10.0.3.180) from 10.0.1.125 : 56(84) bytes of data. 64 bytes from 10.0.3.180: icmp_seq=1 ttl=64 time=1.11 ms 64 bytes from 10.0.3.180: icmp_seq=2 ttl=64 time=0.542 ms 64 bytes from 10.0.3.180: icmp_seq=3 ttl=64 time=0.262 ms 64 bytes from 10.0.3.188: icmp_seq=4 ttl=64 time=0.225 ms ^C -- 10.0.3.180 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3049ms rtt min/avg/max/mdev = 0.225/0.533/1.106/0.352 ms
- Query the network interface names of the source ECS: Search for the network interface names based on IP addresses.
- The IP address of the primary network interface is 10.0.0.125, and its name is eth0.
- The IP address of the extended network interface is 10.0.1.16, and its name is eth1.
[root@ecs-s "l# ip addr ... 2: eth0: <BROADCAST,MULTICAST,UP,LOWER UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether fa:16:3e:07:07:84 brd ff :ff :ff :ff :ff :ff altname enp0s3 altname ens3 inet 10.0.0.125/24 brd 10.0.0.255 scope global dynamic noprefixroute eth0 valid 1ft 315359965sec preferred_lft 315359965sec inet6 fe80::f816:3eff:fe07:784/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether fa:16:3e:07:08:17 brd ff :ff :ff :ff :ff :ff altname enp4s1 inet 10.0.1.16/24 brd 10.0.1.255 scope global dynamic noprefixroute eth1 valid_lft 315359965sec preferred_lft 315359965sec inet6 fe80::f816:3eff:fe07:817/64 scope link valid_lft forever preferred_lft forever - Configure temporary routes for the source ECS.
- Configure policy-based routes for both the primary and extended network interfaces.
- Primary network interface
ip route add default via subnet-gateway dev network-interface-name table route-table-name
ip route add subnet-CIDR-block dev network-interface-name table route-table-name
ip rule add from network-interface-address table route-table-name
- Extended network interface
ip route add default via subnet-gateway dev network-interface-name table route-table-name
ip route add subnet-CIDR-block dev network-interface-name table route-table-name
ip rule add from network-interface-address table route-table-name
Configure the parameters as follows:Example commands:
- Primary network interface
ip route add default via 10.0.0.1 dev eth0 table 10
ip route add 10.0.0.0/24 dev eth0 table 10
ip rule add from 10.0.0.125 table 10
- Extended network interface
ip route add default via 10.0.1.1 dev eth1 table 20
ip route add 10.0.1.0/24 dev eth1 table 20
ip rule add from 10.0.1.16 table 20
If the ECS has multiple network interfaces, configure policy-based routes for all network interfaces one by one.
- Primary network interface
- Check whether the policy-based routes are added.
ip route show table route-table-name-of-the-primary-network-interface
ip route show table route-table-name-of-the-extended-network-interface
The route table name is the one configured in 5.a.
Example commands:
ip rule
ip route show table 10
ip route show table 20
If information similar to the following is displayed, the policy-based routes have been added.[root@ecs-s ~]# ip rule 0: from all lookup local 32764: from 10.0.1.16 lookup 20 32765: from 10.0.0.125 lookup 10 32766: from all lookup main 32767: from all lookup default [rootlecs-s ~# ip route show table 10 default via 10.0.0.1 dev eth0 10.0.0.0/24 dev eth0 scope link [root@ecs-s ~]# ip route show table 20 default via 10.0.1.1 dev eth1 10.0.1.0/24 dev eth1 scope link
- Check whether the source and destination ECSs can communicate with each other.
ping -I IP-address-of-the-primary-network-interface-on-the-source-ECS IP-address-of-the-destination-ECS
ping -I IP-address-of-the-extended-network-interface-on-the-source-ECS IP-address-of-the-destination-ECS
Example commands:
ping -I 10.0.0.125 10.0.2.180
ping -I 10.0.1.16 10.0.2.180
If information similar to the following is displayed, both the network interfaces of the source ECS can communicate with the destination ECS.[root@ecs-s ~1# ping -I 10.0.0.125 10.0.2.180 PING 10.0.2.180 (10.0.2.180) from 10.0.0.125 : 56(84) bytes 0f data. 64 bytes from 10.0.2.180: icmp_seq=1 ttl=64 time=1.12ms 64 bytes from 10.0.2.180: icmp_seq=2 ttl=64 time=0.309ms 64 bytes from 10.0.2.180: icmp_seq=3 ttl=64 time=0.342 ms ^C --10.0.2.180 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2039ms rtt min/avg/max/mdeu = 0.309/0.588/1.115/0.372ms [root@ecs-s ~]# ping -I 10.0.1.16 10.0.2.180 PING 10.0.2.180 (10.0.2.180) from 10.0.1.16 : 56(84) bytes 0f data. 64 bytes from 10.0.2.180: icmp_seq=1 ttl=64 time=1.50 ms 64 bytes from 10.0.2.180: icmp_seq=2 ttl=64 time=0.384 ms 64 bytes from 10.0.2.180: icmp_seq=3 ttl=64 time=0.369 ms ^C -- 10.0.2.180 ping statistics --- 3 packets transmitted,3 received, 0% packet loss, time 2005ms rtt min/avg/max/mdeu = 0.369/0.749/1.495/0.522ms
- Configure policy-based routes for both the primary and extended network interfaces.
- Configure permanent routes for the source ECS.
- Run the following command to add the network-routes.service file to the systemd service:
vi /etc/systemd/system/network-routes.service
- Press i to enter the editing mode.
- Add the following content to the end of the file:
[Unit] Description=Network Routes Configuration After=network.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/bash -c 'for((x=0; x<10; x++)); do [[ $(ip addr show eth0 | grep -w 10.0.0.125 >/dev/null 2>&1 && echo 1) ]] && break; sleep 1; done; ip route flush table 10; ip route add default via 10.0.0.1 dev eth0 table 10; ip route add 10.0.0.0/24 dev eth0 table 10; ip rule add from 10.0.0.125 table 10; for((x=0; x<10; x++)); do [[ $(ip addr show eth1 | grep -w 10.0.1.16 >/dev/null 2>&1 && echo 1) ]] && break; sleep 1; done; ip route flush table 20; ip route add default via 10.0.1.1 dev eth1 table 20; ip route add 10.0.1.0/24 dev eth1 table 20; ip rule add from 10.0.1.16 table 20; ip rule add to 169.254.169.254 table main' [Install] WantedBy=multi-user.target
The parameters are as follows:
- for loop: Check whether eth0 or eth1 has obtained an IPv4 address (eth0: 10.0.0.125; eth1: 10.0.1.16) every second up to 10 times.
- ip route flush table route-table-name: Running this command will delete existing routes from the specified route table. This prevents new routes from being affected.
- Policy-based routes of the primary network interface: Set it to the same value as that in 5.a.
- Policy-based routes of the extended network interface: Set it to the same value as that in 5.a.
- ip rule add to 169.254.169.254 table main: Set the Cloud-Init address to the same value as that in this example.
- Press ESC to exit and enter :wq! to save the configuration.
- Run the following commands to reload the systemd configuration and start the service:
systemctl enable network-routes.service
If information similar to the following is displayed, the service is started:[root@ecs-s ~]# systemctl daemon-reload [root@ecs-s ~]# systemctl enable network-routes.service Created symlink /etc/systemd/system/multi-user.target.wants/network-routes.service → /etc/systemd/system/network-routes.service.
- Run the following command to restart the source ECS:
Policy-based routes added to the network-routes.service file only work after the source ECS is restarted. Ensure that workloads on the ECS will not be affected before restarting the ECS.
- Repeat 5.b to 5.c to check whether the policy-based routes are added and whether the source ECS and the destination ECS can communicate with each other.
- Run the following command to add the network-routes.service file to the systemd service:
Configuring Policy-based Routes for Linux ECSs Using IPv6 Addresses (Huawei Cloud EulerOS)
- Collect the ECS network interface information required for configuring policy-based routes.
For details, see Collecting ECS Network Information.
Table 2 Linux ECSs using IPv6 addresses (Huawei Cloud EulerOS) Type
Primary Network Interface
Extended Network Interface
Source
- Network interface IPv4 address: 10.0.0.125
- Network interface IPv6 address: 2407:c080:802:221c:5e76:7761:8d54:4ebc
- Subnet IPv6 CIDR block: 2407:c080:802:221c::/64
- Subnet IPv6 gateway: 2407:c080:802:221c::1
- Network interface IPv4 address: 10.0.1.16
- Network interface IPv6 address: 2407:c080:802:221d:3be1:c05a:345c:4802
- Subnet IPv6 CIDR block: 2407:c080:802:221d::/64
- Subnet IPv6 gateway: 2407:c080:802:221d::1
Destination
- Network interface IPv4 address: 10.0.2.180
- Network interface IPv6 address: 2407:c080:802:1744:5df4:f1d3:cb97:2eb3
N/A
- Log in to the source ECS.
For details, see How Do I Log In to My ECS?
- Check whether the ECSs have IPv6 enabled and have IPv6 addresses.
Perform this step for both the source and destination ECSs to ensure that the ECSs have IPv6 addresses. Otherwise, the ECSs cannot communicate with each other using IPv6 addresses.
ECSs in this example run CentOS 8.0 (64-bit). For details about how to assign IPv6 addresses for ECSs running other OSs, see Linux (Manually Enabling Dynamic Assignment of IPv6 Addresses).
- Run the following command to check whether the source ECS has IPv6 addresses: In the following command output, eth0 and eth1 are the network interfaces of the ECS. Each network interface has one inet6 entry starting with fe80. This indicates that the ECS has IPv6 enabled but does not have IPv6 addresses assigned. In this case, perform 3.b to 3.g to obtain IPv6 addresses.
[root@ecs-s ~]# ip addr ... 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether fa:16:3e:c0:c0:3d brd ff:ff:ff:ff:ff:ff inet 10.0.0.125/24 brd 10.0.0.255 scope global dynamic noprefixroute eth0 valid_lft 315359743sec preferred_lft 315359743sec inet6 fe80::f816:3eff:fec0:c03d/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether fa:16:3e:c0:c1:d0 brd ff:ff:ff:ff:ff:ff inet 10.0.1.16/24 brd 10.0.1.255 scope global dynamic noprefixroute eth1 valid_lft 315359743sec preferred_lft 315359743sec inet6 fe80::f816:3eff:fec0:c1d0/64 scope link valid_lft forever preferred_lft forever - Query the network interface names of the source ECS: Search for the network interface names based on IP addresses.
- The IP address of the primary network interface is 10.0.0.125, and its name is eth0.
- The IP address of the extended network interface is 10.0.1.16, and its name is eth1.
[root@ecs-s ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.0.125 netmask 255.255.255.0 broadcast 10.0.0.255 inet6 fe80::f816:3eff:fec0:c03d prefixlen 64 scopeid 0x20<link> ether fa:16:3e:c0:c0:3d txqueuelen 1000 (Ethernet) RX packets 94157 bytes 135947002 (129.6 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 9283 bytes 837900 (818.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.1.16 netmask 255.255.255.0 broadcast 10.0.1.255 inet6 fe80::f816:3eff:fec0:c1d0 prefixlen 64 scopeid 0x20<link> ether fa:16:3e:c0:c1:d0 txqueuelen 1000 (Ethernet) RX packets 6 bytes 1176 (1.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6 bytes 768 (768.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ... - Configure the ifcfg file of the primary network interface.
- Run the following command to open the ifcfg file of the primary network interface:
vi /etc/sysconfig/network-scripts/ifcfg-primary-network-interface-name
The name of the primary network interface is obtained in 3.b.
Example command:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
- Press i to enter the editing mode.
- Add the following content to the end of the file:
IPV6INIT="yes" DHCPV6C="yes"
- Press ESC to exit and enter :wq! to save the configuration.
- Run the following command to open the ifcfg file of the primary network interface:
- Configure the ifcfg file of the extended network interface.
- Run the following command to open the ifcfg file of the extended network interface:
vi /etc/sysconfig/network-scripts/ifcfg-extended-network-interface-name
The name of the extended network interface is obtained in 3.b.
Example command:
vi /etc/sysconfig/network-scripts/ifcfg-eth1
- Press i to enter the editing mode.
- Add the following content to the end of the file:
IPV6INIT="yes" DHCPV6C="yes"
- Press ESC to exit and enter :wq! to save the configuration.
- Run the following command to open the ifcfg file of the extended network interface:
- Edit the /etc/sysconfig/network file.
- Run the following command to open the /etc/sysconfig/network file:
vi /etc/sysconfig/network
- Press i to enter the editing mode.
- Add the following content to the end of the file:
NETWORKING_IPV6="yes"
- Press ESC to exit and enter :wq! to save the configuration.
- Run the following command to open the /etc/sysconfig/network file:
- Run the following command to restart the network service for the configuration to take effect:
- Run the following command to check whether the source ECS has IPv6 addresses: In the following command output, each network interface has two inet6 entries, with one newly added that begins with 2407. This indicates that the ECS has IPv6 addresses.
[root@ecs-s ~]# ip addr ... 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether fa:16:3e:c0:c0:3d brd ff:ff:ff:ff:ff:ff inet 10.0.0.125/24 brd 10.0.0.255 scope global dynamic noprefixroute eth0 valid_lft 315359992sec preferred_lft 315359992sec inet6 2407:c080:802:221c:5e76:7761:8d54:4ebc/128 scope global dynamic noprefixroute valid_lft 7192sec preferred_lft 7192sec inet6 fe80::f816:3eff:fec0:c03d/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether fa:16:3e:c0:c1:d0 brd ff:ff:ff:ff:ff:ff inet 10.0.1.16/24 brd 10.0.1.255 scope global dynamic noprefixroute eth1 valid_lft 315359992sec preferred_lft 315359992sec inet6 2407:c080:802:221d:3be1:c05a:345c:4802/128 scope global dynamic noprefixroute valid_lft 7192sec preferred_lft 7192sec inet6 fe80::f816:3eff:fec0:c1d0/64 scope link noprefixroute valid_lft forever preferred_lft forever - Log in to the destination ECS and obtain an IPv6 address by performing operations from 3.a to 3.g.
- Run the following command to check whether the source ECS has IPv6 addresses:
- Log in to the source ECS and check whether it can use its primary network interface to communicate with the destination ECS:
Before configuring policy-based routes, ensure that the source ECS can use its primary network interface to communicate with the destination ECS.
ping6 -I IP-address-of-the-primary-network-interface-on-the-source-ECS IP-address-of-the-destination-ECS
Example command:
ping6 -I 2407:c080:802:221c:5e76:7761:8d54:4ebc 2407:c080:802:1744:5df4:f1d3:cb97:2eb3
If information similar to the following is displayed, the source ECS can use its primary network interface to communicate with the destination ECS.[root@ecs-s ~]# ping6 -I 2407:c080:802:221c:5e76:7761:8d54:4ebc 2407:c080:802:1744:5df4:f1d3:cb97:2eb3 PING 2407:c080:802:1744:5df4:f1d3:cb97:2eb3(2407:c080:802:1744:5df4:f1d3:cb97:2eb3) from 2407:c080:802:221c:5e76:7761:8d54:4ebc : 56 data bytes 64 bytes from 2407:c080:802:1744:5df4:f1d3:cb97:2eb3: icmp_seq=1 ttl=64 time=0.264 ms 64 bytes from 2407:c080:802:1744:5df4:f1d3:cb97:2eb3: icmp_seq=2 ttl=64 time=0.180 ms 64 bytes from 2407:c080:802:1744:5df4:f1d3:cb97:2eb3: icmp_seq=3 ttl=64 time=0.107 ms ^C --- 2407:c080:802:1744:5df4:f1d3:cb97:2eb3 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2038ms rtt min/avg/max/mdev = 0.107/0.183/0.264/0.064 ms
- Log in to the source ECS and configure temporary routes for the ECS.
- Configure policy-based routes for both the primary and extended network interfaces.
- Primary network interface
ip -6 route add default via subnet-gateway dev network-interface-name table route-table-name
ip -6 route add subnet-CIDR-block dev network-interface-name table route-table-name
ip -6 rule add from network-interface-address table route-table-name
- Extended network interface
ip -6 route add default via subnet-gateway dev network-interface-name table route-table-name
ip -6 route add subnet-CIDR-block dev network-interface-name table route-table-name
ip -6 rule add from network-interface-address table route-table-name
Configure the parameters as follows:Example commands:
- Primary network interface
ip -6 route add default via 2407:c080:802:221c::1 dev eth0 table 10
ip -6 route add 2407:c080:802:221c::/64 dev eth0 table 10
ip -6 rule add from 2407:c080:802:221c:5e76:7761:8d54:4ebc table 10
- Extended network interface
ip -6 route add default via 2407:c080:802:221d::1 dev eth1 table 20
ip -6 route add 2407:c080:802:221d::/64 dev eth1 table 20
ip -6 rule add from 2407:c080:802:221d:3be1:c05a:345c:4802 table 20
If the ECS has multiple network interfaces, configure policy-based routes for all network interfaces one by one.
- Primary network interface
- Check whether the policy-based routes are added.
ip -6 route show table route-table-name-of-the-primary-network-interface
ip -6 route show table route-table-name-of-the-extended-network-interface
The route table name is the one configured in 5.a.
Example commands:
ip -6 rule
ip -6 route show table 10
ip -6 route show table 20
If information similar to the following is displayed, the policy-based routes have been added.[root@ecs-s ~]# ip -6 rule 0: from all lookup local 32764: from 2407:c080:802:221d:3be1:c05a:345c:4802 lookup 20 32765: from 2407:c080:802:221c:5e76:7761:8d54:4ebc lookup 10 32766: from all lookup main [root@ecs-s ~]# ip -6 route show table 10 2407:c080:802:221c::/64 dev eth0 metric 1024 pref medium default via 2407:c080:802:221c::1 dev eth0 metric 1024 pref medium [root@ecs-s ~]# ip -6 route show table 20 2407:c080:802:221d::/64 dev eth1 metric 1024 pref medium default via 2407:c080:802:221d::1 dev eth1 metric 1024 pref medium
- Check whether the source and destination ECSs can communicate with each other.
ping6 -I IP-address-of-the-primary-network-interface-on-the-source-ECS IP-address-of-the-destination-ECS
ping6 -I IP-address-of-the-extended-network-interface-on-the-source-ECS IP-address-of-the-destination-ECS
Example commands:
ping6 -I 2407:c080:802:221c:5e76:7761:8d54:4ebc 2407:c080:802:1744:5df4:f1d3:cb97:2eb3
ping6 -I 2407:c080:802:221d:3be1:c05a:345c:4802 2407:c080:802:1744:5df4:f1d3:cb97:2eb3
If information similar to the following is displayed, both the network interfaces of the source ECS can communicate with the destination ECS.[root@ecs-s ~]# ping6 -I 2407:c080:802:221c:5e76:7761:8d54:4ebc 2407:c080:802:1744:5df4:f1d3:cb97:2eb3 PING 2407:c080:802:1744:5df4:f1d3:cb97:2eb3(2407:c080:802:1744:5df4:f1d3:cb97:2eb3) from 2407:c080:802:221c:5e76:7761:8d54:4ebc : 56 data bytes 64 bytes from 2407:c080:802:1744:5df4:f1d3:cb97:2eb3: icmp_seq=1 ttl=64 time=0.316 ms 64 bytes from 2407:c080:802:1744:5df4:f1d3:cb97:2eb3: icmp_seq=2 ttl=64 time=0.190 ms 64 bytes from 2407:c080:802:1744:5df4:f1d3:cb97:2eb3: icmp_seq=3 ttl=64 time=0.114 ms ^C --- 2407:c080:802:1744:5df4:f1d3:cb97:2eb3 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2082ms rtt min/avg/max/mdev = 0.114/0.206/0.316/0.083 ms [root@ecs-s ~]# ping6 -I 2407:c080:802:221d:3be1:c05a:345c:4802 2407:c080:802:1744:5df4:f1d3:cb97:2eb3 PING 2407:c080:802:1744:5df4:f1d3:cb97:2eb3(2407:c080:802:1744:5df4:f1d3:cb97:2eb3) from 2407:c080:802:221d:3be1:c05a:345c:4802 : 56 data bytes 64 bytes from 2407:c080:802:1744:5df4:f1d3:cb97:2eb3: icmp_seq=1 ttl=64 time=1.00 ms 64 bytes from 2407:c080:802:1744:5df4:f1d3:cb97:2eb3: icmp_seq=2 ttl=64 time=0.161 ms 64 bytes from 2407:c080:802:1744:5df4:f1d3:cb97:2eb3: icmp_seq=3 ttl=64 time=0.092 ms ^C --- 2407:c080:802:1744:5df4:f1d3:cb97:2eb3 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2032ms rtt min/avg/max/mdev = 0.092/0.417/1.000/0.412 ms
- Configure policy-based routes for both the primary and extended network interfaces.
- Configure permanent routes for the source ECS.
- Run the following command to create the network-routes6.service file for the systemd service:
vi /etc/systemd/system/network-routes6.service
- Press i to enter the editing mode.
- Add the following content to the end of the file:
[Unit] Description=Network Routes Configuration After=network.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/bash -c 'for((x=0; x<10; x++)); do [[ $(ip addr show eth0 | grep -w 2407:c080:802:221c:5e76:7761:8d54:4ebc >/dev/null 2>&1 && echo 1) ]] && break; sleep 1; done; ip route flush table 10; ip -6 route add default via 2407:c080:802:221c::1 dev eth0 table 10; ip -6 route add 2407:c080:802:221c::/64 dev eth0 table 10; ip -6 rule add from 2407:c080:802:221c:5e76:7761:8d54:4ebc table 10; for((x=0; x<10; x++)); do [[ $(ip addr show eth1 | grep -w 2407:c080:802:221d:3be1:c05a:345c:4802 >/dev/null 2>&1 && echo 1) ]] && break; sleep 1; done; ip route flush table 20; ip -6 route add default via 2407:c080:802:221d::1 dev eth1 table 20; ip -6 route add 2407:c080:802:221d::/64 dev eth1 table 20; ip -6 rule add from 2407:c080:802:221d:3be1:c05a:345c:4802 table 20' [Install] WantedBy=multi-user.target
The parameters are as follows:
- for loop: Check whether eth0 or eth1 has obtained an IPv6 address (eth0: 2407:c080:802:221c:5e76:7761:8d54:4ebc; eth1: 2407:c080:802:221d:3be1:c05a:345c:4802) every second up to 10 times.
- ip route flush table route-table-name: Running this command will delete existing routes from the specified route table. This prevents new routes from being affected.
- Policy-based routes of the primary network interface: Set it to the same value as that in 5.a.
- Policy-based routes of the extended network interface: Set it to the same value as that in 5.a.
- Press ESC to exit and enter :wq! to save the configuration.
- Run the following commands to reload the systemd configuration and start the service:
systemctl enable network-routes6.service
If information similar to the following is displayed, the service is started:[root@ecs-s ~]# systemctl daemon-reload [root@ecs-s ~]# systemctl enable network-routes6.service Created symlink /etc/systemd/system/multi-user.target.wants/network-routes6.service → /etc/systemd/system/network-routes6.service.
- Run the following command to restart the source ECS:
Policy-based routes added to the network-routes6.service file only work after the source ECS is restarted. Ensure that workloads on the ECS will not be affected before restarting the ECS.
- Repeat 5.b to 5.c to check whether the policy-based routes are added and whether the source ECS and the destination ECS can communicate with each other.
- Run the following command to create the network-routes6.service file for the systemd service:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot