I'm just starting out on a mission to learn more about networking and I've followed a tutorial (http://raspberrypihq.com/how-to-turn-a-raspberry-pi-into-a-wifi-router/) to turn my Raspberry Pi into a wifi router.

That worked really well so I modified it slightly so that I can use a tethered iphone for the internet connection - I just switched all "eth0" references to "eth1" (the iphone interface) and added a script to set everything up when the phone is plugged in.

This setup has freed up the Pi's ethernet port so I'd like to try and take this a step further and allow devices plugged into it to connect to the network. If possible, I'd like to try adding a switch so I can connect multiple devices.

I've tried fiddling around with nat & iptables with no luck so my question is, how can I connect devices on eth0 to my wlan network?


Some extra info below. These are from after the phone is plugged in.

Output from iptables -t nat -L:

target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

target     prot opt source               destination         
MASQUERADE  all  --  anywhere             anywhere

Output from netstat -rn:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface         UG        0 0          0 eth1 U         0 0          0 eth1   U         0 0          0 wlan0


The following is in my dhcpd.conf file:

subnet netmask {
 option broadcast-address;
 option routers;
 default-lease-time 600;
 max-lease-time 7200;
 option domain-name "local-network";
 option domain-name-servers,;

dhcp is configured to run on wlan0 - /etc/default/isc-dhcp-server:


Strictly speaking, not much else is required. I presume you have already enabled IPv4 forwarding, and possibly also this rule:

  iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

which will allow you to NAT all of your connections. Then your routing table needs

  ip route add default via IP_ADDRESS_OF_YOUR_PHONE

which it also presumably already has. Then you are good to go.


Now that you posted your routing table (but please, do not use obsolete, deprecated commands like *ifconfig, route,..., just the ip command, for instance, for the routing table ip route show, to see the addresses of interfaces ip addr show,...) I see that you do not have a route to your ethernet port-clients. If the network from which you draw IP addresses port cable-connect clients is, then you will have to add:

   ip route add dev eth1

You should not use the same network for wireless- and cable- clients.

If furthermore you need to configure dhcpd, then edit the same file /etc/dhcp/dhcpd.conf as before, and add the new network:

  subnet netmask {
option subnet-mask;
option routers;

subnet netmask {
option subnet-mask;
option routers;

In the file /etc/default/isc-dhcp-server, change the line INTERFACES="wlan0" to

 INTERFACES="wlan0 eth0"

and lastly give the router a good address on its eth0 NIC:

 ip link set dev eth0 down
 ip addr flush dev eth0
 ip addr add dev eth0
 ip link set dev eth0 up

Restart dhcp, you should be Ok.

  • Thanks for your answer. I tried ip route add default via and got the error: RTNETLINK answers: File exists. I've edited my answer with some extra info.. any ideas where I'm going wrong? – Tom Jun 11 '14 at 12:21
  • @Tom Nowhere: it only means it already has a default gateway. However, your problem (now that you post your routing table) is that you do not have a route to reach pcs connected via cable. You will need to add that. I will add shortly an Edit to my answer – MariusMatutiae Jun 11 '14 at 12:30
  • @Tom Can you tell me whether you have already configured dhcp on eth0? – MariusMatutiae Jun 11 '14 at 12:33
  • @Tom Please see my edit. – MariusMatutiae Jun 11 '14 at 12:48
  • I've added my dhcp configuration to my original question. I followed your instructions and got connected to the Pi from my mac with the ip but couldn't access the internet or ssh to the Pi. Any ideas? – Tom Jun 11 '14 at 14:06

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.