0

Not sure this is the right place to post this question.

My issue is actually simple, I have my android device using a data connection, and a hotspot setup on this device.

I connect my linux box to this hotspot, no problem.
My pc gets the address 192.168.1.234 on wlan0
My android device is 192.168.1.1 on wlan0
=> wlan0 UP 192.168.1.1/24

I can ping the local wifi addresses from both side. However, I cant ping a server located on internet from my pc.

I know there is something about forwarding the traffic from 1 side to the other but I cant figure out how to do it.

I did so far : On the android device

$ echo 1 > /proc/sys/net/ipv4/ip_forward
$ iptables -t nat -F
$ iptables -t nat -A POSTROUTING -j MASQUERADE

Nothing special on the pc except adding a route for a special server I want the traffic to go through the wlan0.

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.162.105.1    0.0.0.0         UG    0      0        0 eth0
10.162.105.0    *               255.255.255.0   U     0      0        0 eth0
158.x.x.x       192.168.1.1     255.255.255.255 UGH   0      0        0 wlan0
192.168.1.0     *               255.255.255.0   U     0      0        0 wlan0
192.168.25.0    *               255.255.255.0   U     0      0        0 vmnet1
192.168.29.0    *               255.255.255.0   U     0      0        0 vmnet8

On the android side, I can see the traffic coming from my pc ie.

03:50:17.426155 IP 192.168.1.234 > 158.x.x.x: ICMP echo request, id 5782, seq 634, length 64
03:50:18.427529 IP 192.168.1.234 > 158.x.x.x: ICMP echo request, id 5782, seq 635, length 64
03:50:19.428445 IP 192.168.1.234 > 158.x.x.x: ICMP echo request, id 5782, seq 636, length 64
03:50:20.425667 IP 192.168.1.234 > 158.x.x.x: ICMP echo request, id 5782, seq 637, length 64
03:50:21.426491 IP 192.168.1.234 > 158.x.x.x: ICMP echo request, id 5782, seq 638, length 64
03:50:22.425759 IP 192.168.1.234 > 158.x.x.x: ICMP echo request, id 5782, seq 639, length 64
03:50:23.425759 IP 192.168.1.234 > 158.x.x.x: ICMP echo request, id 5782, seq 640, length 64

but never see a reply, like the packets would never go out of the android device.

What am i doing wrong?

Thanks for the help.

1 Answer 1

1

I got the answer by myself.

The issue was with the iptables command. It was necessary to specify the output device and also set the forward policy.

iptables -t nat -A POSTROUTING -o rmnet_usb0 -j MASQUERADE
iptables -P FORWARD ACCEPT

After that internet becomes accessible on the linux box side. Hope this helps somebody in the same situation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .