Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How IP-Aliases does work on Google Cloud Computing Instance?

When setup a IP-Alias via gloud command or the interface, it works out of the box. But in the machine itself, i do not see any configuration, ip addr-entries, no firewall rules, no routes that would allow to be the machine pingable - but it's pingable (local and remote)! (for example 10.31.150.70, when you setup a 10.31.150.64/26-subnet, and you primary IP is 10.31.150.1)

On the other hand, the primary IP of the machine is a /32-Netmask. For example: 10.31.150.1/32, Gateway: 10.31.0.1/16. So, how can the machine reach the gateway, 10.31.0.1, when the gateway is out of the range?

When removing the Main-IP via ip addr del, the aliases aren't pingable anymore.

like image 515
Arakis Avatar asked Jun 18 '18 23:06

Arakis


2 Answers

Google runs a networking daemon on your instance. It runs as the google-network-daemon service. This code is open source and viewable at this repo. This repo has a Python module called google_compute_engine which manages IP aliasing among other things. You can browse their code to understand how Google implements this (they use either ip route or ifconfig depending on the platform)

To see the alias route added by Google on a Debian box (where they use ip route underneath for aliasing) run the following command.

ip route ls table local type local dev eth0 scope host proto 66

If you know your Linux commands, you can remove appropriate routes after stopping the daemon, and then assign the alias IP address to your primary interface as the second IP address to see the ifconfig approach in action as well.

like image 160
zapstar Avatar answered Sep 28 '22 06:09

zapstar


When alias IP ranges are configured, GCP automatically installs VPC network routes for primary and alias IP ranges for the subnet of the primary network interface. Alias IP ranges are routable within the GCP virtual network without requiring additional routes. That is the reason why there is no configuration on the VM itself but still it's pingable. You do not have to add a route for every IP alias and you do not have to take route quotas into account.

More information regarding Alias IP on Google Cloud Platform (GCP) can be found in this help center article.

Be aware that Compute Engine networks only support IPv4 unicast traffic and it will show the netmask as /32 on the VM. However, it will still be able to reach the Gateway of the subnet that it belongs to. For example, 10.31.0.0/16 includes hosts ranging from 10.31.0.1 to 10.31.255.254 and the host 10.31.150.1 is within that range.

To further clarify why VM instances are assigned with the /32 mask, it is important to note that /32 is an artificial construct. The instance talks to the software defined network, which creates and manages the "real" subnets. So, it is really a link between the single address and the gateway for the subnet. As long as the link layer is there, communications are established and everything works.

In addition to that, network masks are enforced at the network layer. This helps avoid generation of unnecessary broadcast traffic (which underlying network wouldn't distribute anyway).

Note that removing the primary IP will break the reachability to the metadata server and therefore the IP aliases won't be accessible.

like image 21
Ishtiaque Avatar answered Sep 28 '22 06:09

Ishtiaque