I have a laptop with linux installed on it. The laptop has two network interfaces: eth0 and wlan0. Normally I surf the Internet through eth0, and I've successfully set up a hotspot in linux for my kindle to use. Important codes are as follows:
# Enable NAT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# Run access point daemon
sudo hostapd /etc/ap-hotspot.conf
Usually I would like to surf the Internet through an encrypted socks5 proxy: 127.0.0.1:10000, and I want the proxy system-wide, so I installed redsocks, which can redirect all the TCP connections to the socks5 proxy. Important codes are as follows:
#redsocks requires all the data to be redirected to port 12345, and the socks5 address and port(127.0.0.1:10000) has been written to redsocks's configuration file.
sudo iptables -t nat -A OUTPUT -p tcp -j REDIRECT --to-port 12345
So far, It seems everything works great. My kindle can connect to the hotspot, and I can surf the Internet through a system-wide proxy in linux. The problem is, my kindle bypasses the socks5 proxy and connects to the Internet directly. So how to make my kindle go through the proxy when using the hotspot? I mean, how to do it in linux, because there's no way to set up a proxy in my kindle.
Best Answer
I have a similar set up.
wlan0
is connected to the internet (through my router) whilewlan1
acts as a hotspot (Access Point) for my Android phone.wlan1
is set up with ipv4 address10.0.0.1/24
that is my phone gets ip address in the10.0.0.x
range.The iptables rule I use to pass all traffic from my phone through redsocks is:
sudo iptables -t nat -A PREROUTING -s 10.0.0.0/24 -p tcp -j REDIRECT --to-ports 12345
As far as I understand it this rule basically takes all tcp traffic from any source device with address
10.0.0.0/24
and redirects it to the12345
port which passes it throughredsocks
.