Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey.
Amazon VPC にはないがログにはある IP アドレスを特定する方法を教えてください。
Amazon Virtual Private Cloud (Amazon VPC) にはないが、ログにはある IP アドレスを特定したいです。
解決策
注: AWS コマンドラインインターフェイス (AWS CLI) コマンドの実行中にエラーが発生した場合は、「AWS CLI で発生したエラーのトラブルシューティング」を参照してください。また、AWS CLI の最新バージョンを使用していることを確認してください。
CloudTrail のイベントを確認する
AWS CloudTrail のイベントを使用して IP アドレスを特定するには、次の手順を実行します。
AllocateAddress イベントを使用して Elastic IP アドレスが AWS アカウントに割り当てられているかどうかを確認するには、次の lookup-events コマンドを実行します。
aws cloudtrail lookup-events \--region example-region \ --lookup-attributes AttributeKey=EventName,AttributeValue=AllocateAddress \ --start-time example-yyyy-mm-dd \ --query 'Events[].Resources[?ResourceName == 'example-eip-address'].{ResourceType:ResourceType,IP:ResourceName}[]' --output table
注: example-eip-address を Elastic IP アドレスに、example-yyyy-mm-dd を開始日に、example-region を AWS リージョンに、それぞれお使いの環境に合わせて置き換えます。上記の CloudTrail コマンドでは、Amazon Elastic Compute Cloud (Amazon EC2) のパブリック IPv4 アドレスはリストに含まれません。
AssociateAddress イベントと AllocationID フィルターを使用して Elastic IP アドレスを使用するサービスを表示するには、次の lookup-events コマンドを実行します。
aws cloudtrail lookup-events \--region example-region \ --lookup-attributes AttributeKey=ResourceName,AttributeValue=example-allocation-id \ --start-time example-yyyy-mm-dd \
注: example-allocation-id を Elastic IP アドレス ID に、example-yyyy-mm-dd を開始日に、example-region をリージョンに、それぞれお使いの環境に合わせて置き換えます。上記のコマンドは、Elastic IP アドレス割り当ての全履歴を表示します。選択した日付に基づいて、最新の割り当てから最も古い割り当ての順に表示されます。
CreateNetworkInterface イベントを使用して Elastic Network Interface にプライベート IP アドレスが割り当てられているかどうかを確認するには、次の lookup-events コマンドを実行します。
aws cloudtrail lookup-events \--region example-region \ --lookup-attributes AttributeKey=EventName,AttributeValue=CreateNetworkInterface \ --start-time example-yyyy-mm-dd \ --query 'Events[].CloudTrailEvent' --output text | jq -r "select(.responseElements.networkInterface.privateIpAddressesSet.item[].privateIpAddress == \"example-private-ip-address\")"
注: example-private-ip-address をプライベート IP アドレスに、example-yyyy-mm-dd を開始日に、example-region をリージョンに、それぞれお使いの環境に合わせて置き換えます。上記のコマンドが一致するイベントを返さない場合、出力は得られません。
AttachNetworkInterface イベントを使用して、リソースが過去にネットワークインターフェイスを使用したことがあるかどうかを確認するには、次の lookup-events コマンドを実行します。
aws cloudtrail lookup-events \--region example-region \ --lookup-attributes AttributeKey=EventName,AttributeValue=AttachNetworkInterface \ --start-time example-yyyy-mm-dd \ --query 'Events[].CloudTrailEvent' --output text | jq -r "select(.requestParameters.networkInterfaceId == \"example-eni-id\")"
注: example-eni-id をネットワークインターフェイス ID に、example-yyyy-mm-dd を開始日に、example-region をリージョンに、それぞれお使いの環境に合わせて置き換えます。
CloudTrail がイベントを見つけることができるかどうかを確認するには、jq フィルターなしで次の lookup-events コマンドを実行します。
aws cloudtrail lookup-events \ --region example-region \ --lookup-attributes AttributeKey=EventName,AttributeValue=CreateNetworkInterface \ --start-time example-yyyy-mm-dd
注: example-yyyy-mm-dd を開始日に、example-region をリージョンに、それぞれお使いの環境に合わせて置き換えます。
RunInstances イベントを使用して、インスタンスの起動時にプライベート IP アドレスがインスタンスに関連付けられているかどうかを確認するには、次の lookup-events コマンドを実行します。
aws cloudtrail lookup-events \--region example-region \ --lookup-attributes AttributeKey=EventName,AttributeValue=RunInstances \ --start-time example-yyyy-mm-dd \ --query 'Events[].CloudTrailEvent' --output text | jq -r "select(.responseElements.instancesSet.items[].privateIpAddress == \"example-private-ip-address\") | [.responseElements.instancesSet.items[].networkInterfaceSet.items[]] "
注: example-private-ip-address をプライベート IP アドレスに、example-yyyy-mm-dd を開始日に、example-region をリージョンに、それぞれお使いの環境に合わせて置き換えます。
AssignPrivateIPAddresses イベントを使用して、プライベート IP アドレスがネットワークインターフェイスに関連付けられているかどうかを確認するには、次の lookup-events コマンドを実行します。
aws cloudtrail lookup-events \--region example-region \ --lookup-attributes AttributeKey=EventName,AttributeValue=AssignPrivateIpAddresses \ --start-time example-yyyy-mm-dd \ --query 'Events[].CloudTrailEvent' --output text | jq -r "select(.responseElements.assignedPrivateIpAddressesSet.assignedPrivateIpAddressSetType[].privateIpAddress == \"example-private-ip-address\" ) | {requestParameters,responseElements}"
注: example-private-ip-address をプライベート IP アドレスに、example-yyyy-mm-dd を開始日に、example-region をリージョンに、それぞれお使いの環境に合わせて置き換えます。
AssignIPv6Addresses イベントを使用して、指定したネットワークインターフェイスに IPv6 アドレスが割り当てられているかどうかを確認するには、次の lookup-events コマンドを実行します。
aws cloudtrail lookup-events \--region example-region \ --lookup-attributes AttributeKey=EventName,AttributeValue=AssignIpv6Addresses \ --start-time example-yyyy-mm-dd \ --query 'Events[].CloudTrailEvent' --output text | jq -r "select(.responseElements.AssignIpv6AddressesResponse.assignedIpv6Addresses.item == \"example-IPv6-address\") | [.responseElements.AssignIpv6AddressesResponse] "
注: example-IPv6-address を IPv6 アドレスに、example-yyyy-mm-dd を開始日に、example-region をリージョンに、それぞれお使いの環境に合わせて置き換えます。
CloudWatch Logs を使用してログデータを分析する
注: ログイベントを Amazon CloudWatch Logs に送信するには、証跡を設定します。詳細については、「Amazon CloudWatch Logs による CloudTrail ログファイルのモニタリング」を参照してください。
アカウントに割り当てられている IPv4 アドレスを確認する
過去の Elastic IP アドレスの割り当てと、パブリック IP アドレスを使用したサービスを表示するには、次のイベントを使用します。
fields eventTime as Time, userIdentity.accountId as AccountID, userIdentity.principalId as Principal, awsRegion as Region, eventName as Action, requestParameters.allocationId as AssociateAddress_AllocationID, requestParameters.instanceId as InstanceID, requestParameters.privateIpAddress as PrivateIP, responseElements.allocationId as AllocateAddress_AllocationID, responseElements.publicIp as EIP | filter eventName = "AllocateAddress" or eventName = "AssociateAddress" and # AssociateAddress does not indicate resources outside EC2 instances. ( EIP = "example-public-ip-addresses" or AssociateAddress_AllocationID = "example-allocation-id" ) | sort @timestamp desc
注: example-public-ip-addresses は IP アドレスに、example-allocation-id は割り当て ID に、それぞれお使いの環境に合わせて置き換えます。
以前に割り当てられたプライベート IP アドレスを特定するには、次のイベントを使用します。
CreateNetworkInterface イベント
parse @message '"privateIpAddressesSet":{"item":[{"privateIpAddress":"*"' as PrivateIP| fields eventTime as Time, userIdentity.accountId as AccountID, userIdentity.principalId as Principal, awsRegion as Region, eventName as Action, responseElements.networkInterface.networkInterfaceId as ENI | filter eventName = "CreateNetworkInterface" and ( PrivateIP = "example-private-ip-addresses" ) | sort @timestamp desc
注: example-private-ip-addresses は、お使いの IP アドレスに置き換えます。
RunInstances イベント
parse @message '{"privateIpAddress":"*"' as PrivateIP|fields eventTime as Time, userIdentity.accountId as AccountID, userIdentity.principalId as Principal, awsRegion as Region, eventName as Action | filter eventName = "RunInstances" and ( PrivateIP = "example-private-ip-addresses" ) | sort @timestamp desc
注: example-private-ip-addresses は、お使いの IP アドレスに置き換えます。
AssignPrivateIpAddress イベント
parse @message '"assignedPrivateIpAddressSetType":[{*}]' as PrivateIpAddress| fields eventTime as Time, userIdentity.accountId as AccountID, userIdentity.principalId as Principal, awsRegion as Region, eventName as Action | filter eventName = "AssignPrivateIpAddresses" and ( PrivateIpAddress like "example-private-ip-addresses" ) | sort @timestamp desc Note: Replace example-private-ip-addresses with your IP
注: example-private-ip-addresses は、お使いの IP アドレスに置き換えます。
ネットワークインターフェースを使用したリソースを表示する
fields eventTime as Time, userIdentity.accountId as AccountID, userIdentity.principalId as Principal, awsRegion as Region, eventName as Action, requestParameters.instanceId as InstanceID, requestParameters.networkInterfaceId as ENI | filter eventName = "AttachNetworkInterface" and ( ENI = "example-eni-id" ) | sort @timestamp desc
注: example-eni-id は、お使いのネットワークインターフェイス ID に置き換えます。
アカウントに割り当てられている IPv6 アドレスを確認する
以前に割り当てられたプライベート IP アドレスを特定するには、次のイベントを使用します。
AssignIpv6Addresses イベント
fields eventTime as Time, userIdentity.accountId as AccountID, userIdentity.principalId as Principal, awsRegion as Region, eventName as Action, responseElements.AssignIpv6AddressesResponse.assignedIpv6Addresses.item as IPv6 | filter eventName = "AssignIpv6Addresses" and ( IPv6 = "example-ipv6-addresses" ) | sort @timestamp desc
注: example-ipv6-addresses は、お使いの IP アドレスに置き換えます。
RunInstances イベント
fields eventTime as Time, userIdentity.accountId as AccountID, userIdentity.principalId as Principal, awsRegion as Region, eventName as Action, responseElements.AssignIpv6AddressesResponse.assignedIpv6Addresses.item as IPv6 | filter eventName = "RunInstances" and ( PrivateIP = "example-private-ip-addresses" ) | sort @timestamp desc
注: example-private-ip-addresses は、お使いの IP アドレスに置き換えます。
CreateNetworkInterface イベント
parse @message '"ipv6AddressesSet":{"items":[{"ipv6Address":"*"' as IPv6| fields eventTime as Time, userIdentity.accountId as AccountID, userIdentity.principalId as Principal, awsRegion as Region, eventName as Action, responseElements.instancesSet.items.0.instanceId as InstanceID | filter eventName = "CreateNetworkInterface" and ( IPv6 = "example-ipv6-addresses" ) | sort @timestamp desc
注: example-ipv6-addresses は、お使いの IP アドレスに置き換えます。
ネットワークインターフェースを使用したリソースを表示する
fields eventTime as Time, userIdentity.accountId as AccountID, userIdentity.principalId as Principal, awsRegion as Region, eventName as Action, requestParameters.instanceId as InstanceID, requestParameters.networkInterfaceId as ENI | filter eventName = "AttachNetworkInterface" and ( ENI = "example-eni-id" or ) | sort @timestamp desc
注: example-eni-id は、お使いのネットワークインターフェイス ID に置き換えます。
(オプション) パブリック IP アドレスの BGP プレフィックスと ASN が AWS IP アドレスであるかどうかを確認するには、次の whois コマンドを実行します。
whois -h whois.cymru.com " -v example-public-ip-address"
注: example-public-ip-address は、お使いのパブリック IP アドレスに置き換えます。
IP アドレス履歴を確認する
ip-ranges.json ファイル、Amazon VPC IP Address Manager (IPAM)、AWS CLI のいずれかを使用して、IP アドレス履歴から IP アドレスを探すことができます。
ip-ranges.json
次の手順を実行します。
- AWS サービスに属するすべてのパブリック IP アドレスのリストを表示するには、ip-ranges.json ファイルを確認する。
- リストをフィルタリングするには、次の変数を使用する。
"ip_prefix" "region" "service"
IPAM
IPAM を使用して、特定の IP アドレスを使用した VPC またはリソースを時間の経過にわたって追跡するには、次の手順を実行します。
- IPAM コンソールを開く。
- ナビゲーションペインで、[Search IP history] を選択する。
- IP アドレスを入力する。
- [Search] を選択する。
検索結果には次の項目が表示されます。
- IP アドレスに関連付けられている VPC またはネットワークインターフェイス
- IP アドレスが割り当てられた時間範囲
- 関連リソース
AWS CLI
AWS CLI を使用して IP アドレス情報を取得するには、次の get-ipam-address-history コマンドを実行します。
aws ec2 get-ipam-address-history \ --ipam-scope-id ipam-scope-###### \ --cidr 10.0.1.5 \ --region us-east-1
注: AWS Organizations を使用している場合は、IP アドレスの検索範囲を組織レベルに広げて、複数のメンバーアカウントを一元的に追跡できます。
IPAM 管理者アカウントを指定する
次の手順を実行します。
- 組織内で管理アカウントとして使用する AWS アカウントを選択する。
- アカウント ID を組織の IPAM 管理者にするには、管理アカウントで次の enable-aws-service-access コマンドを実行する。
aws organizations enable-aws-service-access \ --service-principal ipam.amazonaws.comaws ec2 enable-ipam-organization-admin-account \ --delegated-admin-account-id YOUR_ACCOUNT_ID
注: YOUR_ACCOUNT_ID は、お使いのアカウント ID に置き換えます。
管理者アカウントで IPAM を作成する
IPAM 管理者アカウントで次の手順を実行します。
-
IPAM を作成するには、次の create-ipam コマンドを実行する。
aws ec2 create-ipam \ --description "Org-wide IPAM" \ --operating-regions RegionName=us-east-1 RegionName=us-west-2注: us-east-1 と us-west-2 は、お使いのリージョンに置き換えます。
この IPAM では、複数のアカウントの CIDR 使用状況を収集して管理できます。
-
リソース検出を作成するには、次の create-ipam-resource-discovery コマンドを実行する。
aws ec2 create-ipam-resource-discovery \ --description "Org-wide Discovery" \ --operating-regions RegionName=us-east-1 \ --tag-specifications ResourceType=ipam-resource-discovery,Tags=[{Key=Org,Value=Enabled}]注: us-east-1 は、お使いのリージョンに置き換えます。
-
リソース検出を IPAM に関連付けるには、次の associate-ipam-resource-discovery コマンドを実行する。
aws ec2 associate-ipam-resource-discovery \ --ipam-id ipam-######## \ --ipam-resource-discovery-id ipam-res-disco-####
リソース検出を別のアカウントと共有することができます。
注: 組織内の各メンバーアカウントは、リソースデータを IPAM と共有する必要があります。同じ組織を使用しており、一元化された検出を設定している場合、リソースデータは自動的に共有されます。IPAM ダッシュボードを使用して、VPC や IP アドレスなどの検出されたリソースをモニタリングします。
重要:
- 組織内の任意のアカウントまたは VPC に割り当てたすべての IP アドレスは、IPAM の IP アドレス履歴に表示されます。
- IPAM コンソールまたは AWS CLI を使用して、IP アドレスの過去の使用状況をクエリできます。
- IPAM 履歴の IP アドレスが AWS からのもので、悪意のあるアクティビティがあった場合は、AWS リソースの不正行為を報告してください。
- 言語
- 日本語
