GCP 上面創建Instance時,如果有多個network interface設定,需要額外創建routing rule
nic 0 / default / 10.140.0.2
nic 1 / interface-1 / 10.40.0.2
nic 2 / interface-2 / 10.60.0.2
創建好VM後,進入linux
sudo echo "100 rt1" | sudo tee -a /etc/iproute2/rt_tables
sudo echo "200 rt2" | sudo tee -a /etc/iproute2/rt_tables
vim /root/iproute.sh
#!/bin/bash
sleep 10
ip route add 10.40.0.1 src 10.40.0.2 dev eth1 table rt1
ip route add default via 10.40.0.1 dev eth1 table rt1
ip rule add from 10.40.0.2/32 table rt1
ip rule add to 10.40.0.2/32 table rt1
ip route add 10.60.0.1 src 10.60.0.2 dev eth2 table rt2
ip route add default via 10.60.0.1 dev eth2 table rt2
ip rule add from 10.60.0.2/32 table rt2
ip rule add to 10.60.0.2/32 table rt2- 注意一定要 sleep 10 (因為google 執行 startup-scritp的時候,有可能network interface還沒啟動)
在 Instance 加入 metadata :
metadata key : startup-script
metadata value :#!/bin/bash
/root/iproute.sh- 重新啟動 instance,應該就可以正常存取
- 可以去 /var/log/message 看啟動資訊,關鍵字 GCEMetadataScripts