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?