0

I have a RaspberryPi along with a USB to Ethernet adapter (eth1).

I want to bridge eth0 and eth1 and create a br0 interface.

I want to devices connected to eth1 receive their DNS (dnsmasq) settings from Raspberry Pi either with or without DHCP.

How do I go about setting up /etc/network/interfaces and dnsmasq.conf so that dnsmasq is running on the bridge ?

EDIT:

I am trying to limit to dnsmasq to only eth1 , I thought bridge was the best way , is there a better way ?

My setup : ISP -> Router ( DHCP Turned Off ) -> Raspberry Pi -> Devices

My ISP does not have a modem and is direct ethernet connection in my house.

When I connect devices to eth1 on Raspberry Pi, before dnsmasq can answer, the ISP is handing out a DHCP lease bypassing dnsmasq.

My goal: I want the Raspberry Pi in my setup to provide DNS Settings automatically to all devices connected to my network, without manual configuration. I actually don't care if Raspberry Pi provides DHCP, I turned DHCP off on the Router since I came to the conclusion you need to provide DHCP to automatically traverse DNS settings, please let me know if I am wrong.

John
  • 1
  • 1
  • 1
  • 2

2 Answers2

4

There are 3 steps necessary to accomplish what you're describing:

  1. Create the bridge device.
  2. Assign an IP address to the bridge device.
  3. Configure dnsmasq to listen on the bridge interface IP address.

Creating the bridge device is simple:

sudo apt-get install bridge-utils
sudo brctl addbr br0
sudo brctl addif br0 eth0 eth1

If you want it created automatically, modify /etc/network/interfaces:

iface eth0 inet manual
iface eth1 inet manual

# Bridge setup
iface br0 inet static
    bridge_ports eth0 eth1
    address 192.168.0.2
    netmask 255.255.255.0
    gateway 192.168.0.1

For all intents and purposes, the newly-created bridge interface (br0) is just another interface. In this example, the RPi will be assigned 192.168.0.2 and use 192.168.0.1 as its default gateway.

Configuring dnsmasq is done just as with any other interface. dnsmasq supports a lot of options, but one setting is essential: Define a dhcp range:

dhcp-range=192.168.0.128,192.168.0.191,72h

Once you have dnsmasq configured, it will hand out dhcp leases to devices connected to either interface in the bridge pair. dhcp requests received on either eth0 or eth1 will be assigned addresses by dnsmasq. Be sure this is what you want! If you want to limit dnsmasq to only eth1, you'll need to do some additional work, and bridging may not be the best answer.

For devices not using dhcp, simply point them to your RPi's IP address (192.168.0.2 in this example) for their DNS server.

The Debian wiki has an excellent summary on bridging. As Joan notes, the /etc/dnsmasq.conf file has a wealth of documentation on configuring it for dns and dhcp options.

EDIT: In hindsight, the question appears to be simply about configuring dnsmasq on an internal network, and not about routing or bridging. I'll leave this response here in case somebody really is after a bridged solution.

bobstro
  • 3,978
  • 15
  • 27
-4

follow the bridge steps but only add eth1 then do a ip route add default gw. no iptables should be required for either. translation is usually only required for wifi. libvirt does that and can do that without iptables. set ips are very specific. learn to describe, and search for what you want before you ask. sound like your missing a few things that only you should know anyway

moofer
  • 1