Unable to Connect to Internet with NAT adaptor for CentOS 7.8 on Virtual box

Issues related to configuring your network
Post Reply
mayurkadam24
Posts: 3
Joined: 2020/08/09 20:32:13

Unable to Connect to Internet with NAT adaptor for CentOS 7.8 on Virtual box

Post by mayurkadam24 » 2020/08/09 21:03:55

I have a Windows 10 host machine (laptop) and I have guest CentOS 7.8 installed via Oracle VirtualBox 6.0. My aim is to have the following:

1) ssh from Windows host to CentOS VMs

2) Allow Internet access to Guest VMs

3) Allow VM to VM access (currently only 1 VM is there).

Adaptors configured are:
enp0s3 (Adapter 1) – for Host-only Adaptor,configured with a static IP address.
enp0s8 (Adapter 2) – NAT Adaptor,for Internet connection.


I'm able to ssh from host machine to Guest VM (Cent OS) but i'm not able to connect to the internet from Guest (Cent OS 7) VM.

Here's the output of id addr

Code: Select all

[root@localhost network-scripts]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:55:67:5d brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.10/24 brd 192.168.56.255 scope global enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe55:675d/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:de:b7:9c brd ff:ff:ff:ff:ff:ff
    inet 10.0.3.15/24 brd 10.0.3.255 scope global noprefixroute dynamic enp0s8
       valid_lft 83008sec preferred_lft 83008sec
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:b5:17:c1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:b5:17:c1 brd ff:ff:ff:ff:ff:ff
Interface configurations are as follows:

Code: Select all

[root@localhost network-scripts]# cat ifcfg-enp0s8
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=no
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s8
UUID=31a0e646-73b4-4c1a-bdd8-fbe65c48f2af
DEVICE=enp0s8
ONBOOT=yes
DNS1=1.0.0.1
DNS2=1.1.1.1
DNS3=8.8.4.4

Code: Select all

[root@localhost network-scripts]# cat ifcfg-enp0s3
TYPE=Ethernet
#PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPADDR=192.168.56.10
NETWORK=192.168.56.0
NETMASK=255.255.255.0
GATEWAY=192.168.56.1
DNS=8.8.8.8 192.168.56.1
#DNS2=8.8.4.4
NM_CONTROLLED=no
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=1f6cf57c-c97d-4cd0-ad4c-2121c082717a
DEVICE=enp0s3
ONBOOT=yes
[root@localhost network-scripts]#



Ping to google gives following error msg.

Code: Select all

[root@localhost network-scripts]# ping google.com
ping: google.com: Name or service not known

Already added modified the DNS entries to have DNS IP 8.8.8.8

Code: Select all

[root@localhost network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.43.1
nameserver 1.0.0.1
nameserver 1.1.1.1
# NOTE: the libc resolver may not support more than 3 nameservers.
# The nameservers listed below may not be recognized.
nameserver 8.8.4.4
nameserver 8.8.8.8

Trace route and ping to 8.8.8.8 gives N/W is not reachable.

Code: Select all

[root@localhost network-scripts]# ping 8.8.8.8
connect: Network is unreachable

Code: Select all

[root@localhost network-scripts]# traceroute 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
connect: Network is unreachable

Network Manager is running:

Code: Select all

[root@localhost network-scripts]# systemctl status NetworkManager.service
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-08-09 08:07:34 IST; 3h 37min ago
     Docs: man:NetworkManager(8)
 Main PID: 6002 (NetworkManager)
    Tasks: 4
   CGroup: /system.slice/NetworkManager.service
           ├─ 6002 /usr/sbin/NetworkManager --no-daemon
           └─12459 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-enp0s8.pid -lf /var/lib/NetworkManager/dhclient-31a0e646-73b4...

Route entries are as follows:

Code: Select all

[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.3.0        0.0.0.0         255.255.255.0   U     100    0        0 enp0s8
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 enp0s3
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@localhost network-scripts]#
dhclient -v output:

Code: Select all

[root@localhost network-scripts]# dhclient -v enp0s8
dhclient(6545) is already running - exiting

Why there is no internet connections to VMs via NAT adaptor enp0s8 and how do i establish internet connection to the CentOS VM ?

I reffered following article to have the setup i described above: https://www.tecmint.com/network-between ... irtualbox/

BShT
Posts: 278
Joined: 2019/10/09 12:31:40

Re: Unable to Connect to Internet with NAT adaptor for CentOS 7.8 on Virtual box

Post by BShT » 2020/08/10 12:11:18

if enp0s8 is your internet connection your route should run thru it

mayurkadam24
Posts: 3
Joined: 2020/08/09 20:32:13

Re: Unable to Connect to Internet with NAT adaptor for CentOS 7.8 on Virtual box

Post by mayurkadam24 » 2020/08/10 13:15:56

You mean i should add the route entry for NAT adaptor ?

From the route -n i see inet for enp0s8 included. Please correct me i'm missing something @BShT.

User avatar
TrevorH
Forum Moderator
Posts: 29493
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Unable to Connect to Internet with NAT adaptor for CentOS 7.8 on Virtual box

Post by TrevorH » 2020/08/10 14:20:52

You don't have a default route. That would be more easily seen if you ran ip route show rather than the deprecated `route` command.
CentOS 6 will die in November 2020 - migrate sooner rather than later!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

User avatar
jlehtone
Posts: 3044
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Unable to Connect to Internet with NAT adaptor for CentOS 7.8 on Virtual box

Post by jlehtone » 2020/08/10 14:28:49

Note: the "route" (and "ifconfig") are ancient tools. iproute2 package has tried to replace them for two decades now.

With iproute2:

Code: Select all

ip ro
ip ro get 8.8.8.8
the format seems more intuitive (to me, who never did learn to read "route -n") and closer to syntax that 'ip ro add' would use.
The latter command shows how packet to 8.8.8.8 will be routed -- through which interface it will leave.

You have NetworkManager in use. It has commands (to replace iproute2):

Code: Select all

nmcli
nmcli d s
nmcli c s
Presuming that the names of connections are 'enp0s8' and 'enp0s3'

Code: Select all

nmcli c s enp0s8
nmcli c s enp0s3
and if we are interested only in the IPv4 config of enp0s8:

Code: Select all

nmcli -f ipv4 c s enp0s8
Note 2: You have a VM. Are you going to create VM's on top of that VM? I bet not. The default install set has included virtualization packages and they define a virtual network (192.168.122.0/24). If you have no use for it, then I suggest that you disable the libvirtd service:

Code: Select all

sudo systemctl disable libvirtd.service
The effect will show after reboot; no more virbr0. Less is more.


Now, you seem to have ipv4.never-default true on enp0s8. The connection gets configuration from DHCP but ignores the offered default route (aka 'gateway').

The enp0s3 does have as gateway, but I don't see it in:

Code: Select all

10.0.3.0        0.0.0.0         255.255.255.0   U     100    0        0 enp0s8
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 enp0s3
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
As far as I can tell (being illiterate with route -n), the four routes

Code: Select all

10.0.3.0/24 dev enp0s8
169.254.0.0/16 dev enp0s3
192.168.56.0/24 dev enp0s3
129.168.122.0/24 dev virbr0
are all link-local. Traffic to those four subnets is simply tossed out from respective interfaces.

There is no default via a.b.c.d, "if destination is not link-local, then forward to a.b.c.d" route.

Questions to you:
1. If traffic out is not meant to be via router in 192.168.56.0/24, then why do you set a gateway there?
2. Why doesn't route that show?
3. Why default route via router in 10.0.3.0/24 is explicitly disabled?


Disclaimer: I know nothing of VirtualBox, so terms "Host-only Adaptor" and "NAT Adaptor" tell nothing, but the latter name gives me an eerie feeling.

BShT
Posts: 278
Joined: 2019/10/09 12:31:40

Re: Unable to Connect to Internet with NAT adaptor for CentOS 7.8 on Virtual box

Post by BShT » 2020/08/12 13:23:27

you set:

enp0s8 (Adapter 2) – NAT Adaptor,for Internet connection. DEFROUTE=no

enp0s3 (Adapter 1) – for Host-only Adaptor,configured with a static IP address. DEFROUTE=yes GATEWAY=192.168.56.1

how you are supposed to get internet thru a route that does not touch the internet?


just set:

enp0s8 (Adapter 2) – NAT Adaptor,for Internet connection. DEFROUTE=yes

enp0s3 (Adapter 1) – for Host-only Adaptor,configured with a static IP address. DEFROUTE=no and remove "GATEWAY=192.168.56.1"

mayurkadam24
Posts: 3
Joined: 2020/08/09 20:32:13

Re: Unable to Connect to Internet with NAT adaptor for CentOS 7.8 on Virtual box

Post by mayurkadam24 » 2020/08/16 19:58:36

@BShT: Thank you for the inputs. But even after the inputs from you its still the same.
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
#PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=no
IPADDR=192.168.56.10
NETWORK=192.168.56.0
NETMASK=255.255.255.0
#GATEWAY=192.168.56.1
DNS=8.8.8.8 192.168.56.1
#DNS2=8.8.4.4
NM_CONTROLLED=no
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=1f6cf57c-c97d-4cd0-ad4c-2121c082717a
DEVICE=enp0s3
ONBOOT=yes
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s8
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s8
UUID=31a0e646-73b4-4c1a-bdd8-fbe65c48f2af
DEVICE=enp0s8
ONBOOT=yes
DNS1=1.0.0.1
DNS2=1.1.1.1
DNS3=8.8.4.4
[root@localhost ~]#

VM is rebooted and below is the output:
[root@localhost ~]# ping google.com
ping: google.com: Name or service not known
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# traceroute 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
connect: Network is unreachable
[root@localhost ~]#
[root@localhost ~]# ip ro get 8.8.8.8
RTNETLINK answers: Network is unreachable
[root@localhost ~]#
No Default Gateway i see below:
[root@localhost ~]# ip r
10.0.3.0/24 dev enp0s8 proto kernel scope link src 10.0.3.15 metric 100
169.254.0.0/16 dev enp0s3 scope link metric 1002
192.168.56.0/24 dev enp0s3 proto kernel scope link src 192.168.56.10
even tried dhclient -v after it did not work as suggested by your steps, it seems to have added 192.168.43.1
[root@localhost ~]# cat /etc/resolv.conf
; generated by /usr/sbin/dhclient-script
nameserver 192.168.43.1
nameserver 8.8.8.8
nameserver 8.8.4.4

Post Reply

Return to “CentOS 7 - Networking Support”