I have a raspberry connected to a pc via ethernet. The pc's ip is that can't be changed, so i had to give the rpi's eth0 so they can communicate.

Meanwhile the rpi's wlan0 is directly linked to the router with a ip.

Now i want the pc to be able the access the internet. i tried editing the /etc/dhcpcd.conf file like this:

interface eth0
static ip_address=
static routers=
static domain_name_servers= fd51:42f8:caae:d92e::1

but it didn't work.

  • 1
    The short answer is yes, you can do this via ip route. I don't use normal network configs though, so you'll have to wait for someone to come along with that knowledge. In the meantime I'd recommend you explain the context of why you want to do this, since it will help clarify things. Some people won't risk wasting their time providing answers to ambiguous questions only to find out "Oh, that's not what I meant...", etc. And they may not bother trying to get the information out of you if you cannot be bothered to provide it in the first place ;) – goldilocks May 5 '18 at 13:19
  • ok thank you, i've changed the description, now should be more understandable – Hbib May 5 '18 at 13:46

Your Raspberry Pi has two interfaces: eth0 ( and wlan0 ( each with an ip address from another subnet. This is a very good condition to make your raspi a router. First you have to enable ip forwarding. There are several ways to do it. You can enable it direct to the kernel with:

rpi ~$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

Or you can uncomment it in /etc/sysctl.conf and reboot:

rpi ~$ grep -B 1 'ipv4.ip_forward' /etc/sysctl.conf
# Uncomment the next line to enable packet forwarding for IPv4

Or with systemd-networkd you can add IPForward=yes to the [Network] section in your /etc/systemd/network/eth0.network file.

Then you have to set a static route in your internet router so it can find the route over the raspi to your pc. On most internet router you can set a static route but how to do that varies from model to model. It's up to you to find it out. On a Raspberry Pi it would look like this (don't set it on your Raspi router!)

rpi ~$ sudo ip route add via dev wlanX

That means for the internet router: "send all packets belonging to subnet (destination network) to the next router on my subnet, your raspi-router (gateway). It knows where to go on."

For troubleshooting and reference you can look at Using the Raspberry Pi as a Router.

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.