1

My setup is Modem -> Linksys router -> Laptop with 2 devices (wlan0/eth0) -> desktop machine

Router is 192.168.1.1 gateway to the internet Laptop wlan0 is 192.168.1.4 with a gw of 192.168.1.1 Laptop eth0 is 192.168.2.254 which acts as a second gateway desktop is 192.168.2.100

On laptop i've setup ip_forward to 1, and have inserted 2 iptables rules

-A FORWARD -i eth0 -o wlan0 -j ACCEPT 
-A FORWARD -i wlan0 -o eth0 -j ACCEPT

The laptop can ping outside the network (i,e, yahoo.com) it can not ping 192.168.2.100. The desktop can ping 192.168.2.254 but nothing outside the network or 192.168.1.0 subnet.

On laptop ip route show lists:

192.168.2.0/24 dev eth0  proto kernel  scope link  src 192.168.2.254 
192.168.1.0/24 dev wlan0  proto kernel  scope link  src 192.168.1.4 
127.0.0.0/8 dev lo  scope link 
default via 192.168.1.1 dev wlan0 

What am I missing to make my desktop go through the laptop in order to access the router which provides access to the internet?

Thanks

3 Answers 3

1

You could use bridging if you just want to pass on traffic transparently on your laptop. That way, the linksys would assign IP to your desktop, and your desktop would only be routed once in order to access internet.

Still, you would be able to filter data on your laptop with iptables, if that is what you want.

http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge

5
  • This is a good idea too, didn't even think of this.
    – McJeff
    Jun 14, 2010 at 15:05
  • I've setup the bridge per the documentation and the laptop can ping outside network, and desktop machine @ 192.168.1.123, desktop machine can ping laptop 192.168.1.4 however it can not ping gateway at 192.168.1.1. all iptables rules are cleared, routing table is reset to only show 192.168.1.0/24 to be sent to 192.168.1.1, ip_forward is still enabled so not sure what else im missing
    – SimmaDoWN
    Jun 14, 2010 at 16:16
  • also remember im using wireless which is the 192.168.1.4 device so not sure if i need to do anything there
    – SimmaDoWN
    Jun 14, 2010 at 16:22
  • I have a feeling my wireless is the reason why I am unable to move packets out/in. bridging does seem like the simplest solution but i need a workaround for this wireless adapter
    – SimmaDoWN
    Jun 14, 2010 at 17:49
  • iptables should be default allow all, but 192.168.1.0/24 shouldn't point to the gw address, since it's the local net. It should say * as gateway.
    – jishi
    Jun 17, 2010 at 12:06
0

The laptop which is directly connected to the desktop cannot ping the desktop, but your desktop can ping your laptop? So, in other words, A->B works but B->A doesn't?

You probably also need to setup some sort of SNAT or masquerading. My gut feeling is that the packet is getting forwarded to the router with a source of 192.168.2.100, but the router doesn't know what to do with it because it's only directly connected to 192.168.1.0/24. Maybe a static route on your router that forces all 192.168.2.0/24 traffic through the laptop.

5
  • See tldp.org/HOWTO/IP-Masquerade-HOWTO/firewall-examples.html. Not only is the intermediate machine forwarding packets, it's also mangling the source so it looks as though the traffic originates from the routing machine.
    – McJeff
    Jun 14, 2010 at 13:28
  • Im able to ping 192.168.1.0/24 and 192.168.2.0/24 from laptop, however, desktop can not ping 192.168.1.0/24. I'll attempt at setting up a static route on the router which I'm assuming you mean the linksys router and not the laptop? And if im setting up a static route do I still look into masquerading the traffic coming from the laptop eth0(192.168.2.0/24)?
    – SimmaDoWN
    Jun 14, 2010 at 13:34
  • Yeah, on the Linksys itself 192.168.2.0/24 via laptop. If that doesn't work, check into MASQ & might also TCP dump your laptop to see if the packets are actually forwarded through.
    – McJeff
    Jun 14, 2010 at 13:59
  • So ive setup masquerading and tcpdump shows ping responses to be setup at 192.168.1.4 even when it comes from dekstop(192.168.2.100) I had to add another route ip route add 192.168.1.0/24 dev eth0 this allows desktop to access both subnets.. however still can not access outside of network
    – SimmaDoWN
    Jun 14, 2010 at 14:14
  • What's the default GW on the desktop? (I'm actually having a bit of fun with this ;-)
    – McJeff
    Jun 14, 2010 at 14:36
0

So, basically you are using the wireless on the laptop to connect to the router/internet, and want to "share" the connection with the desktop. This is exactly what "bridging" is for, as jishi pointed out.

If you prefer the separate subnets, then you need to make iptables do Network Address Translation (NAT). Iptables can do it .. here is a tutorial. Before starting, make sure that the laptop can do everything you need on the internet.

However, unless this is intended as a learning exercise, I recommend that you buy a wireless adapter for the desktop machine. They aren't expensive and are simple to install (particularly the USB ones).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .