0

I have a fresh installed raspberry pi 3 that is connected to my laptop via ethernet. I want my laptop to act as a router between the raspberry and internet.
I get the network and router configuration done so I can do ping 8.8.8.8 on the raspberry and get answer back. But I can't get dns to work (ping google.com gives Temporary failure in name resolution).

Here are my configuration files on the raspberry :

In /etc/network/interfaces

# message about the file being used with dhcpcd
source-directory /etc/network/interfaces.d
dns-nameservers 8.8.8.8 8.8.4.4

In /etc/dhcpcd.conf

# lot of stuff
static domain_name_servers=8.8.8.8 8.8.4.4

In /etc/resolv.conf

nameserver 8.8.8.8

Config on the laptop/router :
Linux Mint 18.04
card for internet connection : wlo1
card for rapsberry connection : enp2s0

In /etc/resolv.conf

nameserver 127.0.0.53

Iptables commands used :

iptables -t nat -A POSTROUTING -o wlo1 -j MASQUERADE
iptables -A FORWARD -i enp2s0 -j ACCEPT

With all that I tried on the pi I'm starting to think the issue is somewhere in the laptop/router configuration. So my question is shoud I install a DNS server on the laptop/router to forward the dns requests from the pi?

I found a lot of issues on this forum with same titles but a lot of them try to use the pi as a DNS server. I just it to access the net. (wifi not working and can't access directly to the home router with cable)

Please note that with the dns not working I can't install any packages (in particular I can't dig nor nslookup on the raspberry)

EDIT : As the settings where not saved, I had to redo the commands after a restart and this time it worked, but I don't know exactly what I did differently that made it works.
Among all what I did on the laptop are :

  • uninstall conntrack firewalld and dnsmasq that I installed following random tutorials.
  • changed iptable commands to only iptables -t nat -A POSTROUTING -o wlo1 -j MASQUERADE (second is not needed because firewall has an ACCEPT policy on all chains)
2
  • Haven't read all details but at a glance you are doing many things wrong. You mixed up /etc/network/interfaces with dhcpcd and you modified /etc/rresolv.conf that is managed by openresolv and shouldn't touched.
    – Ingo
    Feb 11 at 20:21
  • Yes I edited more and more file following different tutorials as the first ones didn't made it work. But I suppose that if a specific manager is enabled (like dhcpcd) the default files are just ignored
    – Nonoreve
    Feb 13 at 13:57
0

You need to do NAT forwarding on your laptop it is not simply enough to connect the cable to it. You do not mention the OS on it so impossible to give directions on this part of it, you need to enable it regardless of OS. This allows it to pass the connection to your network where it should allow the Pi to connect and get a connection to get the IP and the DHCP server information from it, the router via the NAT.

Edit: In windows they call it Internet Connection sharing, I think, linux is NAT.

Edit2: In this page I see no mention of them wlo1 options being used, give their entire procedure a try.

https://www.howtoforge.com/nat_iptables

4
  • added the informations concerning my laptop and nat configuration
    – Nonoreve
    Feb 10 at 16:55
  • Added procedure for you to try, not sure if you get notified on an edit. I know you do on a reply comment.
    – user130167
    Feb 10 at 17:11
  • Thanks, I looked at the tutorial you gave but their using /etc/sysconfig directory which is a system that's specific to RHEL and that don't exist on Ubuntu.
    – Nonoreve
    Feb 13 at 13:56
  • The /etc/sysconfig settings have nothing to do with it you ahve an IP and all of that no need to be checking it again. It is the iptables commands you need to implement. They are universal no matter the distribution.
    – user130167
    Feb 14 at 1:32
0

Solved (a bit by magic) as stated in the edits of the questions. I retain that keeping the configuration temporary is a good think because it allows a clean rework on next attempt.
Here is a summary of my commands :

  • On the laptop/router :
    ip addr add 169.254.187.69/16 dev enp2s0
    iptables -t nat -A POSTROUTING -o wlo1 -j MASQUERADE
    Not to forget editing /etc/sysctl.conf for ip forwarding.
    I will store them as a script and not setup static configuration as I don't want it to setup at start-up. (The router function is not needed when raspberry is not connected, also the kernel seems to don't like when you try enabling at start-up an Ethernet card that is not connected to anything)
  • on the raspi :
    route add default gw 169.254.187.69
    static domain_name_servers=8.8.8.8 8.8.4.4 In /etc/dhcpcd.conf
    Other setup is let 'as is' because its the default behaviour of the primary card.

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.