I want to configure my Rasberry Pi as a router. I have two network interfaces eth0 and eth1 connected to two networks. eth0 is connected to a private network and eth1 is connected to a public network (internet).
wan ----[router]--> [eth1 (Raspbery pi) eth0]<---->[router]<----> [(PC1)]
I did the following things to configure the Raspberry Pi as router:
Step 1:- enable forwarding in the kernel
echo 1 >> /proc/sys/net/ipv4/ip_forward
step 2:- Set rules in iptables to perform natting and forwarding
# eth0 is LAN
# eth1 is WAN
# Masquerade.
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
# fowarding
iptables -A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
Now I am able to ping from to WAN side router via the Raspberry Pi, and also I am able to ping Google IP (8.8.8.8) from PC1. But I was not able to browse any sites on PC1. Ping is working but other way of accessing Internet are not working. How can I debug this iptables to solve this issue? Where can the problem lie?
EDIT:- Here is the iptables vaules.
root@raspberrypi:/home/duser# iptables -t filter -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
root@raspberrypi:/home/duser# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- anywhere anywhere
root@raspberrypi:/home/duser# iptables -t mangle -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination