ESXi で esxcli から IP アドレス設定していた時にあった話。
通常だと DCUI でやっちゃうのがほとんどだと思うので稀なケースだと思いますが。
事象
ESXi の OS インストールが終わって初めて起動してきたような IP アドレスがまだ設定されていない状態のとき。
esxcli でたたくと↓の状態。
[root@localhost:~] esxcli network ip interface ipv4 get Name IPv4 Address IPv4 Netmask IPv4 Broadcast Address Type Gateway DHCP DNS ---- -------------- ------------ --------------- ------------ ------- -------- vmk0 169.254.242.29 255.255.0.0 169.254.255.255 DHCP 0.0.0.0 true
この状態で esxcli で IP を設定する。
叩き方を確認するので、一回 help。
[root@localhost:~] esxcli network ip interface ipv4 set --help Usage: esxcli network ip interface ipv4 set [cmd options] Description: set Configure IPv4 setting for a given VMkernel network interface. Cmd options: -g|--gateway=<str> The default gateway for this interface. The value must be a valid IPv4 address. Gateway would be reset if not provided -i|--interface-name=<str> The name of the VMkernel network interface to set IPv4 settings for. This name must be an interface listed in the interface list command. (required) -I|--ipv4=<str> The static IPv4 address for this interface. -N|--netmask=<str> The static IPv4 netmask for this interface. -P|--peer-dns=<bool> A boolean value to indicate if the system should use the DNS settings published via DHCPv4 for this interface. -t|--type=<str> IPv4 Address type : dhcp: Use DHCP to aquire IPv4 setting for this interface. none: Remove IPv4 settings form this interface. static: Set Static IPv4 information for this interface. Requires --ipv4 and --netmask options.
なるほど… gateway は -g 指定ね。
というわけで set する。
[root@localhost:~] esxcli network ip interface ipv4 set -i vmk0 -t static -I 192.168.0.100 -N 255.255.255.0 -g 192.168.0.1 [root@localhost:~]
エラー出ず、問題なさげ。
[root@localhost:~] esxcli network ip interface ipv4 get Name IPv4 Address IPv4 Netmask IPv4 Broadcast Address Type Gateway DHCP DNS ---- ------------ --------------- -------------- ------------ ----------- -------- vmk0 192.168.0.100 255.255.255.0 192.168.0.255 STATIC 192.168.0.1 false
これで 8.8.8.8
にping をなげてみる。
[root@localhost:~] ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8): 56 data bytes sendto() failed (Invalid argument)
あれ?
対象に到達しなかったというよりそもそも投げてない??
原因
一見 gateway 設定入っているように見えるが、実は入っていない。
route を表示してみると
[root@localhost:~] esxcli network ip route ipv4 list Network Netmask Gateway Interface Source ----------- --------------- ------- --------- ------ 192.168.0.0 255.255.255.0 0.0.0.0 vmk0 MANUAL
同一 Network しか入ってない…
対処
esxcli で route を明示的に足してやるとよい。
[root@localhost:~] esxcli network ip route ipv4 add -n 0.0.0.0/0 -g 192.168.0.1
これで route を見てみる。
[root@localhost:~] esxcli network ip route ipv4 list Network Netmask Gateway Interface Source ----------- --------------- ----------- --------- ------ default 0.0.0.0 192.168.0.1 vmk0 MANUAL 192.168.0.0 255.255.255.0 0.0.0.0 vmk0 MANUAL
ping も通るように。
こんなものだっけ?
VMware Docs 見ても特に書いてないんですよね… docs.vmware.com 何か過不足あったりするのかな…