How to Make two Ec2 instances connect each other in AWS.

We build Ec2 instances like linux instances in aws. Sometime we need to make two Ec2 instances connect each other so that they can exchange files etc. However by default this communication is not available.

We need to make some configuration changes to make two Ec2 instances connect each other. Here is quick way to do

Prerequisite:

We have got two linux ec2 instances as below:

Note down the IP and the security group ID details of two:

1

2

3

4

5

6

7

Instance ID:i-001bf8faf34df386f

PrivateIP172.31.23.137

Sec grp ID sg-0ce7d465

------

Instance ID:i-0b6a20837dd74ba2c

PrivateIP172.31.25.150

Sec grp ID sg-d0e7d4b9

Initially when we try to ping these servers from each end test was unsuccessful as below:

Test1:

1

2

3

4

5

[root@ip-172-31-23-137~]# ping 172.31.25.150

PING172.31.25.150(172.31.25.150)56(84)bytes of data.

^C

---172.31.25.150ping statistics---

2packets transmitted,0received,100%packet loss,time999ms

Test 2:

1

2

3

4

5

[root@ip-172-31-25-150~]# ping 172.31.23.137

PING172.31.23.137(172.31.23.137)56(84)bytes of data.

^C

---172.31.23.137ping statistics---

2packets transmitted,0received,100%packet loss,time999ms

Now to make two Ec2 instances connect with each other follow below steps:

Step1:Goto Security group option in left pane under NETWORK & SECURITY option as below:

Step2: In the right side select security group “sg-0ce7d465” which is our security group for first instance. Click on edit option as below:

Step3: In the next popup window click on “Add Rule” button as below:

Step 4: Now Select All ICMP-ipv4 under Type drop-down,for Source tab select custom and in the next box enter the security group id of the other server which is “sg-d0e7d4b9” click on save button.

After above configuration we can able to ping the server “172.31.23.137” from the server 172.31.25.150 as below:

1

2

3

4

5

6

7

8

9

10

11

[root@ip-172-31-25-150~]# ping 172.31.23.137

PING172.31.23.137(172.31.23.137)56(84)bytes of data.

64bytes from172.31.23.137:icmp_seq=1ttl=64time=0.632ms

64bytes from172.31.23.137:icmp_seq=2ttl=64time=0.698ms

64bytes from172.31.23.137:icmp_seq=3ttl=64time=0.646ms

64bytes from172.31.23.137:icmp_seq=4ttl=64time=0.638ms

^C

---172.31.23.137ping statistics---

4packets transmitted,4received,0%packet loss,time3000ms

rtt min/avg/max/mdev=0.632/0.653/0.698/0.036ms

[root@ip-172-31-25-150~]#

To make the communication open from other (server) end, follow the steps 1 to 3 for other security group “sg-d0e7d4b9” and in the step 4 enter below details and click save button.

After above configuration we can able to ping vice versa as below:

1

2

3

4

5

6

7

8

9

10

11

[root@ip-172-31-23-137~]# ping 172.31.25.150

PING172.31.25.150(172.31.25.150)56(84)bytes of data.

64bytes from172.31.25.150:icmp_seq=1ttl=64time=0.538ms

64bytes from172.31.25.150:icmp_seq=2ttl=64time=0.666ms

64bytes from172.31.25.150:icmp_seq=3ttl=64time=0.562ms

64bytes from172.31.25.150:icmp_seq=4ttl=64time=0.618ms

^C

---172.31.25.150ping statistics---

4packets transmitted,4received,0%packet loss,time3000ms

rtt min/avg/max/mdev=0.538/0.596/0.666/0.049ms

[root@ip-172-31-23-137~]#

So this how we can make two Ec2 instances connect each other. In case of other ports or service please select particular service such as ssh, http or even NFS make sure you open the source with custom mentioning the security group id of the other server.

If this post helped you by any means, then Please
Support Us! by making Payment Payment Link.
Subscribe For RSS Feed::Here.
Like my facebook page FaceBook PageFollow Us on Twitter::TwitterFollow Us on YouTube::YouTube