-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure multi-nics on Amazon Linux 2023
This configuration only happens when the instance has more than one network interfaces attached. This configuration guarantees two things: 1. Traffic from each network interface looks up its own route table to ensure the responding traffic go through the same network interface. 2. In the default route table, primary network interface has the best priority. Therefore, traffic initiated from the instance uses the interface. This is useful to guarantee Elastic IP access, because Elastic IP is attached to the primary interface using ParallelCluster logic. The configuration files are written in `/etc/systemd/network`, which overwrites configurations from ec2-net-utils in `/run/systemd/network`. This commit also add retries to a resource, which caused sporadic failures during testing this commit. Signed-off-by: Hanwen <[email protected]>
- Loading branch information
1 parent
d6340d2
commit 99281f8
Showing
4 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...arallelcluster-environment/files/amazon-2023/network_interfaces/configure_nw_interface.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
if | ||
[ -z "${DEVICE_NAME}" ] || # name of the device | ||
[ -z "${DEVICE_NUMBER}" ] || # number of the device | ||
[ -z "${DEVICE_IP_ADDRESS}" ] || # ip of the device | ||
[ -z "${MAC}" ] || # mac address of the device | ||
[ -z "${CIDR_BLOCK}" ] # CIDR block of the subnet | ||
then | ||
echo 'One or more environment variables missing' | ||
exit 1 | ||
fi | ||
echo "Configuring NIC, Device name: ${DEVICE_NAME}, Device number: ${DEVICE_NUMBER}" | ||
|
||
configuration_directory="/etc/systemd/network" | ||
file_name="70-${DEVICE_NAME}.network" | ||
sub_directory="${configuration_directory}/${file_name}.d" | ||
if [ ! -d "$sub_directory" ]; then | ||
mkdir -p "$sub_directory"; | ||
fi | ||
|
||
cd "$configuration_directory" | ||
|
||
ROUTE_TABLE=100${DEVICE_NUMBER} | ||
|
||
ln -s /usr/lib/systemd/network/80-ec2.network ${file_name} # Use default EC2 configuration. This include MTU, etc. | ||
|
||
/bin/cat <<EOF > ${sub_directory}/eni.conf | ||
# Configuration for ${DEVICE_NUMBER} generated by ParallelCluster | ||
# This is inspired by https://github.com/amazonlinux/amazon-ec2-net-utils/blob/v2.4.1/lib/lib.sh | ||
[Match] | ||
MACAddress=${MAC} | ||
[Network] | ||
DHCP=yes | ||
[DHCPv4] | ||
RouteMetric=$ROUTE_TABLE | ||
UseRoutes=true | ||
UseGateway=true | ||
[IPv6AcceptRA] | ||
RouteMetric=$ROUTE_TABLE | ||
UseGateway=true | ||
[Route] | ||
Table=$ROUTE_TABLE | ||
Gateway=_ipv6ra | ||
[Route] | ||
Gateway=_dhcp4 | ||
Table=$ROUTE_TABLE | ||
[Route] | ||
Table=$ROUTE_TABLE | ||
Destination=$CIDR_BLOCK | ||
[RoutingPolicyRule] | ||
From=${DEVICE_IP_ADDRESS} | ||
Priority=$ROUTE_TABLE | ||
Table=$ROUTE_TABLE | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters