|
Style Cleanup Required |
|
Duplicate Article |
Introduction
To share wireless connection via router or switch to the wired machine from a machine with a wireless connection.
The simplest solution to sharing that wireless connection is to purchase a wireless adapter for the second computer, but sometimes that is not an option.
Note
- An alternate solution is to use a crossover cable from the wireless system to the wired one, thus cutting out the entire switch/router element.
To be sure of which interfaces you need to configure, first try the networking tools provided by Gnome or KDE. (Alternately, when your interfaces are up and running, before you proceed with these instructions, check ip addr.)
The most common interface names used in linux are: eth0, eth1, ath0, ath1, wlan0, wlan1, ppp0, ppp1, etc.
Please note that the application "firestarter" (from the Universe repository) also can set up Internet connection sharing, with a pretty easy-to-use graphical user interface. .
Requirements
First, you will need the following:
Desktop or Laptop system with both wireless and Ethernet adapters. (Which we will call Wireless-PC)
Ethernet adapter for the second system. (Which we will call Wired-PC)
A Switch or Router. (Which we will call Share-Device)
Two lengths of Ethernet Cable, long enough to connect Wireless-PC->Share-Device->Wired-PC
The package dhcp3-server must be installed for these steps to work. If it is not installed, please go to Applications->Accessories->Terminal and type:
sudo apt-get install dhcp3-server
Section One: The Basic Setup
Now that all the necessary equipment has been assembled, it is time to get the easy part over with now.
Connect the ethernet cable from Wireless-PC, to Wired-PC
Connect their opposite ends to Share-Device
- Power up all devices involved.
Section Two: Configuring our network
Double-check all physical connections between Wireless-PC, Share-Device and Wired-PC.
- Make a backup of your dhcpd.conf
sudo cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.backup
- Use your favorite text editor to open /etc/dhcp3/dhcpd.conf, In this example, we will use Gedit.
NOTE: We use gksudo when we need to use sudo with a graphical application such as gedit.
gksudo gedit /etc/dhcp3/dhcpd.conf
- Add the following so that it looks like this:
#/etc/dhcp3/dhcpd.conf option subnet-mask 255.255.255.0; default-lease-time 600; max-lease-time 7200; subnet 192.168.27.0 netmask 255.255.255.0 { range 192.168.27.10 192.168.27.20; option broadcast-address 192.168.27.255; option routers 192.168.27.1; }
Note
You can change the IP address range to whatever you choose, just make sure that you do not cause an IP address conflict by assigning the same range as your Wireless Access Device. Double check this by typing <tt>ip addr</tt> and look at the IP address set for your wireless device. (wlan0, ath0, etc.) Also, it will probably be easiest to stick to a class C network (e.g. 192.168.x.0/24) to lower the risk of confusion. If you change it, make sure that whatever you change '27' to is reflected everywhere '27' is used in this guide.
Backing Up
- We will backup the dhcp3-server file just for extra safety..
- sudo cp /etc/default/dhcp3-server /etc/default/dhcp3-server.backup
- Edit the file. Again, in this case we will use Gedit.
- gksudo gedit /etc/default/dhcp3-server
- In the section "INTERFACES", we will set dhcp3-server to listen for DHCP requests on your Ethernet interface.
- INTERFACES="eth0"
Save and exit Gedit.
- Next, we will modify the priority of your interfaces. This may not be a necessary step for everyone, but some people find that after bringing up eth0, the system attempts to use that as the Internet connection, rather than the wireless interface. Make sure you back up the /etc/network/interfaces file using the steps for backing up outline in previous steps.
- gksudo gedit /etc/network/interfaces
In the section # The primary network interface', add the following:
iface wlan0 inet dhcp wireless-essid default iface eth0 inet static address 192.168.27.1 netmask 255.255.255.0 gateway 192.168.0.100 pre-up /sbin/iptables-restore /etc/network/iptables
Note
The pre-up section is necessary will be touched on later in the tutorial. Remember to change the IP address ranges, and interface device names to reflect those present on your system. Also, do not forget to set the gateway to your Wireless Connection's gateway if you want Wired to be able to resolve domains.
Wireless-PC's ip address on eth0 (192.168.27.1 here, see the configuration of eth0 above) can be set to something different, but still on the same subnet (and not conflicting with the DHCP range) by you. Make sure that 'gateway' is correct; it will be the address of the next router up in your network, usually the household or building router. If your Wireless-PC is connected via DHCP, check the gateway that it has on its connection (after association/dhcp to your access point) and use it for eth0 also.
- Drop your wireless and wired connections.
- ip link set wlan0 down
- ip link set eth0 down
STOP: If you are not using iptables then there is no need to edit anything that follows pertaining to iptables.
- Do the following to add the appropriate iptables rule:
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables-save | sudo tee /etc/network/iptables
- Now when you bring up eth0, you will not have to set up the iptables rules again. They will be auto-set for you each time you bring up eth0.
- Starting and Testing the Network
- ip link set eth0 up
- sudo /etc/init.d/networking restart
- sudo /etc/init.d/dhcp start
- ip link set wlan0 up
(You can also make a shell script using those commands. It is suggested that this be done, since otherwise these commands may have to be retyped after every reboot. Another option is to add "auto wlan0" before the wlan0 configuration in /etc/network/interfaces as well as "auto eth0" just above the eth0 configuration)
On Wired-PC, ping ubuntu.com. If the ping is successful all is well. You now have a working connection to the Internet.
Troubleshooting
If the ping is unsuccessful:
On Wireless-PC ping ubuntu.com to get the site's IP address and write it down. Go back to Wired-PC and try pinging google with the IP address. If this works, then you simply have a DNS issue which can easily be fixed. Open /etc/resolv.conf with your favourite editor (for this example we will use gedit) and type the following command:
gksudo gedit /etc/resolv.conf
Then add in "nameserver <IP Address>" (without the angle brackets or the double quotes and change the IP address to whatever your router that Wireless-PC is getting the Internet from).
TODO
- TODO: there is only one mention of checking for interface names, the rest of the article only makes the most generic references to interface names. it could get confusing