0

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 
7
  • are you able to ping 8.8.8.8 from PC1? Oct 16, 2015 at 10:22
  • @KonradGajewski yes
    – Kumar
    Oct 16, 2015 at 11:02
  • Show me the entire iptable on the router (all tables). Oct 16, 2015 at 11:06
  • @KonradGajewski I have edited with iptables values.
    – Kumar
    Oct 16, 2015 at 11:32
  • They all seem fine. What is the error you get on the PC? Oct 16, 2015 at 11:44

1 Answer 1

1

Have you correctly set DNS server on PC? Can you ping www.google.com instead of 8.8.8.8? It looks like your PC cannot translate domain name to IP.

1
  • Looks like the issue is with nameserver. I set the 8.8.8.8 (Google Nameserver) in /etc/resolv.conf and everything worked good. Thank you.
    – Kumar
    Oct 19, 2015 at 3:59

You must log in to answer this question.

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