仮想マシンで実行されているCentos 7でデフォルトゲートウェイを設定する方法 - ping google.comが失敗する

仮想マシンで実行されているCentos 7でデフォルトゲートウェイを設定する方法 - ping google.comが失敗する

Oracle VM VirtualBox Managerで実行されているCentos 7を使用しています。私のWindows(ホスト)がCentos 7(ゲスト)をpingできるようにしたいので、仮想マシンのネットワーク設定を変更して仮想マシンIPをpingできますが、仮想マシンIPはpingできないので、うまく機能するホスト専用ネットワークアダプタを使用するようにします。変更しました。デバイス デバイスがネットワークに接続されていません。デフォルトゲートウェイに問題があるようです。デフォルトゲートウェイを設定するには?デフォルトゲートウェイの正しい値は何ですか?これにより、仮想マシンで利用可能なネットワーク接続が得られます。

デフォルトパスとDNSのないネットワークスクリーンショット

[root@hostname sysconfig]# ifconfig -a
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
        inet6 fe80::42:48ff:fe73:32ae  prefixlen 64  scopeid 0x20<link>
        ether 02:42:48:73:32:ae  txqueuelen 0  (Ethernet)
        RX packets 1086312  bytes 190220822 (181.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2244812  bytes 1153561488 (1.0 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.101  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::a00:27ff:fe57:e658  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:57:e6:58  txqueuelen 1000  (Ethernet)
        RX packets 1083  bytes 112900 (110.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 166  bytes 24915 (24.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 70229  bytes 8733878 (8.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 70229  bytes 8733878 (8.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth0022793: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::541a:3bff:fefe:40fc  prefixlen 64  scopeid 0x20<link>
        ether 56:1a:3b:fe:40:fc  txqueuelen 0  (Ethernet)
        RX packets 206  bytes 15300 (14.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5850  bytes 272760 (266.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth0333914: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 16:78:ed:04:52:5e  txqueuelen 0  (Ethernet)
        RX packets 68480  bytes 84562622 (80.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 90298  bytes 14502209 (13.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth06f16da: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::4aa:47ff:fe36:c394  prefixlen 64  scopeid 0x20<link>
        ether 06:aa:47:36:c3:94  txqueuelen 0  (Ethernet)
        RX packets 51  bytes 4678 (4.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5823  bytes 267358 (261.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth16e581d: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::2cb7:66ff:fe1a:a627  prefixlen 64  scopeid 0x20<link>
        ether 2e:b7:66:1a:a6:27  txqueuelen 0  (Ethernet)
        RX packets 8  bytes 648 (648.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5769  bytes 262582 (256.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth1ecf198: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::2022:c4ff:fe1c:9ab5  prefixlen 64  scopeid 0x20<link>
        ether 22:22:c4:1c:9a:b5  txqueuelen 0  (Ethernet)
        RX packets 8  bytes 648 (648.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5773  bytes 262882 (256.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth8536f91: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::ac21:2fff:fe0e:87e6  prefixlen 64  scopeid 0x20<link>
        ether ae:21:2f:0e:87:e6  txqueuelen 0  (Ethernet)
        RX packets 841994  bytes 71927871 (68.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1841996  bytes 992110236 (946.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethda88d72: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::f44c:52ff:fe6c:b856  prefixlen 64  scopeid 0x20<link>
        ether f6:4c:52:6c:b8:56  txqueuelen 0  (Ethernet)
        RX packets 8  bytes 648 (648.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5759  bytes 261746 (255.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:ce:19:b8  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0-nic: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 52:54:00:ce:19:b8  txqueuelen 500  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


[root@hostname network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3 
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s3
UUID=dc80dadc-3072-428f-888f-25dc8dcd8ca9
DEVICE=enp0s3
ONBOOT=no
[root@hostname network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-lo
DEVICE=lo
IPADDR=127.0.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0

[root@hostname network-scripts]# cat /etc/resolv.conf 
# Generated by NetworkManager


# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:
#
# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com


[root@hostname sysconfig]# ip route show
172.17.0.0/16 dev docker0  proto kernel  scope link  src 172.17.0.1 
192.168.56.0/24 dev enp0s3  proto kernel  scope link  src 192.168.56.101  metric 100 
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1 
[root@hostname sysconfig]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.56.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
[root@hostname sysconfig]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.56.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
[root@hostname sysconfig]# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.101  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::a00:27ff:fe57:e658  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:57:e6:58  txqueuelen 1000  (Ethernet)
        RX packets 1070  bytes 110928 (108.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 164  bytes 24513 (23.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@hostname sysconfig]# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.17.0.0      0.0.0.0         255.255.0.0     U         0 0          0 docker0
192.168.56.0    0.0.0.0         255.255.255.0   U         0 0          0 enp0s3
192.168.122.0   0.0.0.0         255.255.255.0   U         0 0          0 virbr0

[root@hostname sysconfig]# ip route list
172.17.0.0/16 dev docker0  proto kernel  scope link  src 172.17.0.1 
192.168.56.0/24 dev enp0s3  proto kernel  scope link  src 192.168.56.101  metric 100 
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1 

[root@hostname sysconfig]# ping google.com
ping: unknown host google.com
[root@hostname sysconfig]# nslookup google.com
;; connection timed out; trying next origin
;; connection timed out; no servers could be reached

ベストアンサー1

これは予想される動作です。使用ホストのみ名前が示すように、ネットワーキングはホストと仮想マシン間または同じホストからの仮想マシン間の接続のみを許可します。 「...仮想マシンは物理ネットワークインターフェイスに接続されていないため、ホストマシンの外部と通信できません」とマニュアルに記載されています。

ホストからゲストへのネットワーク接続を確立する場合そしてゲストから外部世界に接続するネットワークアダプタが必要な場合があります。

おすすめ記事