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
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.
Comments