个人工具

“UbuntuHelp:EasyWirelessToWiredConnectionSharing”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{From|https://help.ubuntu.com/community/EasyWirelessToWiredConnectionSharing}} {{Languages|UbuntuHelp:EasyWirelessToWiredConnectionSharing}} == What is this all about, man? == Got a wire...)
 
 
(未显示同一用户的2个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/EasyWirelessToWiredConnectionSharing}}
 
{{From|https://help.ubuntu.com/community/EasyWirelessToWiredConnectionSharing}}
 
{{Languages|UbuntuHelp:EasyWirelessToWiredConnectionSharing}}
 
{{Languages|UbuntuHelp:EasyWirelessToWiredConnectionSharing}}
== What is this all about, man? ==
+
<<Include(Tag/StyleCleanup)>>
Got a wireless connection, but a second computer without a wireless adapter?  Of course the easiest solution is to purchase a wireless adapter for it, but not all of us have that option. This guide is a short howto on sharing that wireless connection via router, switch, or hub to the wired machine.
+
<<Include(Tag/ContentCleanup)>>
 
+
== Introduction ==
Revision One
+
To share wireless connection via router, switch, or hub to the wired machine from a machine with a wireless connection.
----
+
The simplest solution to sharing that wireless connection is to purchase a wireless adaptor for the second computer, but sometimes that is not an option.
It would appear that I overlooked a couple of details.  The first being that you can also use a crossover cable from Sys1 - > Sys2, and cut out the entire switch/router/hub element.
+
'''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/hub element.
Secondly, I made only one mention of checking your interface names, and from that point on (and before) assumed only the most generic interface names.  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 this howto, check ifconfig.)
+
* 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 ifconfig.)
 
+
 
The most common interface device names are: eth0, eth1, ath0, ath1, wlan0,wlan1,ppp0,ppp1.
 
The most common interface device names are: eth0, eth1, ath0, ath1, wlan0,wlan1,ppp0,ppp1.
 
I apologize for any confusion this may have caused.
 
 
----
 
----
 
+
'''''Firestarter is no longer recommended for configuring IPtables. UFW is now the recommended program.''''' Please note that the application "firestarter" (from the ''Universe'' package repository) also can set up Internet connection sharing, with a pretty easy-to-use graphical user interface.  
Please note that the application "firestarter" (from the ''Universe'' package repository) also can set up internet connection sharing, with a pretty easy-to-use graphical user interface.
+
=== Setup ===
 
+
=== The Meat 'n Potatoes ===
+
 
+
 
Firstly, you will need the following:
 
Firstly, you will need the following:
 +
* Desktop or Laptop system with both wireless and Ethernet adaptors. (Which we will call '''Wireless-PC''')
 +
* Ethernet adaptor for the second system. (Which we will call '''Wired-PC''')
 +
* A Switch, Hub, or Router. (Which we will call '''Share-Device''')
 +
* Two lengths of Ethernet Cable, long enough to connect '''Wireless-PC'''->'''Share-Device'''-'''Wired-PC'''
 +
* The program '''dhcpd''' should be installed for these steps to work. If it isn't, please go to Applications->Accessories->Terminal and type:
 +
<pre><nowiki>
 +
sudo apt-get install dhcpd
 +
</nowiki></pre>
 +
=== Section One: The Basic Setup ===
 +
Now that  all the necessary equipment has been assembled, it's time to get the easy part over with now.
 +
<ol><li>Connect the Ethernet Cables to '''Wireless-PC''', and '''Wired-PC'''
 +
</li><li>Connect their opposite ends to '''Share-Device'''
 +
</li><li>Power up all devices involved.</li></ol>
  
* Desktop or Laptop system with both wireless and ethernet adapters. (Which we will call "Sys1")
+
=== Section Two: Configuring the Setup ===
 
+
* Ethernet adapter for the second system. (Which we will call "Sys2")
+
 
+
* A Switch, Hub, or Router. (Which we will call "ShareDevice", for simplicity's sake.)
+
 
+
* Two lengths of Ethernet Cable, long enough to connect Sys1->ShareDevice-Sys2.
+
 
+
* dhcpd package. (sudo apt-get install dhcpd)
+
 
+
 
+
==== Initial Setup ====
+
 
+
Now that you've assembled all the necessary equipment for our little adventure, it's time to get the easy part over with now.
+
 
+
1) Connect the Ethernet Cables to Sys1, and Sys2.
+
2) Connect their opposite ends to ShareDevice.
+
3) Turn on/Power up all devices involved.
+
 
+
===== The Down 'n Dirty =====
+
 
+
 
Now that we've got all that out of the way, it's time to begin our journey.
 
Now that we've got all that out of the way, it's time to begin our journey.
 +
<ol><li>Double-check all physical connections between '''Wireless-PC''', '''Share-Device''' and '''Wired-PC'''.
 +
</li><li>Make a backup of your dhcpd.conf</li></ol>
  
1) Check that you have dhcpd installed.
+
<pre><nowiki>
 
+
sudo cp /etc/dhcpd.conf /etc/dhcpd.conf.backup
* sudo apt-get install dhcpd
+
</nowiki></pre>
 
+
<ol><li>Use your favorite text editor to open /etc/dhcpd.conf, In this example, we'll use GEdit.</li></ol>
2) Double-check all physical connections between Sys1, ShareDevice, and Sys2.
+
 
+
3) Make a backup of your dhcpd.conf
+
 
+
* sudo cp /etc/dhcpd.conf /etc/dhcpd.conf.backup
+
 
+
4) Use your favorite text editor to open /etc/dhcpd.conf, In this example, we'll use GEdit.
+
 
+
* gksudo gedit /etc/dhcpd.conf (don't use sudo with graphical apps -cpk1)
+
  
 +
<pre><nowiki>
 +
gksudo gedit /etc/dhcpd.conf
 +
</nowiki></pre>
 +
'''Warning'''
 +
Remember, don't use sudo with GUI applications!
 
* Add the following (It is safe, at this point, to remove everything in the configuration.):
 
* Add the following (It is safe, at this point, to remove everything in the configuration.):
 
<pre><nowiki>
 
<pre><nowiki>
第66行: 第51行:
  
 
subnet 192.168.27.0 netmask 255.255.255.0 {
 
subnet 192.168.27.0 netmask 255.255.255.0 {
range 192.168.27.10 192.168.27.20;
+
  range 192.168.27.10 192.168.27.20;
option broadcast-address 192.168.27.255;
+
  option broadcast-address 192.168.27.255;
option routers 192.168.27.1;
+
  option routers 192.168.27.1;
 
}
 
}
  
 
</nowiki></pre>
 
</nowiki></pre>
 
+
'''Note'''
NOTE: You can change the IP range to whatever you choose, just make sure that you do not cause an IP conflict by assigning the same range as your Wireless Access Device.  Double check this by typing 'ifconfig' and looking at the IP set for your wireless device.  (wlan0, ath0, etc.) Also it will probably be easiest to stick to a class C network (starts with 192.168.) to lower the risk of confusing yourself =).
+
You can change the IP range to whatever you choose, just make sure that you do not cause an IP conflict by assigning the same range as your Wireless Access Device.  Double check this by typing 'ifconfig' and looking at the IP 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) to lower the risk of confusion.
 
+
=== Backing Up ===
5) Backup the following file, just for extra safety..
+
<ol><li>Backup the following file, just for extra safety..</li></ol>
  
 
*sudo cp /etc/default/dhcp /etc/default/dhcp.backup
 
*sudo cp /etc/default/dhcp /etc/default/dhcp.backup
 
+
<ol><li>Edit the file.  Again, in this case we'll use GEdit.</li></ol>
6) Edit the file.  Again, in this case we'll use GEdit.
+
  
 
* gksudo gedit /etc/default/dhcp (don't use sudo with graphical apps -cpk1)
 
* gksudo gedit /etc/default/dhcp (don't use sudo with graphical apps -cpk1)
 
+
<ol><li>In the section "INTERFACES", we will set dhcpd to listen for DHCP requests on your Ethernet interface.</li></ol>
7) In the section "INTERFACES", we will set dhcpd to listen for dhcp requests on your ethernet interface.
+
  
 
* INTERFACES="eth0"
 
* INTERFACES="eth0"
 
 
Save and exit GEdit.
 
Save and exit GEdit.
 
+
<ol><li>Next, we'll modify the priority of your interfaces.  This may not be a necessary step for everyone, but I found that after bringing up eth0, my system attempted to use that as my internet connection, rather than my wireless interface.  Make sure you back up the /etc/network/interfaces file using the steps for backing up outline in previous steps.</li></ol>
8) Next, we'll modify the priority of your interfaces.  This may not be a necessary step for everyone, but I found that after bringing up eth0, my system attempted to use that as my internet connection, rather than my 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/interface (don't use sudo with graphical apps -cpk1)
 
* gksudo gedit /etc/network/interface (don't use sudo with graphical apps -cpk1)
 
+
* In the section <code><nowiki># The primary network interface'</nowiki></code>, add the following:
* In the section '# The primary network interface', add the following:
+
 
<pre><nowiki>
 
<pre><nowiki>
 
iface wlan0 inet dhcp
 
iface wlan0 inet dhcp
第104行: 第84行:
 
pre-up /sbin/iptables-restore /etc/network/iptables
 
pre-up /sbin/iptables-restore /etc/network/iptables
 
</nowiki></pre>
 
</nowiki></pre>
 
 
The pre-up section is necessary.  It's something we'll touch on later, but for now just trust me and add it.
 
The pre-up section is necessary.  It's something we'll touch on later, but for now just trust me and add it.
(Remember to change the IP ranges, and interface device names to reflect those present on your system. Also, don't forget to set the gateway to your Wireless Connection's gateway if you want Sys2 to be able to resolve domains.)
+
(Remember to change the IP ranges, and interface device names to reflect those present on your system. Also, don't forget to set the gateway to your Wireless Connection's gateway if you want '''Wired''' to be able to resolve domains.)
 
+
<ol><li>Drop your wireless and wired connections.</li></ol>
9) Drop your wireless and wired connections.
+
  
 
* ifconfig wlan0 down
 
* ifconfig wlan0 down
 
 
* ifconfig eth0 down
 
* ifconfig eth0 down
 +
<ol><li>Do the following to add the appropriate iptables rule:</li></ol>
  
10) Do the following to add the appropriate iptables rule:
+
<pre><nowiki>
 
+
sudo iptables -t nat -A POSTROUTING -s 192.168.27.0/16 -o wlan0 -j MASQUERADE
*sudo iptables -t nat -A POSTROUTING -s 192.168.27.0/16 -o wlan0 -j MASQUERADE
+
</nowiki></pre>
(NOTE: Due to user error, I can't assure that this is actually the appropriate syntax.  If this doesn't do the trick, let me know.)"sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE" should be all that you need here, since the source should not matter here -cpk1
+
<pre><nowiki>
 
+
sudo iptables-save /etc/network/iptables
* sudo iptables-save /etc/network/iptables   (Told you we'd get to that part.  Now when you bring up eth0, you won't have to set up the iptables rules again.  They'll be auto-set for you each time you bring up eth0.)
+
</nowiki></pre>
 
+
Now when you bring up eth0, you won't have to set up the iptables rules again.  They'll be auto-set for you each time you bring up eth0.
11)  Now, the "Moment of Truth".
+
10. Starting and Testing the Network
 
+
 
* ifconfig eth0 up
 
* ifconfig eth0 up
 
 
* sudo /etc/init.d/networking start
 
* sudo /etc/init.d/networking start
 
 
* sudo /etc/init.d/dhcp start
 
* sudo /etc/init.d/dhcp start
 
 
* ifconfig wlan0 up
 
* ifconfig wlan0 up
 
+
(You can also make a shell script using those commands.  It is suggest that be done since otherwise these commands will have to be retyped after every reboot.)
(You can also make a shell script using those commands.  I suggest that, because otherwise you'll find yourself typing all of those commands every single boot.)
+
On '''Wired-PC''', ping <code><nowiki>ubuntu.com</nowiki></code>. If the ping is successful all is well. You now have a working connection to the Internet.
 
+
=== Troubleshooting ===
12) On Sys2, ping google.com, and cross your fingers. What if ping doesn't work?  On Sys1 ping google to get google's ip and write it down.  Go back to Sys2 and try pinging google by ip. If this works then be happy! You simply have a DNS issue which can easily be fixed by opening /etc/resolv.conf with your favorite editor "gksudo gedit /etc/resolv.conf" and then add in "nameserver 192.168.1.1" (without the quotes and change the ip to whatever your router that Sys1 is getting the internet from).
+
If the ping is unsuccessful:
 
+
On '''Wireless-PC''' ping <code><nowiki>ubuntu.com</nowiki></code> 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:
 
+
<pre><nowiki>
 +
gksudo gedit /etc/resolv.conf
 +
</nowiki></pre>
 +
Then add in "<code><nowiki>nameserver <IP Address></nowiki></code>" (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).
 
----
 
----
====== Credits ======
+
=== TODO ===
Special Thanks to: cpk1 and hexidigital on #ubuntu-offtopic (freenode)
+
* 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.
 +
* TODO: Review that this is actually the appropriate syntax.  "sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE" should be all that you need here, since the source should not matter here -cpk1
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2009年11月17日 (二) 18:57的最新版本

<<Include(Tag/StyleCleanup)>> <<Include(Tag/ContentCleanup)>>

Introduction

To share wireless connection via router, switch, or hub to the wired machine from a machine with a wireless connection. The simplest solution to sharing that wireless connection is to purchase a wireless adaptor 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/hub 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 ifconfig.)

The most common interface device names are: eth0, eth1, ath0, ath1, wlan0,wlan1,ppp0,ppp1.


Firestarter is no longer recommended for configuring IPtables. UFW is now the recommended program. Please note that the application "firestarter" (from the Universe package repository) also can set up Internet connection sharing, with a pretty easy-to-use graphical user interface.

Setup

Firstly, you will need the following:

  • Desktop or Laptop system with both wireless and Ethernet adaptors. (Which we will call Wireless-PC)
  • Ethernet adaptor for the second system. (Which we will call Wired-PC)
  • A Switch, Hub, or Router. (Which we will call Share-Device)
  • Two lengths of Ethernet Cable, long enough to connect Wireless-PC->Share-Device-Wired-PC
  • The program dhcpd should be installed for these steps to work. If it isn't, please go to Applications->Accessories->Terminal and type:
sudo apt-get install dhcpd

Section One: The Basic Setup

Now that all the necessary equipment has been assembled, it's time to get the easy part over with now.

  1. Connect the Ethernet Cables to Wireless-PC, and Wired-PC
  2. Connect their opposite ends to Share-Device
  3. Power up all devices involved.

Section Two: Configuring the Setup

Now that we've got all that out of the way, it's time to begin our journey.

  1. Double-check all physical connections between Wireless-PC, Share-Device and Wired-PC.
  2. Make a backup of your dhcpd.conf
sudo cp /etc/dhcpd.conf /etc/dhcpd.conf.backup
  1. Use your favorite text editor to open /etc/dhcpd.conf, In this example, we'll use GEdit.
gksudo gedit /etc/dhcpd.conf

Warning Remember, don't use sudo with GUI applications!

  • Add the following (It is safe, at this point, to remove everything in the configuration.):
#/etc/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 range to whatever you choose, just make sure that you do not cause an IP conflict by assigning the same range as your Wireless Access Device. Double check this by typing 'ifconfig' and looking at the IP 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) to lower the risk of confusion.

Backing Up

  1. Backup the following file, just for extra safety..
  • sudo cp /etc/default/dhcp /etc/default/dhcp.backup
  1. Edit the file. Again, in this case we'll use GEdit.
  • gksudo gedit /etc/default/dhcp (don't use sudo with graphical apps -cpk1)
  1. In the section "INTERFACES", we will set dhcpd to listen for DHCP requests on your Ethernet interface.
  • INTERFACES="eth0"

Save and exit GEdit.

  1. Next, we'll modify the priority of your interfaces. This may not be a necessary step for everyone, but I found that after bringing up eth0, my system attempted to use that as my internet connection, rather than my 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/interface (don't use sudo with graphical apps -cpk1)
  • 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

The pre-up section is necessary. It's something we'll touch on later, but for now just trust me and add it. (Remember to change the IP ranges, and interface device names to reflect those present on your system. Also, don't forget to set the gateway to your Wireless Connection's gateway if you want Wired to be able to resolve domains.)

  1. Drop your wireless and wired connections.
  • ifconfig wlan0 down
  • ifconfig eth0 down
  1. Do the following to add the appropriate iptables rule:
sudo iptables -t nat -A POSTROUTING -s 192.168.27.0/16 -o wlan0 -j MASQUERADE
sudo iptables-save /etc/network/iptables

Now when you bring up eth0, you won't have to set up the iptables rules again. They'll be auto-set for you each time you bring up eth0. 10. Starting and Testing the Network

  • ifconfig eth0 up
  • sudo /etc/init.d/networking start
  • sudo /etc/init.d/dhcp start
  • ifconfig wlan0 up

(You can also make a shell script using those commands. It is suggest that be done since otherwise these commands will have to be retyped after every reboot.) 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.
  • TODO: Review that this is actually the appropriate syntax. "sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE" should be all that you need here, since the source should not matter here -cpk1