2

I am configuring my Rpi 3 as ethernet router. I have used dnsmasq for configuring dns and dhcp server. The configuration files are given below.

/etc/network/interfaces

auto lo
iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug eth1
iface eth1 inet static
    address 192.168.2.1
    netmask 255.255.255.0
    network 192.168.2.0
    broadcast 192.168.2.255

up iptables-restore < /etc/iptables.ipv4.nat

/et/dnsmasq.conf

interface=eth1 #listen only to interface eth1
listen-address=192.168.2.1 # listen on
# Bind to the interface to make sure we aren't sending things
# elsewhere
bind-interfaces
server=8.8.8.8 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
# Never forward addresses in the non-routed address spaces.
bogus-priv
# Assign IP addresses between 192.168.2.2 and 192.168.2.100 with a
# 12 hours lease time
dhcp-range=192.168.2.2,192.168.2.100,12h

/etc/sysctl.conf

kernel.printk = 3 4 1 3
net.ipv4.ip_forward=1
vm.swappiness=1
vm.min_free_kbytes = 8192

At last iptables configuration for seting nat is given below

sudo iptables -F
sudo iptables -t nat -F

#Connect a LAN to the internet
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

#forward only the packets that are associated with an established #connection
sudo iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT

#forward all packets from eth1 to eth0
sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

sh -c "iptables-save > /etc/iptables.ipv4.nat"

These configuration perfectly works for older wheezy versions and jessie lite version too but in jessie full version( 2017-08-16) its not working.

When i configured the files above, rpi won't get connected to my external router (router and rpi are connected through a lan cable). I think this is because configuration for eth0 is changed when i configured the files as above.

In Raspbian jessie version, i don't know where to configure the network interfaces. Also they shipped with inbuilt bind9 and dhcpcd, hence is there any conflict with dnsmasq server.

sudo service dnsmasq status throws an exit-code error.

Can anyone please help me to solve this?

How to configure Rpi 3 with raspbian jessie for the ethernet router?

0

Run sudo nano /etc/rc.local And before exit 0; paste:

iptables-restore < /etc/iptables.ipv4.nat

It works for me on Stretch and I've been following raspberrypi.org tutorial and using dhcpcd method ( SUPER IMPORTANT FOR Stretch VERSION )

That's my guess. Provide the error message you get.

0

In etc/network/interfaces, you don't bring up eth0 automatically -

auto lo iface lo inet loopback iface eth0 inet dhcp

Add in auto eth0 to make sure that eth0 will actually come up and get an IP address, so it should look like this -

auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp

Also the same with eth1, make sure you bring that up automatically.

Raspbian Stretch uses dhcpcd.conf to configure the networking unless they are configured in /etc/network/interfaces

0

I think i've read somewhere that you should not modify /etc/network/interfaces anymore.

If you want to set up static IP's you should modify /etc/dhcpcd.conf

interface eth1
static ip_address 192.168.2.1/24

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.