Let Raspberry Pi connect to internet through Ubuntu in virtual machine

Marc

I have Ubuntu 12.04.5 LTS installed in a virtual machine in OS X. There's a Raspberry Pi connected to the same mac via direct ethernet wire. The mac is connected to the internet via wifi connection.

I want to connect the RPI to the internet, but ping <ip>, wget <url> don't work. Strangely, apt-get IS working. In the Ubuntu virtual machine, everything can connect to the internet, no problem at all.

If i do a sudo tcpdump -a -v -i eth1 in the Ubuntu machine and ping 8.8.8.8 in the RPI, I can see that the traffic is reaching Ubuntu, but the RPI gets no response. I see this in Ubuntu:

10.0.0.101 > google-public-dns-a.google.com: ICMP echo request, id 2156, seq 1, length 64
09:49:47.008804 IP (tos 0x0, ttl 64, id 22891, offset 0, flags [DF], proto ICMP (1), length 84)
10.0.0.101 > google-public-dns-a.google.com: ICMP echo request, id 2156, seq 2, length 64
09:49:48.008648 IP (tos 0x0, ttl 64, id 22985, offset 0, flags [DF], proto ICMP (1), length 84)
...

If I do an wget http://google.com, curl, etc. in the RPI I always see traffic reaching the Ubuntu virtual machine, but never get anything back to the RPI.

How can I connect the RPI to the internet?

Thanks

Marc

Finally I got it working. I was confused because apt-get was working, so I thought that everything was correctly set up in the Ubuntu VM, but it wasn't. I got the solution from this post https://support.hidemyass.com/hc/en-us/articles/202721486-Using-Linux-Virtual-Machine-instead-of-a-router-for-VPN

In your Ubuntu VM, assuming that eth0: internet, eth1: your RPI connected via ethernet cable

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -A FORWARD -o eth0 -i eth1 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A POSTROUTING -t nat -j MASQUERADE
sudo iptables-save | sudo tee /etc/iptables.sav

uncomment this line in /etc/sysctl.conf

net.ipv4.ip_forward=1

The reason why apt-get was working in the first place is still a mistery to me.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Need to connect to the internet from private Virtual Machine on the cloud through a local server with internet access

From Dev

Connect raspberry pi 4 with ubuntu server to wifi

From Dev

Prepare and setup Raspberry Pi image on a PC (virtual machine)

From Dev

Cannot connect to VMWare virtual machine through NAT

From Dev

Raspberry Pi: able to access through own network but not internet

From Dev

Access Raspberry Pi behind a NAT firewall through Internet

From Dev

Connect to Raspberry Pi through SSH without Port Forwarding

From Dev

Connect to Raspberry Pi 4 with Ubuntu Core 18 via serial cable

From Dev

Can't connect with SSH to Ubuntu server (20.04) on raspberry pi 4

From Dev

Virtual machine won't connect to the internet using bridged adapter on virtualbox

From Dev

I can't access the internet through my raspberry pi when connected through ssh

From Dev

Within Ubuntu, let virtual Windows machine control the discrete graphics card

From Dev

Within Ubuntu, let virtual Windows machine control the discrete graphics card

From Dev

Communicating with raspberry pi over internet

From Dev

Cannot connect Oracle ldap server(OID) in a virtual machine through JDBC

From Dev

No internet on virtual machine

From Dev

how to connect windows azure virtual machine with ubuntu system correctly?

From Dev

how to connect windows azure virtual machine with ubuntu system correctly?

From Dev

scp from ubuntu virtual machine under Windows 7: connect refused

From Dev

Connect Robomongo to Virtual Machine

From Dev

Kinect / Primesense (Xtion) ROS Ubuntu through Virtual Machine (VMware)

From Dev

sendmail through virtual machine

From Dev

Can a Raspberry Pi run Ubuntu?

From Dev

Can a Raspberry Pi run Ubuntu?

From Dev

Install ubuntu 18.04 on Raspberry Pi

From Dev

Is Python installed: (Raspberry Pi Ubuntu)

From Dev

virtual machine not having internet connectivity

From Dev

Raspberry Pi - run a program with specified internet connection

From Dev

Raspberry Pi - run a program with specified internet connection

Related Related

  1. 1

    Need to connect to the internet from private Virtual Machine on the cloud through a local server with internet access

  2. 2

    Connect raspberry pi 4 with ubuntu server to wifi

  3. 3

    Prepare and setup Raspberry Pi image on a PC (virtual machine)

  4. 4

    Cannot connect to VMWare virtual machine through NAT

  5. 5

    Raspberry Pi: able to access through own network but not internet

  6. 6

    Access Raspberry Pi behind a NAT firewall through Internet

  7. 7

    Connect to Raspberry Pi through SSH without Port Forwarding

  8. 8

    Connect to Raspberry Pi 4 with Ubuntu Core 18 via serial cable

  9. 9

    Can't connect with SSH to Ubuntu server (20.04) on raspberry pi 4

  10. 10

    Virtual machine won't connect to the internet using bridged adapter on virtualbox

  11. 11

    I can't access the internet through my raspberry pi when connected through ssh

  12. 12

    Within Ubuntu, let virtual Windows machine control the discrete graphics card

  13. 13

    Within Ubuntu, let virtual Windows machine control the discrete graphics card

  14. 14

    Communicating with raspberry pi over internet

  15. 15

    Cannot connect Oracle ldap server(OID) in a virtual machine through JDBC

  16. 16

    No internet on virtual machine

  17. 17

    how to connect windows azure virtual machine with ubuntu system correctly?

  18. 18

    how to connect windows azure virtual machine with ubuntu system correctly?

  19. 19

    scp from ubuntu virtual machine under Windows 7: connect refused

  20. 20

    Connect Robomongo to Virtual Machine

  21. 21

    Kinect / Primesense (Xtion) ROS Ubuntu through Virtual Machine (VMware)

  22. 22

    sendmail through virtual machine

  23. 23

    Can a Raspberry Pi run Ubuntu?

  24. 24

    Can a Raspberry Pi run Ubuntu?

  25. 25

    Install ubuntu 18.04 on Raspberry Pi

  26. 26

    Is Python installed: (Raspberry Pi Ubuntu)

  27. 27

    virtual machine not having internet connectivity

  28. 28

    Raspberry Pi - run a program with specified internet connection

  29. 29

    Raspberry Pi - run a program with specified internet connection

HotTag

Archive