Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What's a simplistic recipe to connect my PC to my WLAN through my laptop?

I have one wireless network, one desktop that (for practical reasons) has no connection to the WLAN, and one laptop with wireless and an ethernet port.

I would like to run a cable from my desktop to my laptop, connect my laptop to my WLAN and forward the network to my desktop.

Is there a solution?

share|improve this question
    
What unix variant does your laptop run? The commands will be different on different variants. If it's Linux, specify your distribution: there may be a distribution-specific way that's a lot simpler than the simplest distribution-agnostic way. –  Gilles Sep 6 '10 at 21:52
    
I am running archlinux, but I think more people could benefit from a "distribution-agnostic" answer... –  NixNinja Sep 6 '10 at 22:09
add comment

4 Answers

up vote 4 down vote accepted

Simple and platform agnostic:

  1. Ensure that the two networks to be bridged have different subnet addresses.
  2. Enable standard Linux IP forwarding in /etc/sysctl.conf.

For different subnets, assuming you are using the allocated private class C space, 192.168.1.* and 192.168.2.* are different subnets.

share|improve this answer
add comment

Asuming that:

  • PC1 has a working internet connection which we want to share with PC2.
  • PC1 is connected to PC2 with a cross-over cable or a switch
  • 192.168.0.1 is the IP address we assign to PC1
  • 192.168.0.2 is the IP address we assign to PC2
  • 10.0.0.2 is the IP address for the nameserver used by PC1 ( cat /etc/resolve.conf on PC1 )

ON PC1:

eth0 is the network interface that connects to PC2

# configure eth0
ifconfig eth0 192.168.0.1 netmask 255.255.255.0
ifconfig eth0 up

# enable forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# forward with iptables
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/etc/rc.d/iptables save
/etc/rc.d/iptables start

ON PC2:

eth0 is the interface that connects to PC1

# enable eth0
ifconfig eth0 192.168.0.2 netmask 255.255.255.0
ifconfig eth0 up

# route through other pc
route add default gw 192.168.0.1

# specify nameserver
echo "nameserver 10.0.0.2" >> /etc/resolve.conf

See Internet Share for reference.

share|improve this answer
1  
on PC2, shouldn't the gateway be set to 192.168.0.1? and there is a confusion in the 1st part (both addresses are assigned to PC1) –  gurney alex Aug 15 '11 at 8:28
    
its been fixed, thank you –  NixNinja Aug 17 '11 at 11:17
add comment

Ok, I don't think I really have the answer here but here it goes:

  1. Connect your laptop to the WLAN,
  2. Connect your Desktop to your Laptop (make sure to configure the IP's properly, or have a DHCP server on your laptop),
  3. Use firestarter (should be available on your package manager) to create a bridge between the two connections.

That's as far as I could get by researching the subject; hope this info serves as a good starting point.

share|improve this answer
add comment

You can also connect the laptop to the WLAN, the desktop to Laptop and only bridge the connections on the laptop so you don't need to run anything on the laptop (DHCP/NAT). The Desktop will get its config from the WLAN dhcp.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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