1

In GCE, the DHCP server return the IP address with mask of 32 bits. Making the instance the only one in its subnet. It also return couple of static routes (RFC3442) that need to be configured. Example of the response looks like this

udhcpc:  interface=eth0                                                                           
udhcpc:  ip=10.240.0.2                                                                                
udhcpc:  siaddr=10.240.0.1                                                                   
udhcpc:  subnet=255.255.255.255                                     
udhcpc:  mask=32                                                                                
udhcpc:  router=10.240.0.1                                                                      
udhcpc:  staticroutes=10.240.0.1/32 0.0.0.0 0.0.0.0/0 10.240.0.1                                                       
udhcpc:  opt53=05                                                                

Using dhcpd, this works perfectly, the client get the routes and push them to the routing table. However, here I'm using udhcp and I need to add them myself. I tried adding them with the ip command but that doesn't seem to work.

ip addr add 10.240.0.2/32 dev eth0
ip route add 10.240.0.1 dev eth0 proto kernel scope link
ip route add 0.0.0.0/0 via 10.240.0.1

But that doesn't seem to work.

/ # ping 8.8.8.8 -c 10
PING 8.8.8.8 (8.8.8.8): 56 data bytes

--- 8.8.8.8 ping statistics ---
10 packets transmitted, 0 packets received, 100% packet loss

Am I missing something when adding those routes?

Sunny J
  • 607
  • 3
  • 14
Chaker
  • 111
  • 3

2 Answers2

1

udhcpc doesn't request classless static routes by default, you need to instruct it to do so by adding -O 121 or -O staticroutes to the command line. Alternatively DHCP server can be configured to forcibly send the option.

The routes should then be configured by the udhcpc hook script. You can see Gentoo's netifrc udhcpc-hook.sh for an implementation that does this.

A. Z.
  • 96
  • 4
-1

I see that this post was created two years and a half ago, could you clarify that you still have the issue?

In the meanwhile, first concept we need to have in mind is that DHCP on GCP cannot be modified. Also, modifying NIC settings inside the Instance can cause some disruptions like that one.

I'd recommend you for that specific issue check the routing part on GCP. Normally you have a default Internet gateway and a default route to the Internet that it might get confused or wrong with the new IP subnet and configuration.

Joan Marin
  • 31
  • 2