0

I have a router with 4 ports. One of the ports connects to my pi zero server. And on my pi zero, I have another ethernet port that connects to my computer. My pi has a simple web server running.

It would look something like this:

Router < === > PiZero < === > Computer

  1. How do I setup my pi zero with 2 ethernet ports. With one port going to the router and the other going to my computer but also providing that computer with access to the entire network and the internet?
  2. What hardware would I need for 2 ethernet ports on a pi zero?
  3. What software would I need to setup to make this work?
  4. What is this called exactly? Is this a Network bridge?
  • this sounds like an X-Y Problem. Please let us know why you want to do this, which'll allow us to provide specific answers. eg: do you want to firewall traffic? – stevieb Sep 7 '16 at 21:52
  • No i want to have a web server running on the pi zero where any connected computer to the router can access this web server. I'm planning to embed the pizero inside the router and power it aswell via soldering the points needed for etherenet and power. – Patoshi パトシ Sep 8 '16 at 3:54
1

I suspect you'll need a USB-Ethernet adapter.

A network bridge is a device that operates at Layer-2 of the network stack, and doesn't understand the IP protocol (ie, it just forwards frames).

A router (which it sounds like you want) is Layer-3, each interface requiring an IP in a different network subnet. You then have to enable IP forwarding on the Pi, make the existing gateway aware of the new network on the far side of the Pi, update existing DHCP with a new scope, add a DHCP relay to the Pi (or add a DHCP server on the Pi, or use static to avoid altogether).

So, let's say your existing network is DHCP-enabled in the 192.168.0.0/24 subnet, and the current default gateway (your Internet gateway) is 192.168.1.1.

  • configure the Pi's existing interface to a static IP (eg: 192.168.1.2/24)
  • add a new Ethernet interface to the Pi (USB dongle or the like)
  • configure the new interface on a new subnet (192.168.20.0/24) with an IP of 192.168.20.1
  • enable IP-forwarding on the Pi:

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

  • make the forwarding permanent. Edit the /etc/sysctl.conf file with sudo, and uncomment the following line:

    net.ipv4.ip_forward=1

  • on your existing Internet gateway device, add a new route (this will be device specific). The new route will be pointing 192.168.20.0/24 to 192.168.0.2 (the Pi's 'external' interface address)

  • now, you'll configure your computers behind the Pi with an address in the 192.168.20.0/24 address space, with a default gateway of 192.168.20.1. The DNS servers on the client should point to the IP of the Internet gateway device (192.168.1.1) if it does DNS, if not, the IPs of your ISP DNS servers (you could set up a DNS server on the Pi, if you wanted to)
  • if you want to have DHCP available instead of static addresses on the internal side of the Pi, you'll have to either configure your Pi as a DHCP server and create a new scope with the new subnet, or add a new scope to your Internet gateway DHCP server if this feature is available, and using dhcrelay on the Pi, relay DHCP requests from the inside Pi network to 192.168.1.1
| improve this answer | |
  • i want all devices to be on 192.168.1.x so every device can see each other. the pizero should have DHCP as the dhcp will be done by the router. – Patoshi パトシ Sep 8 '16 at 16:00
  • You don't need two eth interfaces for that. Just connect everything to the main gateway, and run your web server on the Pi's IP address. All devices will be able to access the Pi. – stevieb Sep 8 '16 at 16:10
  • I need 2 eth interfaces on the pizero because i cannot plug my computer to the router. – Patoshi パトシ Sep 8 '16 at 16:14
  • ok, then you either need to bridge the unit, or better yet, just go buy a small network switch, connect it to your gateway, and connect your devices to it. – stevieb Sep 8 '16 at 16:28
  • Remember when you have a multi-homed device (one with more than one active ethernet interface) that the "name" that a device has when seen from other devices on a network more properly belongs to the interface rather than the device itself - forgetting this can make things a little confusing at times...! Also - your connection diagram implies that ALL the internet traffic for your "Computer" will have to pass via not one but two USB network devices on the RPiZero which will impose something of a bottleneck if you plan to pass large/fast volumes of network traffic! – SlySven Sep 9 '16 at 19:52

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.