I think I undestand the problem...
I assume you have a wired NIC in your desktop, right? and you have both wired NIC and wireless NIC in your laptop.
I have a similar situation at home, just that the wireless router I'm using is at MY home and I can just plug a network cable for my desktop and be connected to the internet without needing my laptop.
The problem is if you're using someone else's nearby wireless and you can't just connect a cable to your desktop NIC. Is this your situation?
Anyway, in order to make it happen you'll have to turn your laptop linux into a router which performs NAT between your desktop and your wireless network. I guess the router also performs NAT so your desktop will be behind NAT twice, it works, but sometimes it can lead you to some weird problems...
So, here's how you can make it happen, please pay attention and adapt everything to your PC where needed, OK? We'll use iptables and linux ip forwarding capabilities.
1. Make sure you have iptables installed
- Code: Select all
which iptables
/sbin/iptables
If not, install it
- Code: Select all
sudo apt-get install iptables
2. Edit the file /etc/sysctl.conf
- Code: Select all
sudo gedit /etc/sysctl.conf
and uncomment (remove the "#" from the beginning of the line) this line (in my case is line number 38)
before
- Code: Select all
#net.ipv4.ip_forward=1
after
- Code: Select all
net.ipv4.ip_forward=1
Save and close the file.
3. Now we need to make sure we start on a clean iptables configuration, so let's clean it up
- Code: Select all
sudo iptables -F
sudo iptables -t nat -F
sudo iptables -t mangle -F
4. Now let's configure the network. I assume your network interfaces are wlan0 for your wireless internet and eth0 for your wired network (keep in mind you may need a cross connection cable) So please change if needed, to suit your setup. The IP address I chose is also an example, though it will work if you set it exactly like this.
Edit /etc/network/interfaces and add the needed settings for eth0
- Code: Select all
sudo gedit /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0
Save exit and restart the networking
- Code: Select all
sudo /etc/init.d/networking restart
5. Now we need to set up the iptables NAT and forwarding and save its configuration, for this "sudo" isn't enough, so we need to be root, be careful here!
- Code: Select all
sudo -s
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i eth0 -j ACCEPT
iptables-save > -c /etc/iptables.rules
exit
6. In order to make it persistent after reboot, we need to edit again the file /etc/network/interfaces but this time you'll need to add the following line to the end of your "wlan0" section
- Code: Select all
sudo gedit /etc/network/interfaces
auto wlan0 inet dhcp
...
...
post-up iptables-restore < /etc/iptables.rules
Save, exit, and now you can reboot your Laptop and see if all comes up nicely.
If you get by mistake locked down by iptables, the command "sudo iptables -F" will clean it all up for you.
From now on, any computer you connect to the wired NIC of your Laptop will be able to surf through it as long as you set them the networking properly, any IP you set on the Desktop from 192.168.0.2 and up to 192.168.0.255 with a default gateway 192.160.0.1 will be able to surf the internet.
Oh, almost forgotten, you should set DNS servers to your desktop too, you can get them from your Laptop settings.
I hope this helps and is not too complicated.
And remember what the 11th commandment says:
"Thou shalt not covet thy neighbours WiFi..."
Ziv