LoginSignup
0
1

More than 5 years have passed since last update.

run-instances の --secondary-private-ip-addresses って何じゃろ?

Posted at

こんばんは

2回目の投稿、神谷です。どもども。
今回はモヤモヤっとした「よう判らん」な結果になってしまっております。教えて判る人!

セカンダリIPアドレスって何じゃー

というわけで、今日はrun-instancesの--secondary-private-ip-addressについて。
そもそもこれ何だ?セカンダリIPアドレスって何じゃい、NIC2枚刺すんちゃうんか。試す前はそう思ってました。

実践!実践!

早速コマンド打ってみた
aws ec2 run-instances --image-id ami-hogehoge --instance-type t2.micro --key-name keyname --private-ip-address 10.0.1.100 --secondary-private-ip-addresses 10.0.1.101 --security-group-ids sg-hogehoge --subnet-id subnet-hogehoge
これで作ったインスタンスにログインは出来たものの、セカンダリアドレスとして指定した10.0.1.101にはpingは通らない。何でやー。

仕方ないのでコンソールで

コンソールで作成。
IPアドレスを指定するところ、複数行指定出来た。知らなかった。
複数行指定。

どんなインスタンスが出来たか

NICは1枚。IPは2つ、プライマリとセカンダリ。おおっ、まんまや。
OS自体は、プライマリIPアドレスのみ認識。
セカンダリIP自体は、仮想マシンのOSとしては認識せず。しかし、pingすると、そのマシンが応答を返す。sshするとそのマシンへログイン出来る。
つまり仮想IPっぽく、他のサーバからプライマリIPアドレスへアクセス出来るという事。

describeの結果はこんな感じ

{
"Reservations": [
{
"Instances": [
{
(省略)
"SecurityGroups": [
{
"GroupName": "xxxxx",
"GroupId": "sg-xxxx"
}
(省略)
"NetworkInterfaces": [
{
"Status": "in-use",
"MacAddress": "xx:xx:xx:xx:xx:xx",
"SourceDestCheck": true,
"VpcId": "vpc-xxxxxxxx",
"Description": "Primary network interface",
"NetworkInterfaceId": "eni-xxxxx",
"PrivateIpAddresses": [
{
"Primary": true,
"PrivateIpAddress": "10.0.1.100"
},
{
"PrivateDnsName": "",
"Primary": false,
"PrivateIpAddress": "10.0.1.101"
}
],
"SubnetId": "subnet-xxxxxxxx",
"Attachment": {
"Status": "attached",
"DeviceIndex": 0,
"DeleteOnTermination": true,
"AttachmentId": "eni-attach-xxxxxxxx",
"AttachTime": "2017-10-23T13:57:44.000Z"
},
"Groups": [
{
"GroupName": "xxxxxx",
"GroupId": "sg-xxxxxx"
}
],
"Ipv6Addresses": [],
"OwnerId": "xxxx",
"PrivateIpAddress": "10.0.1.100"
}
],
"SourceDestCheck": true,
(以下略)

}

NIC1枚に、フツーにIPアドレスが2つ入ってる。
実際pingも通るしsshでログインも出来る。
ふむ。

何でコマンドで出来ないんやー

これやってる人、あんまり居ないので、ネットでも例があまり無い。ので、公式をジロジロ見たり、自分で打って試行錯誤するしかない。
Describeを見て気がついたのですが、primary IP Addressに2つモノが入ってるぞ。
コマンドを少し変えてみよう。

aws ec2 run-instances --image-id ami-xxxxx --instance-type t2.micro --key-name xxxxx --private-ip-address 10.0.1.102 10.0.1.103 --security-group-ids sg-xxxxx --subnet-id subnet-xxxxx

usage: aws [options] [ ...] [parameters]
To see help text, you can run:

aws help
aws help
aws help

Unknown options: 10.0.1.103

ふがっ、プライベートIPは1つしか指定出来ない!いやいや、コンソールからやったら2つ入ってるで!

aws ec2 run-instances --image-id ami-xxxxx --instance-type t2.micro --key-name xxxxx --private-ip-address 10.0.1.106 --secondary-private-ip-address-count 1 --secondary-private-ip-addresses 10.0.1.104 --security-group-ids sg-xxxxx --subnet-id subnet-xxxxx

これでやったら、何故か 10.0.1.106と10.0.1.25の2つのIPを持つインスタンスを作成する事に成功しました。10.0.1.104は見事に無視されましたん。んんん、--secondary-private-ip-addresses、効かないんちゃうかー!
で、色々試したら出来た。

aws ec2 run-instances --image-id ami-xxxxx --instance-type t2.large --key-name kamiya --network-interfaces PrivateIpAddresses="[{Primary=true,PrivateIpAddress=10.0.1.120},{Primary=false,PrivateIpAddress=10.0.1.121}]",DeviceIndex=0 --security-group-ids sg-xxxxx --subnet-id subnet-xxxxx

これで、コンソールでセカンダリIPアドレスを指定したときと同じ動作のインスタンスが作成出来たぜ!
……結局、--secondary-private-ip-addressesは「コマンドに指定されても完全に無視される」という事しかわからなかった。
何なんだこのオプション。

終わりに

僕よりもっと頭のいい人は、--secondary-private-ip-addressesのオプションの正しい使い道を知っているに違いない。ので、何方かのツッコミをお待ちしております。結局判らんかった……

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1