22

I'm using centos7 in virtualbox on windows. And vagrant made it, got ping error with http or https. also curl. someone can help me how to fix it and let it work.

[root@localhost ~]# ping google.com
PING google.com (61.91.161.217) 56(84) bytes of data.
64 bytes from chatenabled.mail.google.com (61.91.161.217): icmp_seq=1 ttl=43 time=404 ms
64 bytes from chatenabled.mail.google.com (61.91.161.217): icmp_seq=2 ttl=43 time=408 ms
64 bytes from chatenabled.mail.google.com (61.91.161.217): icmp_seq=3 ttl=43 time=407 ms
64 bytes from chatenabled.mail.google.com (61.91.161.217): icmp_seq=4 ttl=43 time=408 ms
^C
--- google.com ping statistics ---
5 packets transmitted, 4 received, 20% packet loss, time 4000ms
rtt min/avg/max/mdev = 404.297/407.234/408.956/1.887 ms
[root@localhost ~]# ping https://google.com
ping: https://google.com: Name or service not known
[root@localhost ~]# ping https://61.91.161.217
ping: https://61.91.161.217: Name or service not known

`

resolv.conf

[root@localhost ~]# cat /etc/resolv.conf 
nameserver 10.0.2.3
nameserver 8.8.8.8
nameserver 8.8.4.4
search localhost

`

ifconfig

[root@localhost ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::5054:ff:fe73:fb1  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:73:0f:b1  txqueuelen 1000  (Ethernet)
        RX packets 610587  bytes 48453952 (46.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 468759  bytes 41290880 (39.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.33.10  netmask 255.255.255.0  broadcast 192.168.33.255
        inet6 fe80::a00:27ff:fe0e:ae16  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:0e:ae:16  txqueuelen 1000  (Ethernet)
        RX packets 3069145  bytes 2674132747 (2.4 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2531212  bytes 213727091 (203.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

network file automatically created from vagrant

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
NAME="eth0"
ONBOOT=yes
NETBOOT=yes
UUID="704aa015-53dd-4ba7-9689-b9b8bf6e09a5"
IPV6INIT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
HWADDR=52:54:00:73:0f:b1
DNS1=8.8.8.8
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
NM_CONTROLLED=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.33.10
NETMASK=255.255.255.0
DEVICE=eth1
PEERDNS=no
DNS1=8.8.8.8
Carey
  • 307
  • 2
  • 5
  • 13

8 Answers8

33

First make sure you have your network adapter enabled in virtual box settings.

Your network interface which you use it for connecting to internet might not be active.

  1. To check this,use "sudo nmcli d" command.

  2. If it is disconnected,use "sudo nmtui"->Edit a connection,select your network interface and choose "Automatically connect" option(by pressing Space key) and select OK.

  3. Do "sudo reboot now" After logging in,do "ping www.google.com".

You should be able to connect now.

weber
  • 733
  • 1
  • 5
  • 12
  • Worked! Only difference is restarting my centos vm deactivated the network interface. But running the commands fixed the problem you rule – newITguy Oct 09 '19 at 00:01
  • The part of your answer that actually mattered was "ping www.google.com". Because the "http://" they were using prefixed to the domain name or IP# is not part of the domain name or IP# (nor is it a valid part of one or the other). The ping command takes host/domain names or IP#s arguments, not a URL that contains a protocol or anything else. – Matthew May 14 '21 at 16:15
24

ping has nothing to do with HTTP or HTTPS:

Ping will use ICMP protocol, it belongs to TCP/IP

Ping operates by sending Internet Control Message Protocol (ICMP) echo request packets to the target host and waiting for an ICMP response.

Actually ping works at a much lower level than HTTP or HTTPS, and only accepts hostnames, not URLs.

Mairon
  • 621
  • 8
  • 21
  • 6
    "Actually ping works at a much lower level than HTTP or HTTPS, and only accepts hostnames, not URLs." Yep. Agreed. Couldn't have been more succinctly put. – T-Heron Apr 15 '17 at 14:44
  • 1
    As @T-Heron said, ping works with ip addresses or domain names. So try to ping google.com without the 'http://' prefix. – barper May 26 '21 at 16:50
2

change the VirtualBOx network card

use -> Intel PRO/1000 T Server (82543GC)

1

There is another possibility,If you are a cloned machine, please check the UUID of the server NIC,The UUID is the same, and this will also happen, please delete the UUID。

eg:CentOS 7

cat /etc/sysconfig/network-scripts/ifcfg-ens192 
...
UUID=03da7500-2101-c722-2438-xxxxxxx
...
0

I tried a lot of different solutions. Changed resolve.conf a billion times. In the end I just needed to restart the router lol. Solved for me I hope it does the same for you.

  • 12
    Assuming each time you took 5 second, it comes to be 5 billion seconds, i.e. `158.55 year`. Hats off to you!! – Kamal Nayan Feb 22 '19 at 18:46
  • So you were able to (ping http://some-domain-name.com)? That shouldn't work, even with your networking configured fully correctly. Because ping takes only host/domain names or IP#s, not URLs. – Matthew May 14 '21 at 16:16
0

If you are able to ping all the network devices and only facing issue like - ping: http://google.com: Name or service not known , then you should try to remove all the lines and try to put only one nameserver in /etc/resolv.conf . enter image description here

-1

Okay I tried so many times with all different methods. But in the end what worked was that my linux system was connected to Internet. I changed to NAT and it worked.

-3

Check /etc/nsswitch.conf and remove the # from below line

networks: files #dns

  • 1
    If you need to say something, Please comment. – Nur Mar 31 '21 at 21:39
  • 1
    That config has nothing to do with the problem reported, as the answer chosen as correct shows. Do not edit nsswitch.conf if you don't understand how it works, or if you don't understand how ping works. Configuring it wrong can cause the host networking to fail, or to become insecure in ways you'll understand even less. – Matthew May 14 '21 at 16:19