Bind an Elastic IPv4 Address
Last updated
You can bind up to 4 elastic IPv4 addresses to a private IPv4.
Click the instance name to go to instance Details > Information > Network interface.
Select the private IPv4 you want to bind elastic IPv4 and go to Actions > Bind Elastic IPv4.

Select a desired elastic IPv4 and click Confirm to bind. If no desired elastic IPv4, click New Elastic IPv4 to create a new IPv4. See Create an Elastic IPv4 for detailed steps.

Note
You can also go to Elastic IPv4 > Actions > Bind Private IPv4 to bind the elastic IPv4.

Single network interface (NIC) only
Supports multiple IPs (up to 254)
All IPs must be in Bypass mode
Ubuntu: 20.04 / 22.04 / 24.04
Debian: 10 / 11 / 12
CentOS: 7 / 9
Rocky Linux: 8.10 / 9.6
A reboot is required after running the script, otherwise the configuration will not take effect
Mixed modes are not supported (Bypass Mode + NAT Mode)
Create Command:
Path:
Console → Orchestration Service → Commands → Create Commands
copy and add the following script and create command.
Run Command:
Path:
Console → Elastic Compute → Elastic Compute Instance List → Actions → Operations → Run command → Select the command→ Confirm
Run the created command.
Reboot the Instance
After execution, you must manually reboot the instance.
Add Additional IPs (Optional)
To attach more IPs, repeat:
Bind IP
Run command
Reboot instance
Create Compute Instance
Create an instance following the standard process.
Create and Bind EIP
Create an Elastic IP
Bind it to the instance in Bypass mode
Run Command via API
Call the API to run the command:
API Documentation: https://docs.console.zenlayer.com/api-reference/security/zos/command/createcommand
Use the script provided following.
Reboot the Instance
Call the API to reboot the instance to apply the configuration.
Add Additional IPs (Optional)
To attach more IPs, repeat:
Bind IP
Run command
Reboot instance
Cause: Instance not rebooted
Solution: Reboot the instance
Ensure all IPs are in Bypass mode
Verify the OS is within the supported list
Last updated
#!/bin/sh -e
# Task Description:
# Used for initializing configuration in single NIC EIP full Bypass mode scenarios.
# Supports from 1 public IP up to 254 public IPs.
# Execute this task after external resource environment is ready.
# Adapted for ubuntu20.04, 22.04, 24.04, debian10, 11, 12, centos7, centos9, rocky9.6, rocky8.10 (10 systems)
# ===== Global Variable Definitions =====
TASK_NAME=single_nic_bypass_init
META_CURL="curl -sf"
META_URL="http://169.254.169.254/latest/meta-data/network/interfaces/macs"
NIC_NAME=eth0
PRI_GW4=
PRI_IP4=
PRI_PREFIX=
SYSTEM=
DEFAULT_PUB_EIP4=
ALL_PUB_EIP4s=
NAME_SERVER1=8.8.8.8
NAME_SERVER2=1.1.1.1
# =======================
CheckSupportedOS() {
if [ ! -f /etc/os-release ]; then
echo "Error: Unsupported system: /etc/os-release not found"
exit 1
fi
. /etc/os-release
if [ "$ID" = "ubuntu" ]; then
if [ "$VERSION_ID" = "20.04" ] || [ "$VERSION_ID" = "22.04" ] || [ "$VERSION_ID" = "24.04" ]; then
echo "Supported OS: Ubuntu $VERSION_ID"
SYSTEM=ubuntu
return 0
else
echo "Error: Unsupported Ubuntu version: $VERSION_ID"
exit 1
fi
elif [ "$ID" = "debian" ]; then
if [ "$VERSION_ID" = "11" ] || [ "$VERSION_ID" = "10" ] || [ "$VERSION_ID" = "12" ]; then
echo "Supported OS: Debian $VERSION_ID"
SYSTEM=debian
return 0
else
echo "Unsupported Debian version: $VERSION_ID"
exit 1
fi
elif [ "$ID" = "centos" ] || [ "$ID" = "rhel" ]; then
if [ "$VERSION_ID" = "7" ] && [ -f /etc/centos-release ]; then
echo "Supported OS: CentOS $VERSION_ID"
SYSTEM=centos
return 0
elif [ "$VERSION_ID" = "9" ] && [ -f /etc/centos-release ]; then
echo "Supported OS: CentOS $VERSION_ID"
SYSTEM=centos
return 0
else
echo "Unsupported CentOS/RHEL version: $VERSION_ID"
exit 1
fi
elif [ "$ID" = "rocky" ]; then
if [ "$VERSION_ID" = "9.6" ] || [ "$VERSION_ID" = "8.10" ]; then
echo "Supported OS: rocky $VERSION_ID"
SYSTEM=rocky
return 0
else
echo "Unsupported rocky version: $VERSION_ID"
exit 1
fi
else
echo "Unsupported OS: $ID $VERSION_ID"
exit 1
fi
}
ConfigUbuntuNetwork() {
cat > /etc/netplan/50-cloud-init.yaml << EOF
network:
version: 2
ethernets:
eth0:
addresses:
- ${PRI_IP4}/${PRI_PREFIX}
EOF
for EIP in $ALL_PUB_EIP4s; do
echo " - ${EIP}/32" >> /etc/netplan/50-cloud-init.yaml
done
cat >> /etc/netplan/50-cloud-init.yaml << EOF
nameservers:
addresses:
- ${NAME_SERVER1}
- ${NAME_SERVER2}
EOF
# Default route
cat >> /etc/netplan/50-cloud-init.yaml << EOF
routes:
- to: default
via: ${PRI_GW4}
from: ${DEFAULT_PUB_EIP4}
EOF
}
ConfigCentOSNetwork() {
rm -f /etc/sysconfig/network-scripts/ifcfg-eth0*
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=${PRI_IP4}
PREFIX=${PRI_PREFIX}
EOF
index=0
for EIP in $ALL_PUB_EIP4s; do
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0:$index
DEVICE=eth0:$index
BOOTPROTO=static
ONBOOT=yes
IPADDR=${EIP}
PREFIX=32
EOF
index=$((index+1))
done
# Default route
cat << EOF > /etc/sysconfig/network-scripts/route-eth0
default via ${PRI_GW4} dev eth0 src ${DEFAULT_PUB_EIP4}
EOF
# Disable DHCP on eth2
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
EOF
}
ConfigDebianNetwork() {
cat > /etc/network/interfaces.d/50-cloud-init << EOF
auto lo
iface lo inet loopback
dns-nameservers ${NAME_SERVER1} ${NAME_SERVER2}
auto eth0
iface eth0 inet static
address ${PRI_IP4}/${PRI_PREFIX}
auto eth0:0
iface eth0:0 inet static
address ${DEFAULT_PUB_EIP4}/32
up ip route add default via ${PRI_GW4} dev eth0 src ${DEFAULT_PUB_EIP4}
down ip route del default via ${PRI_GW4} dev eth0 src ${DEFAULT_PUB_EIP4}
EOF
index=1
for EIP in $ALL_PUB_EIP4s; do
if [ "$EIP" = "$DEFAULT_PUB_EIP4" ]; then
continue
fi
cat >> /etc/network/interfaces.d/50-cloud-init << EOF
auto eth0:$index
iface eth0:$index inet static
address ${EIP}/32
EOF
index=$((index+1))
done
}
FetchMetaData() {
pri_macs=$($META_CURL $META_URL/ | sed 's/\///g')
nic_count=$(echo "$pri_macs" | wc -w | tr -d ' ')
if [ "$nic_count" -ne 1 ]; then
echo "[ERR] Expected exactly one nic, got $nic_count: $pri_macs" >&2
exit 4
fi
PRI_IP4=$($META_CURL $META_URL/$pri_macs/primary-ip-address)
pri_subnet_cidr=$($META_CURL $META_URL/$pri_macs/subnet-cidr-block)
PRI_PREFIX=$(echo "$pri_subnet_cidr" | cut -d'/' -f2)
PRI_GW4=$($META_CURL $META_URL/$pri_macs/gateway)
DEFAULT_PUB_EIP4=$($META_CURL $META_URL/$pri_macs/public-ipv4)
ALL_PUB_EIP4s=$($META_CURL $META_URL/$pri_macs/public-ipv4s | sed 's/\[//;s/\]//;s/"//g;s/,/ /g')
if [ -z "$pri_macs" ] || [ -z "$PRI_IP4" ] || [ -z "$pri_subnet_cidr" ] || [ -z "$PRI_PREFIX" ] || [ -z "$PRI_GW4" ] || [ -z "$DEFAULT_PUB_EIP4" ] || [ -z "$ALL_PUB_EIP4s" ]; then
echo "[ERR] Missing metadata, check EC2 metadata service." >&2
exit 3
fi
echo " Private MacAddr: $pri_macs"
echo " Private IPv4: $PRI_IP4"
echo " Private Prefix: $PRI_PREFIX"
echo " Private GWv4: $PRI_GW4"
echo " ALl Public IPv4: $ALL_PUB_EIP4s"
echo " Default Public IPv4: $DEFAULT_PUB_EIP4"
}
ConfigNetwork() {
# Disable RPF (Reverse Path Filtering)
if ! grep -q "net.ipv4.conf.all.rp_filter=0" /etc/sysctl.conf; then
echo "net.ipv4.conf.all.rp_filter=0" | tee -a /etc/sysctl.conf > /dev/null
sysctl -p /etc/sysctl.conf
fi
# Disable cloud-init network configuration
echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
if [ "$SYSTEM" = "ubuntu" ]; then
ConfigUbuntuNetwork
elif [ "$SYSTEM" = "centos" ]; then
ConfigCentOSNetwork
elif [ "$SYSTEM" = "debian" ]; then
if [ "$VERSION_ID" = "11" ] || [ "$VERSION_ID" = "10" ]; then
ConfigDebianNetwork
elif [ "$VERSION_ID" = "12" ]; then
ConfigUbuntuNetwork
else
echo "Unsupported Debian version: $VERSION_ID"
exit 1
fi
elif [ "$SYSTEM" = "rocky" ]; then
ConfigCentOSNetwork
else
echo "Unsupported OS for network config: $SYSTEM"
exit 1
fi
}
echo "1. Check OS..."
CheckSupportedOS
echo
echo "2. FetchMetaData..."
FetchMetaData
echo
echo "3. Configuring networks..."
ConfigNetwork
echo
echo
echo "Done."
sync#!/bin/sh -e
# Task Description:
# Used for initializing configuration in single NIC EIP full Bypass mode scenarios.
# Supports from 1 public IP up to 254 public IPs.
# Execute this task after external resource environment is ready.
# Adapted for ubuntu20.04, 22.04, 24.04, debian10, 11, 12, centos7, centos9, rocky9.6, rocky8.10 (10 systems)
# ===== Global Variable Definitions =====
TASK_NAME=single_nic_bypass_init
META_CURL="curl -sf"
META_URL="http://169.254.169.254/latest/meta-data/network/interfaces/macs"
NIC_NAME=eth0
PRI_GW4=
PRI_IP4=
PRI_PREFIX=
SYSTEM=
DEFAULT_PUB_EIP4=
ALL_PUB_EIP4s=
NAME_SERVER1=8.8.8.8
NAME_SERVER2=1.1.1.1
# =======================
CheckSupportedOS() {
if [ ! -f /etc/os-release ]; then
echo "Error: Unsupported system: /etc/os-release not found"
exit 1
fi
. /etc/os-release
if [ "$ID" = "ubuntu" ]; then
if [ "$VERSION_ID" = "20.04" ] || [ "$VERSION_ID" = "22.04" ] || [ "$VERSION_ID" = "24.04" ]; then
echo "Supported OS: Ubuntu $VERSION_ID"
SYSTEM=ubuntu
return 0
else
echo "Error: Unsupported Ubuntu version: $VERSION_ID"
exit 1
fi
elif [ "$ID" = "debian" ]; then
if [ "$VERSION_ID" = "11" ] || [ "$VERSION_ID" = "10" ] || [ "$VERSION_ID" = "12" ]; then
echo "Supported OS: Debian $VERSION_ID"
SYSTEM=debian
return 0
else
echo "Unsupported Debian version: $VERSION_ID"
exit 1
fi
elif [ "$ID" = "centos" ] || [ "$ID" = "rhel" ]; then
if [ "$VERSION_ID" = "7" ] && [ -f /etc/centos-release ]; then
echo "Supported OS: CentOS $VERSION_ID"
SYSTEM=centos
return 0
elif [ "$VERSION_ID" = "9" ] && [ -f /etc/centos-release ]; then
echo "Supported OS: CentOS $VERSION_ID"
SYSTEM=centos
return 0
else
echo "Unsupported CentOS/RHEL version: $VERSION_ID"
exit 1
fi
elif [ "$ID" = "rocky" ]; then
if [ "$VERSION_ID" = "9.6" ] || [ "$VERSION_ID" = "8.10" ]; then
echo "Supported OS: rocky $VERSION_ID"
SYSTEM=rocky
return 0
else
echo "Unsupported rocky version: $VERSION_ID"
exit 1
fi
else
echo "Unsupported OS: $ID $VERSION_ID"
exit 1
fi
}
ConfigUbuntuNetwork() {
cat > /etc/netplan/50-cloud-init.yaml << EOF
network:
version: 2
ethernets:
eth0:
addresses:
- ${PRI_IP4}/${PRI_PREFIX}
EOF
for EIP in $ALL_PUB_EIP4s; do
echo " - ${EIP}/32" >> /etc/netplan/50-cloud-init.yaml
done
cat >> /etc/netplan/50-cloud-init.yaml << EOF
nameservers:
addresses:
- ${NAME_SERVER1}
- ${NAME_SERVER2}
EOF
# Default route
cat >> /etc/netplan/50-cloud-init.yaml << EOF
routes:
- to: default
via: ${PRI_GW4}
from: ${DEFAULT_PUB_EIP4}
EOF
}
ConfigCentOSNetwork() {
rm -f /etc/sysconfig/network-scripts/ifcfg-eth0*
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=${PRI_IP4}
PREFIX=${PRI_PREFIX}
EOF
index=0
for EIP in $ALL_PUB_EIP4s; do
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0:$index
DEVICE=eth0:$index
BOOTPROTO=static
ONBOOT=yes
IPADDR=${EIP}
PREFIX=32
EOF
index=$((index+1))
done
# Default route
cat << EOF > /etc/sysconfig/network-scripts/route-eth0
default via ${PRI_GW4} dev eth0 src ${DEFAULT_PUB_EIP4}
EOF
# Disable DHCP on eth2
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
EOF
}
ConfigDebianNetwork() {
cat > /etc/network/interfaces.d/50-cloud-init << EOF
auto lo
iface lo inet loopback
dns-nameservers ${NAME_SERVER1} ${NAME_SERVER2}
auto eth0
iface eth0 inet static
address ${PRI_IP4}/${PRI_PREFIX}
auto eth0:0
iface eth0:0 inet static
address ${DEFAULT_PUB_EIP4}/32
up ip route add default via ${PRI_GW4} dev eth0 src ${DEFAULT_PUB_EIP4}
down ip route del default via ${PRI_GW4} dev eth0 src ${DEFAULT_PUB_EIP4}
EOF
index=1
for EIP in $ALL_PUB_EIP4s; do
if [ "$EIP" = "$DEFAULT_PUB_EIP4" ]; then
continue
fi
cat >> /etc/network/interfaces.d/50-cloud-init << EOF
auto eth0:$index
iface eth0:$index inet static
address ${EIP}/32
EOF
index=$((index+1))
done
}
FetchMetaData() {
pri_macs=$($META_CURL $META_URL/ | sed 's/\///g')
nic_count=$(echo "$pri_macs" | wc -w | tr -d ' ')
if [ "$nic_count" -ne 1 ]; then
echo "[ERR] Expected exactly one nic, got $nic_count: $pri_macs" >&2
exit 4
fi
PRI_IP4=$($META_CURL $META_URL/$pri_macs/primary-ip-address)
pri_subnet_cidr=$($META_CURL $META_URL/$pri_macs/subnet-cidr-block)
PRI_PREFIX=$(echo "$pri_subnet_cidr" | cut -d'/' -f2)
PRI_GW4=$($META_CURL $META_URL/$pri_macs/gateway)
DEFAULT_PUB_EIP4=$($META_CURL $META_URL/$pri_macs/public-ipv4)
ALL_PUB_EIP4s=$($META_CURL $META_URL/$pri_macs/public-ipv4s | sed 's/\[//;s/\]//;s/"//g;s/,/ /g')
if [ -z "$pri_macs" ] || [ -z "$PRI_IP4" ] || [ -z "$pri_subnet_cidr" ] || [ -z "$PRI_PREFIX" ] || [ -z "$PRI_GW4" ] || [ -z "$DEFAULT_PUB_EIP4" ] || [ -z "$ALL_PUB_EIP4s" ]; then
echo "[ERR] Missing metadata, check EC2 metadata service." >&2
exit 3
fi
echo " Private MacAddr: $pri_macs"
echo " Private IPv4: $PRI_IP4"
echo " Private Prefix: $PRI_PREFIX"
echo " Private GWv4: $PRI_GW4"
echo " ALl Public IPv4: $ALL_PUB_EIP4s"
echo " Default Public IPv4: $DEFAULT_PUB_EIP4"
}
ConfigNetwork() {
# Disable RPF (Reverse Path Filtering)
if ! grep -q "net.ipv4.conf.all.rp_filter=0" /etc/sysctl.conf; then
echo "net.ipv4.conf.all.rp_filter=0" | tee -a /etc/sysctl.conf > /dev/null
sysctl -p /etc/sysctl.conf
fi
# Disable cloud-init network configuration
echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
if [ "$SYSTEM" = "ubuntu" ]; then
ConfigUbuntuNetwork
elif [ "$SYSTEM" = "centos" ]; then
ConfigCentOSNetwork
elif [ "$SYSTEM" = "debian" ]; then
if [ "$VERSION_ID" = "11" ] || [ "$VERSION_ID" = "10" ]; then
ConfigDebianNetwork
elif [ "$VERSION_ID" = "12" ]; then
ConfigUbuntuNetwork
else
echo "Unsupported Debian version: $VERSION_ID"
exit 1
fi
elif [ "$SYSTEM" = "rocky" ]; then
ConfigCentOSNetwork
else
echo "Unsupported OS for network config: $SYSTEM"
exit 1
fi
}
echo "1. Check OS..."
CheckSupportedOS
echo
echo "2. FetchMetaData..."
FetchMetaData
echo
echo "3. Configuring networks..."
ConfigNetwork
echo
echo
echo "Done."
sync