#chiroito ’s blog

Java を中心とした趣味の技術について

VirtualBoxでホストオンリーアダプタをつかう

環境とかVMの情報とかはこちらを確認してください。

ホストからVMへ通信を行う場合に使います。
同一ホスト外との通信はおこなえません。

設定

まずは、VMがホストオンリーアダプタを使うようにVirtualBoxの設定をします。


次に、VMのOSの設定をします。
IPやネットマスクは動的に割り当てられます
HWADDRはVM毎に変えてください。VBoxの設定画面から確認できます。

/etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:78:81:5B
ONBOOT=yes
BOOTPROTO=dhcp

確認

ifdown eth0とifup eth0でNICを再起動させてから設定通りになっているか確認してみます。

■VM1
[root@localhost network-scripts]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 08:00:27:78:81:5B  
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe78:815b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:36102 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24022 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 

          RX bytes:43461763 (41.4 MiB)  TX bytes:1308325 (1.2 MiB)

[root@localhost network-scripts]# ping 192.168.56.1
PING 192.168.56.1 (192.168.56.1) 56(84) bytes of data.
64 bytes from 192.168.56.1: icmp_seq=1 ttl=128 time=1.40 ms
64 bytes from 192.168.56.1: icmp_seq=2 ttl=128 time=0.249 ms
^C
--- 192.168.56.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1355ms
rtt min/avg/max/mdev = 0.249/0.825/1.401/0.576 ms

[root@localhost network-scripts]# ping 192.168.56.101
PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
64 bytes from 192.168.56.101: icmp_seq=1 ttl=64 time=0.057 ms
64 bytes from 192.168.56.101: icmp_seq=2 ttl=64 time=0.047 ms
^C
--- 192.168.56.101 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1476ms
rtt min/avg/max/mdev = 0.047/0.052/0.057/0.005 ms

[root@localhost network-scripts]# ping 192.168.56.102
PING 192.168.56.102 (192.168.56.102) 56(84) bytes of data.
64 bytes from 192.168.56.102: icmp_seq=1 ttl=64 time=1.62 ms
64 bytes from 192.168.56.102: icmp_seq=2 ttl=64 time=0.338 ms
^C
--- 192.168.56.102 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1518ms
rtt min/avg/max/mdev = 0.338/0.982/1.626/0.644 ms

[root@localhost network-scripts]# ping 192.168.0.254
connect: ネットワークに届きません

■VM2
[root@localhost network-scripts]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 08:00:27:C3:E0:7E  
          inet addr:192.168.56.102  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fec3:e07e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:72 errors:0 dropped:0 overruns:0 frame:0
          TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:27652 (27.0 KiB)  TX bytes:7722 (7.5 KiB)

[root@localhost network-scripts]# ping 192.168.56.1
PING 192.168.56.1 (192.168.56.1) 56(84) bytes of data.
64 bytes from 192.168.56.1: icmp_seq=1 ttl=128 time=1.04 ms
64 bytes from 192.168.56.1: icmp_seq=2 ttl=128 time=0.332 ms
^C
--- 192.168.56.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1437ms
rtt min/avg/max/mdev = 0.332/0.688/1.045/0.357 ms

[root@localhost network-scripts]# ping 192.168.56.101
PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
64 bytes from 192.168.56.101: icmp_seq=1 ttl=64 time=0.339 ms
64 bytes from 192.168.56.101: icmp_seq=2 ttl=64 time=0.304 ms
^C
--- 192.168.56.101 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1494ms
rtt min/avg/max/mdev = 0.304/0.321/0.339/0.025 ms

[root@localhost network-scripts]# ping 192.168.56.102
PING 192.168.56.102 (192.168.56.102) 56(84) bytes of data.
64 bytes from 192.168.56.102: icmp_seq=1 ttl=64 time=0.050 ms
64 bytes from 192.168.56.102: icmp_seq=2 ttl=64 time=0.051 ms
^C
--- 192.168.56.102 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1446ms
rtt min/avg/max/mdev = 0.050/0.050/0.051/0.007 ms

[root@localhost network-scripts]# ping 192.168.0.254
connect: ネットワークに届きません
■ホスト
C:\Windows\System32>ping -n 1 192.168.56.101

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

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


C:\Windows\System32>ping -n 1 192.168.56.102

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

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