가상 머신에서 실행되는 Centos 7에서 기본 게이트웨이를 설정하는 방법 - ping google.com이 실패합니다.

가상 머신에서 실행되는 Centos 7에서 기본 게이트웨이를 설정하는 방법 - ping google.com이 실패합니다.

Oracle VM VirtualBox Manager에서 실행되는 Centos 7을 사용하고 있습니다. 내 Windows(호스트)가 Centos 7(게스트)을 핑할 수 있기를 원하므로 가상 머신의 네트워크 설정을 변경하여 가상 머신 IP는 핑할 수 있지만 가상 머신 IP는 핑할 수 없으므로 잘 작동하는 호스트 전용 네트워크 어댑터를 사용하도록 변경했습니다. 기기 기기가 네트워크에 연결되어 있지 않습니다. 기본 게이트웨이에 문제가 있는 것 같습니다. 기본 게이트웨이를 설정하는 방법은 무엇입니까? 기본 게이트웨이의 올바른 값은 무엇입니까? 이렇게 하면 가상 머신에서 사용 가능한 네트워크 연결을 갖게 됩니다.

기본 경로와 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

이는 예상된 동작입니다. 사용호스트 전용이름에서 알 수 있듯이 네트워킹은 호스트와 가상 머신 간 또는 동일한 호스트의 가상 머신 간 연결만 허용합니다. "...가상 머신은 물리적 네트워크 인터페이스에 연결되어 있지 않기 때문에 호스트 머신 외부와 통신할 수 없습니다."라고 매뉴얼에는 나와 있습니다.

호스트에서 게스트로 네트워크 연결을 설정하려는 경우그리고게스트에서 외부 세계로 연결되는 네트워크 어댑터가 필요할 수 있습니다.

관련 정보