1

I want to use the pi3 as gateway (to scan network traffic + pihole). My desktop is connected via cabled connection.

The route (outbound):

Computer, Ethernet port ---EthernetCable---> PI3, USB-Ethernet Adapter (in) -- PI3 Ethernet port (out) ---EthernetCable---> Router

Is this route / setup possible?

2
  • 1
    yes, it is possible ... there are many tutorials about linux networking
    – jsotola
    Jul 10, 2021 at 22:55
  • I have updated the answer with installation of pi-hole.
    – Ingo
    Jul 12, 2021 at 23:03

1 Answer 1

2

Yes, it is possible to have either a router or a bridge between your local network and the internet router. With a router you will have two subnets with different ip address ranges, each interface connected to one subnet. So you have to manage some simple routing configuration to your subnets, at least a static route on your internet router. Or you use Network Address Translation (NAT) with the restriction that you cannot connect to devices on the local subnet from outside the local network.

So I would prefer a bridge. It is completely transparent to other network devices. Because it is working on the Data Link Layer (OSI layer 2 with mac addresses) and not on the Network Layer (OSI layer 3 with ip addresses) it does not involve ip addresses. On the bridge you can sniff the network traffic and you can use nftables (successor of iptables) as firewall to control access and connections. How to do that you can look at the "man in the middle" bridge.

When following that tutorial to setup a bridge you should prepare it for installation of pi-hole. You need a static ip address on the br0 interface. So modify /etc/systemd/network/12-br0_up.network to this:

rpi ~# cat > /etc/systemd/network/12-br0_up.network << EOF
[Match]
Name=br0
[Network]
Address=192.168.50.10/24
Gateway=192.168.50.1
DNS=84.200.69.80 1.1.1.1
EOF

Of course you have to use an ip address from your local network and you must ensure that it isn't given to another device by a DHCP server. The Gateway is the ip address of your internet router. After a reboot the bridge should work. You should be able to browse from your local network as before. The bridge is transparent.

Now you can install pi-hole. The problem is that it expect default networking dhcpcd5 to be available. But to avoid conflicts with systemd-networkd we have deinstalled it. pi-hole tries to install it but fails with an error message because we have set dhcpcd5 on hold that prevents unexpected installation. So we will remove dhcpcd5 from the installation script with the stream editor sed. pi-hole doesn't need it. systemd-networkd is doing its work. So install pi-hole with this modified installation stream and follow its setup:

curl -sSL https://install.pi-hole.net | sed 's/INSTALLER_DEPS=(\(.*\)dhcpcd5/INSTALLER_DEPS=(\1/;s/setStaticIPv4() {/setStaticIPv4() { return 0;/' | sudo bash

On the installation dialog select interface br0.

That's it. Now you have a transparent bridge where you can sniff on its interfaces eth0 and eth1 and that is also working as pi-hole.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.