Results 1 to 10 of 15

Thread: HOWTO: Share internet connection over wireless network with DHCP

Threaded View

  1. #1
    Join Date
    Apr 2006
    Beans
    30

    HOWTO: Share internet connection over wireless network with DHCP

    This HOWTO is based on this forum post, but also explains how to set up internet connection sharing with wireless and DHCP.

    Say you want to use your desktop as a router, so that the topology looks something like this:

    internet -> [eth0 - desktop - wlan0] -> laptop

    with the laptop being assigned a dynamic IP address. To do this (replace eth0 and wlan0 appropriately for your setup - eth0 is the connection to the internet, and wlan0 is the wireless for your LAN):

    1. First, install the packages dnsmasq, ipmasq, and dhcp3-server, either with Synaptic or with the following command line:
      Code:
      sudo apt-get install dnsmasq ipmasq dhcp3-server
      This may warn you that dhcp3-server could not be started - as we haven't edited the configuration yet, this is normal .
    2. Assign a static IP address for the wireless card on the desktop machine by editing the file /etc/network/interfaces. Add these lines to the end of the file (if you already see wlan0 somewhere else, delete that first):
      Code:
      auto wlan0
      iface wlan0 inet static
           address 192.168.0.1
           netmask 255.255.255.0
           broadcast 192.168.0.255
           wireless-mode ad-hoc
           wireless-essid YOUR-NETWORK-SSID-HERE
      You can also add encryption to this - see "man interfaces" for more details.
    3. Edit the file /etc/default/dhcp3-server by finding the line with INTERFACES="" and replacing it with
      Code:
      INTERFACES="wlan0"
      This tells the DHCP server to listen on the local network for connections.
    4. Open the file /etc/dhcp3/dhcpd.conf. Find the following lines:
      Code:
      option domain-name "example.org";
      option domain-name-servers ns1.example.org, ns2.example.org;
      
      default-lease-time 600;
      max-lease-time 7200;
      and replace them with:
      Code:
      #option domain-name "example.org";
      #option domain-name-servers ns1.example.org, ns2.example.org;
      
      #default-lease-time 600;
      #max-lease-time 7200;
      by adding a pound sign to the beginning of the lines. Then paste this at the end of the file:
      Code:
      subnet 192.168.0.0 netmask 255.255.255.0 {
        range 192.168.0.100 192.168.0.200;
        option domain-name-servers 192.168.0.1;
      #  option domain-name "internal.example.org";
        option routers 192.168.0.1;
        option broadcast-address 192.168.0.255;
        default-lease-time 600;
        max-lease-time 7200;
      }
    5. Set up IP masquerading and forwarding:
      Code:
      sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
      sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
      sudo dpkg-reconfigure ipmasq
      The default answers should be fine.
    6. Set up DNS masquerading:
      Code:
      sudo dpkg-reconfigure dnsmasq
    7. Start everything up!
      Code:
      sudo ifdown wlan0
      sudo ifup wlan0
      sudo /etc/init.d/dnsmasq restart
      sudo /etc/init.d/dhcp3-server restart


    If everything went well, you should now be able to get internet from a laptop just by connecting to this network!

    Note: If the settings aren't saved after a reboot, try this:
    Code:
    sudo sh -c "echo \"net.ipv4.ip_forward = 1\" >> /etc/sysctl.conf"
    Hope you enjoyed, post any problems and questions here
    Last edited by sciyoshi; March 12th, 2007 at 03:25 PM. Reason: Small change so that things work after reboot - thanks Spack971

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •