I have a few Raspberry Pi2 loaded with Jessie lite on a network. I want them to share the internet connection of a 3G dongle, but I can't make it work.
Here are some details:
The RPi's are all on the same 10.0.0.x network, together with some other devices. I configured them (both RPi's and devices) with fixed IP address on the same subnet and that works fine, they can all talk each other. I need fixed IPs because I want to be able to NAT all devices and access them from the internet later.
Only one RPi (eth0 address 10.0.0.10, let's call it RPi0) has an internet connection, which comes from a Huawei 3G dongle. The dongle creates an eth1 interface with an automatic address that seems to be always 192.168.8.100. If I try to force it to a manual IP, I can't access internet.
Out of the box, when I plug the USB key, RPi0 can access to internet and resolve addresses.
Now I'd like to let all the other devices on 10.0.0.x to access internet through the RPi that has the USB dongle. So I suppose 10.0.0.10 needs to work as a gateway and route the traffic through eth1. I have followed many tutorials up to know, but I must be missing something because I can't make it work.
I have enabled NAT setting net.ipv4.ip_forward=1 in /etc/sysctl.conf
Then I try to specify a NAT rule for all the traffic that must go through eth1
sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
cannot ping anymore public IPs
route looks like this:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default hi.link 0.0.0.0 UG 247 0 0 eth1
10.0.0.0 * 255.255.255.0 U 202 0 0 eth0
192.168.8.0 * 255.255.255.0 U 247 0 0 eth1
what am I doing wrong?
EDIT
the dongle automatically creates an ethernet port with address 192.168.8.100, but the gateway address is 192.168.8.1 (which should be hi.link in the ip tables). So I expect it working, the packets for the internet coming from other 10.0.0.x devices should be routed to the gateway. But they don't.
traceroute
? your output seems quite different from that of this command. – Rho Phi