What is the easiest way to give PC2 access to the Internet through PC1 in the setup below:

PC2 [ dhcp client]
eth0  []
PC1   [runns dhcpd on subnet]
wlan0 [ dhcp client]
Router with nat []

Background: PC2 is a headless computer with no wifi running a dhcp client. PC1 is my regular laptop connecting through wifi to a cable modem. I would like to configure PC2 (eg. sshing in to it and pull stuff from the Internet) using PC1.

Since it's a wifi and an eth0 they can't be bridged using brctl.

I found this "Bridging wlan0 to eth0" method of doing it with iptables, where iptables is used to do nat on PC1. But is it necessary? The and are different so do they need to be nat:ed?

Is it possible to use route somehow on PC1 to route between the subnets?


Yes, this can be done. Add a default route via on PC2, and a static route to subnet via on each machine on the subnet that should be able to talk to PC2. How to make these routes persistent is dependent on the OS and distribution.

You will also have to make sure PC1 forwards packets; on Linux: sysctl -w net.ipv4.ip_forward=1. Also make sure you NAT the whole range, if you want PC2 to be able to reach the Internet.

  • Still no luck. Updated question with more info after trying to do what you suggested. Perhaps I didn't understand your advice. – Anders Jan 5 '17 at 22:26
  • Works! Had to use iptables -t nat -A POSTROUTING -j SNAT --to-source since -j MASQUERADE didn't work (used wrong source IP in nat). – Anders Jan 5 '17 at 22:52

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