I have made my Raspberry Pi an access point and DHCP server and it is working fine. I have used iface wlan0 inet static and provide static ip address for it and I have left iface eth0 inet manual as it is.

The part I am confused about is do I need to configure eth0 with a static IP address in order to make the Raspberry Pi act as a router, or is just configuring wlan0 enough? In what case do we need to configure interface wlan0 (wireless) and eth0 (wired)? What commands do we need to add to make the Raspberry Pi a router as I have already made it an access point?

  • When you connect to the pis hotspot right now what happens? – Mohammad Ali Mar 21 '17 at 5:38

To enable routing, assuming you're running a standard kernel, etc.

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

So far as addressing, just configure the interfaces however you need to. If your RPi is going to be an access point, you'd want the wireless interface (wlan0 presumably) to have a fixed IP address. If the Ethernet interface (eth0 presumably) is your outside interface, use DHCP if the network it's connecting to provides dhcp. The main requirements are that:

  1. The RPi itself be able to access external addresses.
  2. Routing be enabled as above.
  3. The devices attaching to the RPi use the RPi's IP address as their default gateway.

If those conditions are met, it should "just work" as a router on your local network.

Keep in mind, if your external connection is an Internet connection, you probably need to set up NAT as well.

| improve this answer | |

I'd recommend setting a static IP for both interfaces (my personal flavour, not sure if that's needed, though).

In any case, for packets to be able to be routed, you'll need to do the following (all being root of course):

echo 1 > /proc/sys/net/ipv4/ip_forward

or, to make it boot persistant, add

net.ipv4.ip_forward = 1

to /etc/sysctl.conf and activate it using sysctl -p

You might want / need to add some static routes to the routing table as well, depending on what you're trying to achieve and if you're using different networks (keep in mind to set your newly built router as the gateway for specific networks as well on the machines that are supposed to use that router)

| improve this answer | |

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.