Introduction

Okay, imagine you only have a network cable plugged in your desktop PC (which we'll call "eth0") and a wireless card too (which we'll call "wireless0"). Now suppose you have your laptop (or any other computer) and you have no way to connect it to the internet - but wait! you have a wireless in your desktop PC and your laptop does too, so we will share your internet connection for your laptop through your wireless card. Come aboard!

Remember, your machine may vary so be sure to use the commands shown in the "The basics" section right below.

Note: this guide has been tested for sharing connection between :

Ubuntu Feisty Fawn (7.04)

and

Windows XP Professional

Please add successfull configurations

ICS2.jpeg

Note: This diagram was created with inkscape. If you want to edit it download the full file ics.svg from: More Actions->Attachments

The Basics

For getting your wireless card info, open a terminal and use these commands:

lsusb     (lists all the connected USB devices)
iwconfig  (lists all the detected wireless hardware)
iwlist    (allows you to scan the wireless networks around you)
ip addr   (lists all the detected network hardware. You can get some info for your wireless here too)

Packages

  • You also need Firestarter, which is just a GTK frontend for the iptables and will allow your internet connection to be shared. You can use Add/Remove Applications or the Synaptic package manager to get it (search for firestarter) or just issue a command in any open terminal window:

sudo apt-get install firestarter

Configuring the SERVER

Here we'll configure who is going to share the Internet connection (our desktop PC with the two cards installed). First, we need to have some concepts and rules in mind:

  1. Computers must be in the same subnet (see below for explanations)
  2. You might not be able to use the Gnome Network Manager (and/or maybe KDE WiFi Manager) using this method.

  3. The Server's wireless0 has to be in a range of 192.168.x.2 and 192.168.x.24. Why? our computer is usually using 192.168.0.1 unless you're on a big network, 192.168.0.0 can't be used for it and ranges higher than 24 in the last number are only allowed for Wireless networking,(1.reference please) or so I've read.

  4. Your wireless card must have the lowest IP possible,(2.reference please) that's why we're using 192.168.0.2 because it's closest to 1 and 0 which are in use and we can't use it, so 2 is free. Client computers ALWAYS MUST have greater IP addresses than the chosen one for the wireless adapter (3.reference please)(or the one sharing the internet).

If you haven't yet, it's time to stop the Network Manager:

sudo /etc/dbus-1/event.d/25NetworkManager stop

Once stopped, we shall proceed to edit our /etc/network/interfaces file.

sudo gedit /etc/network/interfaces

Network Interfaces configuration -IMPORTANT-

Your network configuration file will look similar to this one:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet dhcp

auto eth2
iface eth2 inet dhcp

auto ath0
iface ath0 inet dhcp

auto wlan0
iface wlan0 inet dhcp

For the sake of this example, we only have two network cards, so I'm gonna simplify the example by removing the interfaces we won't use from the file. You can happily do your modifications without deleting them.

We need to think how we'll set up our network. We'll do it this way:

  • IP Address for wireless0: 192.168.0.2 (its own IP address we can define manually).
  • Gateway for wireless0: 192.168.0.1 (where does the internet come from? us, of course. 192.168.0.1 will always be your own computer in most of the cases).
  • Network Mask for wireless0: 255.255.255.0 (Always needed and standard value 99.9% of the time).

Note: You might need to think up another IP address for it if you're on a large network. Else, just leave it like that.

For sharing internet through the wireless with those settings, our interfaces file will end up like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto wireless0
iface wireless0 inet static
         wireless-key 1234567890
         wireless-channel 6
         wireless-mode ad-hoc
         wireless-essid 'Wireless Connection'
         address 192.168.0.2
         gateway 192.168.0.1
         netmask 255.255.255.0

Note: Remember to replace wireless0 with your network adapter's name, which you can get by typing in a terminal:

iwconfig

Okay. Now, we're doing the following things:

  • Setting wireless0 to load automatically.
  • Specify a static configuration instead of being assigned by DHCP (which we won't be able to do).
  • We'll set an hexadecimal WEP key for safety (WPA is not supported at this stage).
  • Also, a channel where to send the information through. Remember Wireless is very similar to radio/tv communications.
  • Specify that we're going be in an ad-hoc network (peer-to-peer or mesh).
  • We'll put a name for it, which we'll use to identify it in Windows, and to identify ourselves in our location.
  • We'll set it's address, gateway and netmask as we decided earlier.

That done, we can restart networking to get the device ready:

sudo /etc/init.d/networking restart

After that, we'll fire up Firestarter:

gksudo firestarter

A wizard should appear. Follow through these steps:

  1. Press Next.
  2. Choose eth0 (or your Ethernet device's name) as the Internet device. If your IP configuration is assigned by DHCP, check/uncheck the corresponding box according to your situation.
  3. Choose wireless0 (or your wireless device's name) as the device which will share Internet. Check the box that says to share Internet.
  4. Do NOT activate the option to enable DHCP in the Local Network.

  5. Press Save.

If everything went good, it should say Firewall Started. If not, please refer to the Troubleshooting section, else, we're done here.

Configuring the CLIENTS

This is relatively easy. When you have your wireless card working (it should blink its led lights, or at least turn on) and you've set up the server correctly, all you have to do is this:

  1. Make sure your other computer has wireless enabled and working.

  2. Go to the Wireless Connections panel and scan for nearby networks. Yours should appear soon. If not, then something's wrong with your server computer or the connection itself. Refer to the Troubleshooting section for details.

  3. Double-click your connection and type your password in. Wait for it to connect.

  4. Go to Control Panel -> Network Connections and right-click your wireless connection, then click Properties.

  5. Click TCP/IP Internet Protocol (or similar) and click the Properties button.

  6. Click the Assign an IP Address Manually radio button (or similar).

  7. We'll need to put the following data:
    • IP Address: 192.168.0.10
    • Gateway: 192.168.0.1
    • Network Mask: 255.255.255.0
  8. Set the DNS addresses to the same ones that your desktop PC has. You can check that by typing on the terminal on the Server/Desktop computer (use the IP addresses after "nameserver"):

cat /etc/resolv.conf
  1. Click Ok, then Ok again to apply changes.

  2. Right-click the small icon on the bottom-right corner of the screen (system tray) which looks like a small monitor with some green curves next to it representing radio signals. Then click Repair.

  3. Pat yourself on the back for your hard work and make yourself a sandwich Smile :)

Your laptop should have Internet now. If anything went wrong, check the Troubleshooting section, as always.

Troubleshooting

See related page on Ad hoc networking.

Authors

Big thanks to

  • theone (IRC channel)
  • astro76 (IRC channel)
  • P3L|C4N0 (Spanish IRC channel)

References

  • 1.
  • 2.
  • 3.

See also

WifiDocs/ShareEthernetConnectionThroughWireless (last edited 2011-07-07 06:49:01 by 1)