0

I connected my Pi to my home computer through an Ethernet link. My computer is connected to the Internet by a wireless connection. And I'd like to route all Internet traffic from my Pi by my computer.

I set a /30 subnetwork on the Ethernet link, and I added routes on both, so they can ping each other.

Here are my configurations.

My computer:

# IP addresses
eth0 192.168.1.1/30
wlan0 192.168.0.13/24


# IP routes
default via 192.168.0.254 dev wlan0  proto static  metric 600 
169.254.0.0/16 dev wlan0  scope link  metric 1000 
192.168.0.0/24 dev wlan0  proto kernel  scope link  src 192.168.0.13  metric 600 
192.168.1.0/30 dev eth0  scope link 

My Pi:

# IP address
eth0 192.168.1.2/30

# IP routes
default via 192.168.1.1 dev eth0
default via 192.168.1.1 dev eth0  proto static  metric 1024 
169.254.0.0/16 dev wlan0  scope link  metric 1000 
192.168.1.0/30 dev eth0  scope link 

On my computer, to route all traffic from eth0 to wlan0, do I just have to add some routes? Or do I have to use NAT with iptables?

EDIT:

After the Henrik's answer I did some search about masquerading, and I found this tutorial.

In this, he says to check if the masquerading kernel support is up, by looking in the /proc/net dir, for a 2.2x kernel.
In my 4.2.x kernel, I didn't find the file that he mentions, but I found some *masquerade*.ko files. Is this mean masquerading support is up in my kernel?
If not, is there a way to set it up without recompile my kernel ?

At the end of the tutorial, he gives some firewall rules to make the masquerading.
The first one is:

/sbin/ipchains -A input -j ACCEPT -i eth1 -s 0/0 67 -d 0/0 68 -p udp  

This is just to let the DHCP requests go trough for the "hidden" computer. But me I fixed the Ip manually on my PI, so I don't need it, right ?

Then, there are this two rules:

/sbin/ipchains -P forward DENY
/sbin/ipchains -A forward -s 10.1.199.0/24 -j MASQ

Why is there a DENY ?
For my subnetwork, it's

/sbin/ipchains -A forward -s 192.168.1.0/30 -j MASQ

Right ?

EDIT 2:
I found a newer tutorial as suggested by Henrik.
In the /etc/rc.local file, I added:

iptables -t nat -A POSTROUTING -s 192.168.1.0/30 -o wlan0 -j MASQUERADE

So now the masquerading seems to be working, but not completely.
Indeed, when I try to ping google.com with the IP address (8.8.8.8) it's working, but if I try with the url it's not.

I supposed it was because of somes DNS porblems, so I add some DNS's IPs in the /etc/resolv.conf file. And it changed nothing.
So I tried to go to DuckDuckgo with the IP address in Firefox, and it's not working.

So it seems, only ICMP traffic is forwarded. I checked with wireshark what is coming from eht0 and what is living by wlan0.

4
  • If that tutorial talks about 2.2 kernels you really should find a newer. – Henrik supports the community Apr 2 '16 at 7:32
  • I found a newer, but it's not completely working! :s – Phantom Apr 3 '16 at 10:10
  • There's not much to go on now. If only ICMP gets through you must have some firewall rules on the computer doing the masquerading. 8.8.8.8 is not the ip for google.com, but for their public DNS service. If you don't have firewall rules that only allow ICMP, my guess would be that you forgot to enable ip forwarding on the computer, if that's not the case we'll need a lot of details about yor setup to figure out what is wrong. – Henrik supports the community Apr 3 '16 at 21:50
  • You're write, it was because of my firewall. No it's working! \o/ Thanks ;) – Phantom Apr 4 '16 at 15:45
0

You need to turn on forwarding (might be on by default), and setup masquerading (just a fancy word for a special kind of NAT, but it will probably help you to know what to search for).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.