beringresearch / macpine

Lightweight Linux VMs on MacOS
https://beringresearch.github.io/macpine/
Apache License 2.0
911 stars 22 forks source link

Why does ping not work but curl does #107

Closed johnlonganecker closed 1 year ago

johnlonganecker commented 1 year ago

On a 2019 x86 macbook I do the follow:

alpine launch -d 8G -c 1 -m 2048
ssh root@localhost

apk add curl

# ping google.com
PING google.com (142.250.68.110): 56 data bytes
64 bytes from 142.250.68.110: seq=0 ttl=255 time=2326203.246 ms
64 bytes from 142.250.68.110: seq=0 ttl=255 time=2327215.976 ms (DUP!)
64 bytes from 142.250.68.110: seq=0 ttl=255 time=2328217.294 ms (DUP!)
64 bytes from 142.250.68.110: seq=0 ttl=255 time=2329223.278 ms (DUP!)
^C
--- google.com ping statistics ---
4 packets transmitted, 1 packets received, 3 duplicates, 75% packet loss
round-trip min/avg/max = 2326203.246/2327714.948/2329223.278 ms

curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

If I ping from my macbook directly in iterm I get 0 % packet loss:

~ ping google.com
PING google.com (172.217.14.78): 56 data bytes
64 bytes from 172.217.14.78: icmp_seq=0 ttl=58 time=6.140 ms
64 bytes from 172.217.14.78: icmp_seq=1 ttl=58 time=8.401 ms
64 bytes from 172.217.14.78: icmp_seq=2 ttl=58 time=12.542 ms
64 bytes from 172.217.14.78: icmp_seq=3 ttl=58 time=11.803 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 6.140/9.721/12.542/2.591 ms

I have also tested on a M1 Max and get the same result.

What am I doing wrong?

idroz commented 1 year ago

Could you try

ping 8.8.8.8 inside the VM?

idroz commented 1 year ago

Having done a bit of research, machines QEMU configuration uses user networking (SLIRP). Although the network is easy to set up (hence its choice here), it doesn't support PING inside the guest (see https://wiki.qemu.org/Documentation/Networking#User_Networking_(SLIRP))

However, you should still be able to send and receive traffic and install additional software inside the guest as required.

Does this networking option preclude your work inside macpine VMs?

maxzinkus commented 1 year ago

That info is a good candidate for the FAQs/troubleshooting doc as it may be a common point of confusion