How to connect two instances Google Cloud Platform with ip private via VPC Peering

In order this environment, we need create two instances and running as well.

Configuring

Instance 1 - VPC

  1. Create VPC Network, in example with name: dhroot , subnet: 10.10.10.0/24 , private google: on
  2. Create VPC Network Peering, in example with name of peering: ungaran-peering, current name vpc: dhroot (VPC Network created before), other Peered VPC network: default (example), other Peered project ID: dd1177 (example).
  3. click create

Instance 1 - Compute

  1. configure nic0 with internal ip: 10.10.10.4 and subnet network: dhroot.
  2. save, done. reboot or restart to make sure use new subnet.

Instance 2 - VPC

  1. Dont Create VPC Network, because we use existing network. But if you want to create, you must define the current name VPC into step 2.
  2. Create VPC Network Peering, in example with name of peering: ungaran-peering, current name vpc: default (existing VPC Network), other Peered VPC network: dhroot, other Peered project ID: dd1188 (example).
  3. click create

Instance 2 - Compute

nothing to do.

Testing

After we create VPC Network Peering, check connection. it should be like this:

from instance 1:

eth

user@dct:~$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000
link/ether 42:01:0a:0a:0a:04 brd ff:ff:ff:ff:ff:ff
inet 10.10.10.4/32 brd 10.10.10.4 scope global eth0
   valid_lft forever preferred_lft forever
inet6 fe80::4001:aff:fe0a:a04/64 scope link 
   valid_lft forever preferred_lft forever

trying ping

user@dct:~$ ping 10.148.0.4
PING 10.148.0.4 (10.148.0.4) 56(84) bytes of data.
64 bytes from 10.148.0.4: icmp_seq=1 ttl=64 time=0.872 ms
64 bytes from 10.148.0.4: icmp_seq=2 ttl=64 time=0.213 ms
64 bytes from 10.148.0.4: icmp_seq=3 ttl=64 time=0.245 ms
^C
--- 10.148.0.4 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2040ms
rtt min/avg/max/mdev = 0.213/0.443/0.872/0.303 ms

from instance 2:

eth:

[root@serv3 ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc mq state UP group default qlen 1000
    link/ether 42:01:0a:94:00:04 brd ff:ff:ff:ff:ff:ff
    inet 10.148.0.4/32 brd 10.148.0.4 scope global dynamic eth0
       valid_lft 59636sec preferred_lft 59636sec
    inet6 fe80::4001:aff:fe94:4/64 scope link 
       valid_lft forever preferred_lft forever
[root@serv3 ~]#

ping:

[root@serv3 ~]# ping 10.10.10.4
PING 10.10.10.4 (10.10.10.4) 56(84) bytes of data.
64 bytes from 10.10.10.4: icmp_seq=1 ttl=64 time=1.02 ms
64 bytes from 10.10.10.4: icmp_seq=2 ttl=64 time=0.185 ms
64 bytes from 10.10.10.4: icmp_seq=3 ttl=64 time=0.305 ms
64 bytes from 10.10.10.4: icmp_seq=4 ttl=64 time=0.202 ms

done.