# VPC Network

## Network and Subnetworks

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FhCSMNIyR1x3fsoWLfKtz%2Fimage.png?alt=media\&token=a53458a5-8596-41ac-bd06-b319ab49c511)

* Default type is also the type of auto mode network
* All the subnet fits within 10.128.0.0/9 CIDR block
* When new Google Cloud regions become available, new subnets in those regions are automatically added to auto mode networks using the IP range from that block.
* Network range cannot be overlapped within the same network
* Custom mode cannot be changed to auto mode, but auto mode can be changed into custom mode
* the first and second addresses in the range, .0 and .1, are reserved for the network and the subnet's gateway respectively. This makes the first and second available addresses .2 and .3 which are assigned to the VM instances. Other reserved addresses in every subnet are the second-to-last address in the range and the last address which are reserved as the broadcast address. every subnet has four reserved IP addresses in its primary IP range
* Google Cloud VPCs that you increase the IP address space of any subnet without any workload shutdown or down time.

## Firewall

* If all firewall rules in a network are deleted, there is still an implied deny all ingress rule and an implied allow all egress rule for the network.
* Here is the explanation of the field on firewall set up

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FccWjX1oulyH7KmLPPghR%2Fimage.png?alt=media\&token=92aa6837-cd9b-4615-97e9-9f5e9bffcfd3)

* We can decide whether it is egress type or ingress, but also set up the condition that which port or protocol should be limited, whether the rule is blocking or allowing and the range of the vm within the network

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FS7UWoz61LANAqS9LVRIk%2Fimage.png?alt=media\&token=24501ef7-b50f-4c80-971e-d5d979a1ca20)

* Destination ranges  is to protect from undesired connections initiated by a VM instance towards an external host

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FnAc3PYY4ckhGuRfNNBoV%2Fimage.png?alt=media\&token=e8409247-262e-47b1-81bd-c3ee2bbedab0)

* Source CIDR ranges can be used to protect an instance from undesired connections coming either from external networks or from GCP IP ranges.
* Here is the default firewall rule when auto mode network is created

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2Frgn5XWy9azErBcAXFpst%2Fimage.png?alt=media\&token=46ca7909-a168-46e5-a457-923e0fca21b4)

## Cloud NAT

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FMMq1vOkH677I2vgKsJV6%2Fimage.png?alt=media\&token=869eb0e7-6564-44b5-ac4e-cbc6ca5d2235)

* Cloud NAT lets you provision your application instances without public IP addresses, while also allowing them to access the internet in a controlled and efficient manner.

## Shared VPC & VPC Peering

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FtXfwwv0GDg3MupJk8T8y%2Fimage.png?alt=media\&token=98dad286-ae45-4bc9-afbd-9e855dfcf2ff)

* Shared VPC connects projects within the same [organization](https://cloud.google.com/resource-manager/docs/creating-managing-organization). Linked projects can be in the same or different [folders](https://cloud.google.com/resource-manager/docs/creating-managing-folders), but if they are in different folders the admin must have [Shared VPC Admin](https://cloud.google.com/vpc/docs/shared-vpc#iam_in_shared_vpc) rights to both folders.
* When using shared VPC, you designate a project as a host project and attach one or more other service projects to it. Subnets of the Shared VPC networks in the host project are accessible by Service Project Admins
* In this case, the web application service project is the host project and the three other projects are the service projects.

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2F7DHqwDpBzq9UL8jOLacL%2Fimage.png?alt=media\&token=73fe9093-4c59-4ed9-80af-22be4f63c049)

* VPC network peering in contrast, allows private RFC 1918 connectivity across two VPC networks, regardless of whether they belong to the same project or the same organization.
* VPC network peering is a decentralized or distributed approach to multi project networking. each VPC network may remain under the control of separate administrator groups and maintains its own global firewall and routing tables.

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FbuTMOfBoRtzqQnKCsTtP%2Fimage.png?alt=media\&token=c300b4ee-7e20-4a5b-a991-6d33d72752c5)

## Cloud DNS

### What is DNS

* DNS system is a database that store information including ip address, so that it can be used to convert human-readable name into ip address

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FSZvTwkZFU8DDR1ffitLa%2Fimage.png?alt=media\&token=ac3d3c28-1e55-40a3-ab05-4252addefccf)

### DNS Records

#### NS

* The name server that containing domain information, such as ip

#### A

* The ip address that the domain name points to (ip v4 format)

#### CNAME

* The other domain name that points to other domain name
* Use case: share the same ip address to multiple different domain names

## Cloud VPN

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FHE3A24j1opIAk4vbXJ1H%2Fimage.png?alt=media\&token=161b6ebd-4bb8-4b73-85ef-3db9fab8f598)

* Cloud VPN securely connects your _peer network_ to your [Virtual Private Cloud (VPC) network](https://cloud.google.com/vpc/docs/vpc) through an [IPsec](https://wikipedia.org/wiki/IPsec) [VPN](https://wikipedia.org/wiki/Virtual_private_network) connection. Traffic traveling between the two networks is encrypted by one VPN gateway and then decrypted by the other VPN gateway.
* When using Cloud VPN is that the maximum transmission unit or MTU, for your on-premises VPN gateway cannot be greater than 1460 bytes.

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FoITJxaVrMtsJlpcHuZ34%2Fimage.png?alt=media\&token=f89d6d74-eaf3-4a37-9546-2fc571055e46)

* In order to use dynamic routes you need to configure Cloud Routers
* Cloud router can manage routes from a cloud VPN tunnel using Border Gateway Protocol or BGP to allows for routes to be updated and exchanged without changing the tunnel configuration.

## Load Balancer

* Here is the decision tree&#x20;

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2F9ZxrFDJAE2WKc7X8OcnC%2Fimage.png?alt=media\&token=e5cef663-29e9-4c20-8c1c-b24172568017)

![](https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FObI1T40H70kua7aLvU0j%2Fimage.png?alt=media\&token=cb505931-91c1-4ae6-bf63-38d400f3aab7)

* The frontend is where your application interacts with requests and forwards the traffic to the URL map.
* The next component is the URL map, which has path-based routine configuration to send traffic to one or more backend services. A URL map can match parts or hosts in the request to send traffic to different backend services.
* Cloud Run services can be a backend, as can other services on Google Cloud.



