这种情况通常是由于安全组配置造成的。您需要检查两个ENI在同一安全组中是否有相同的规则。如果规则不同,则可能会导致一条ENI接受,另一条ENI被拒绝。此外,您应该检查网络访问控制列表(Network ACLs)和子网级别的防火墙设置。
以下是一个Python脚本示例,可以用于检查两个ENI是否在同一个安全组中并且具有相同的安全组规则:
import boto3
client = boto3.client('ec2', region_name="us-west-2")
eni_reservations = client.describe_instances()['Reservations']
eni_list = []
for r in eni_reservations:
for i in r['Instances']:
for n in i['NetworkInterfaces']:
eni_list.append(n['NetworkInterfaceId'])
if len(eni_list) != 2:
print("Error: There must be exactly two ENIs")
exit(1)
eni1 = eni_list[0]
eni2 = eni_list[1]
eni1_sg_list = client.describe_network_interfaces(NetworkInterfaceIds=[eni1])['NetworkInterfaces'][0]['Groups']
eni2_sg_list = client.describe_network_interfaces(NetworkInterfaceIds=[eni2])['NetworkInterfaces'][0]['Groups']
if set(eni1_sg_list) != set(eni2_sg_list):
print("ENIs are not in the same security group")
exit(1)
for sg in eni1_sg_list:
eni1_sg_rules = client.describe_security_groups(GroupIds=[sg['GroupId']])['SecurityGroups'][0]['IpPermissions']
eni2_sg_rules = client.describe_security_groups(GroupIds=[sg['GroupId']])['SecurityGroups'][0]['IpPermissions']
if set(eni1_sg_rules) != set(eni2_sg_rules):
print("ENIs have different security group rules")
exit(1)
print("ENIs are in the same security group and have