2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VMware on SoftLayerのゲストOSにパブリックIPを付与

Last updated at Posted at 2016-05-06

VMware on SoftLayerに作ったゲストOSをインターネットと通信させたい場合の設定例です。

一言で言うと、仮想マシンにパブリック側のNICを付けて、ゲストOS上でそのNICにPublic Portable IPを付与し、ゲストOSのルーティング設定をすればOKです。

順を追って説明します。なお、インターネットに接続するにあたってのセキュリティ確保は、ユーザー責任となりますので、実際に行う際は考慮いただくようお願いします。

Portable IPをオーダー

ゲストOSに付与するIPは基本的にPortable IPが適しているので、Public側・Private側の両方をオーダーします。Private側は無料で、Public側は有料です。

vmpub04.jpg

仮想マシンにパブリック側のNICを付ける

仮想マシン作成時、デフォルトではNICはPrivateに1つだけ持った状態です。

vmpub01.jpg

NICを2つにし、Public側にも接続するように変更します。

vmpub02.jpg

ゲストOSインストール直後の状態

ubuntuを例にします。
ubuntuのインストール中に、どちらか1つのNICを使ってインストールを進めるよう選ぶ必要があるため、eth0(プライベート側)を選択します。
そのため、インストール直後は、eth0にプライベートのIPアドレスが付き、eth1にはIPは設定されていない状態になっています。プライベートのIPは、購入しておいた、Private PortableのIPアドレスです。

$ ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0c:29:36:77:a8
          inet addr:10.110.227.118  Bcast:10.110.227.119  Mask:255.255.255.252
          inet6 addr: fe80::20c:29ff:fe36:77a8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:44 errors:0 dropped:0 overruns:0 frame:0
          TX packets:72 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5759 (5.7 KB)  TX bytes:10212 (10.2 KB)

eth1      Link encap:Ethernet  HWaddr 00:0c:29:36:77:b2
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

$

デフォルトゲートウェイもプライベート側にセットされています。
外部との疎通状況としては、SoftLayerのプライベートネットワーク上のサーバーとの通信は可能ですが、インターネットには繋がっていない状態です。

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.110.227.117  0.0.0.0         UG    0      0        0 eth0
10.110.227.116  0.0.0.0         255.255.255.252 U     0      0        0 eth0
$

ゲストOS上でPublic Portable IPを付与

/etc/network/interfacesにeth1に関する設定を追記します。IPアドレスは、購入しておいたPublic Portableのものを使います。
デフォルトゲートウェイもPublic側に設定します。

root@ubuntu01:~# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        address 10.110.227.118
        netmask 255.255.255.252
        network 10.110.227.116
        broadcast 10.110.227.119
#       gateway 10.110.227.117
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 10.0.80.11
        dns-search softlayer.com

# The secondary network interface
    auto eth1
    iface eth1 inet static
    address 119.81.151.190
    netmask 255.255.255.252
    gateway 119.81.151.189
root@ubuntu01:~#

vSphere Clientのコンソールから(SSH接続だと、ifdownのタイミングで接続が切れるため)、下記コマンドを実行し、上記設定を反映します。

# ifdown eth0 && ifup eth0
# ifdown eth1 && ifup eth1

パブリック側のIPと通信できるようになります。(逆に、後述の静的経路を設定するまで、プライベート側からは繋がらなくなります)

ローカルPCからのping
C:\Users\User01>ping 119.81.151.190

119.81.151.190 に ping を送信しています 32 バイトのデータ:
119.81.151.190 からの応答: バイト数 =32 時間 =64ms TTL=47
119.81.151.190 からの応答: バイト数 =32 時間 =61ms TTL=47
119.81.151.190 からの応答: バイト数 =32 時間 =61ms TTL=47
119.81.151.190 からの応答: バイト数 =32 時間 =59ms TTL=47

119.81.151.190 の ping 統計:
    パケット数: 送信 = 4、受信 = 4、損失 = 0 (0% の損失)、
ラウンド トリップの概算時間 (ミリ秒):
    最小 = 59ms、最大 = 64ms、平均 = 61ms

C:\Users\User01>

ルーティング設定

今、ゲストOSのルーティング設定は下記となっています。

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         119.81.151.189  0.0.0.0         UG    0      0        0 eth1
10.110.227.116  0.0.0.0         255.255.255.252 U     0      0        0 eth0
119.81.151.188  0.0.0.0         255.255.255.252 U     0      0        0 eth1
#

この状態では、SoftLayerのプライベート側に行ってほしい10.x.x.xもパブリック側に行ってしまうので、静的経路を追加し、10.0.0.0/8はプライベート側のゲートウェイに行くように設定します。

# route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.110.227.117

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         119.81.151.189  0.0.0.0         UG    0      0        0 eth1
10.0.0.0        10.110.227.117  255.0.0.0       UG    0      0        0 eth0
10.110.227.116  0.0.0.0         255.255.255.252 U     0      0        0 eth0
119.81.151.188  0.0.0.0         255.255.255.252 U     0      0        0 eth1
#

これで、パブリック側からもプライベート側からも通信できるようになりました。インターネットへも通信可能です。

# ping www.yahoo.co.jp
PING www.g.yahoo.co.jp (183.79.75.234) 56(84) bytes of data.
64 bytes from f7.top.vip.kks.yahoo.co.jp (183.79.75.234): icmp_seq=1 ttl=51 time=64.5 ms
64 bytes from f7.top.vip.kks.yahoo.co.jp (183.79.75.234): icmp_seq=2 ttl=51 time=102 ms
64 bytes from f7.top.vip.kks.yahoo.co.jp (183.79.75.234): icmp_seq=3 ttl=51 time=64.5 ms
64 bytes from f7.top.vip.kks.yahoo.co.jp (183.79.75.234): icmp_seq=4 ttl=51 time=64.6 ms
64 bytes from f7.top.vip.kks.yahoo.co.jp (183.79.75.234): icmp_seq=5 ttl=51 time=60.9 ms
^C
--- www.g.yahoo.co.jp ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 60.910/71.354/102.115/15.448 ms
root@ubuntu01:~#

vSphere Client上での表示

今回の構成は、vSphere ClientのvSphere標準スイッチ上は、下図のように表示されます。
仮想マシンvm01が、Privateネットワークであるvmnic0と、Publicネットワークであるvmnic1の両方に接続されていることが分かります。

vmpub05b.jpg

なお、ベアメタルオーダー時にSoftLayerから払い出されるPrimaryネットワークですが、Private側はVMkernelポートとして割り当てられ、vSphere ClientはこのIPに対して接続します。Primary Public IPも、SoftLayerの管理ポータル上は払い出されていますが、ユーザーが意識して使う機会は今のところなさそうです。

vmpub06.jpg

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?