0

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

PC2 [192.168.0.200 dhcp client]
 |
eth0  [192.168.0.123]
PC1   [runns dhcpd on subnet 192.168.0.200-250]
wlan0 [192.168.1.123 dhcp client]
 |
Router with nat [192.168.1.1]
 |
Internetz

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 192.168.1.0/24 and 192.168.0.0/24 are different so do they need to be nat:ed?

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

Anders
  • 13
  • 3

1 Answers1

1

Yes, this can be done. Add a default route via 192.168.0.123 on PC2, and a static route to subnet 192.168.0.0/24 via 192.168.1.123 on each machine on the 192.168.1.0/24 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 192.168.0.0/23 range, if you want PC2 to be able to reach the Internet.

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