个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
第38行: 第38行:
 
default-lease-time 600;
 
default-lease-time 600;
 
max-lease-time 7200;
 
max-lease-time 7200;
 +
 
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: 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 =).
 
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 =).
第58行: 第60行:
 
iface wlan0 inet dhcp
 
iface wlan0 inet dhcp
 
wireless-essid default
 
wireless-essid default
 +
 
iface eth0 inet static
 
iface eth0 inet static
 
address 192.168.27.1
 
address 192.168.27.1

2007年12月6日 (四) 10:12的版本

What is this all about, man?

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. Revision One


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. 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.) The most common interface device names are: eth0, eth1, ath0, ath1, wlan0,wlan1,ppp0,ppp1. I apologize for any confusion this may have caused.


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.

The Meat 'n Potatoes

Firstly, you will need the following:

  • Desktop or Laptop system with both wireless and ethernet adapters. (Which we will call "Sys1")
  • 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. 1) Check that you have dhcpd installed.

  • sudo apt-get install dhcpd

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)
  • 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 (starts with 192.168.) to lower the risk of confusing yourself =). 5) Backup the following file, just for extra safety..

  • sudo cp /etc/default/dhcp /etc/default/dhcp.backup

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)

7) In the section "INTERFACES", we will set dhcpd to listen for dhcp requests on your ethernet interface.

  • INTERFACES="eth0"

Save and exit GEdit. 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)
  • 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 Sys2 to be able to resolve domains.) 9) Drop your wireless and wired connections.

  • ifconfig wlan0 down
  • ifconfig eth0 down

10) 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

(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

  • 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.)

11) Now, the "Moment of Truth".

  • 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. I suggest that, because otherwise you'll find yourself typing all of those commands every single boot.) 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).


Credits

Special Thanks to: cpk1 and hexidigital on #ubuntu-offtopic (freenode)