Page 1 of 2 12 LastLast
Results 1 to 10 of 15

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

  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

  2. #2
    Join Date
    Aug 2006
    Beans
    1

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

    Very useful your howto but I have a problem when I restart my computer I can't connect to Internet until I restart the ipmasq service

  3. #3
    Join Date
    Jul 2005
    Location
    Remote Desert, USA
    Beans
    683

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

    If you can afford to have the PC that's sharing the Internet connection to be on a static IP instead of DHCP, and all other systems be on DHCP, then you could implement tinyproxy on it and have all the other workstations proxy through it. The side-effect of the web proxy, besides web content/adware filtering, is that all the Internet connections are funneled out through the system hosting the proxy.

    For me, tinyproxy seems to be the easier route. However, if for some reason you can only implement your sharing host PC as a DHCP client, not a static client, then yes, this technique as specified above as the start of this thread is one workable solution.
    SuperMike
    When in doubt, follow the penguins.
    Evil Kitty is watching you

  4. #4
    Join Date
    Jan 2007
    Beans
    1

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

    Hmm I've got the problem it doesn't work for me :/
    I've got Ubuntu on the PC connected via wired router to the internet and would like to share this connection with a laptop (with WinXP). Made step by step what is written in this howto though it doesn't work.
    During step 6 i encountered message:
    Restarting DNS forwarder and DHCP server: dnsmasqstart-stop-daemon: warning: failed to kill 5495: No such process

    Maybe it's the problem but i don't know how to solve it.

    I'm quite fresh in Linux systems so I would be glad for any help.

  5. #5
    Join Date
    Apr 2005
    Location
    Philladelphia, PA
    Beans
    54
    Distro
    Ubuntu 9.04 Jaunty Jackalope

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

    Thanks for the howto, I'm almost completely up and running!

    I can see and connect to the ad-hoc network provided by my workstation from my laptop using iwconfig (not network manager for some reason), and when I run jnettop on the workstation wireless interface, and ping a WAN address, I can see the laptop's IP. I've gotten to the point where I can ping some websites via IP, and I can ping some, but not all I tried, using their www names, also firefox does not load any pages. I'm assuming this to be some sort of DNS issue.

    My current setup is as follows:

    Wired Router(192.168.0.1) -> [ eth0 (192.168.0.102) - workstation - ra0 (192.168.1.1) ] -> laptop eth1 (192.168.1.1xx)

    Here are some outputs:

    # iwconfig
    ra0 RT61 Wireless ESSID:"*_____*"
    Mode:Ad-Hoc Frequency:2.437 GHz Cell: 0A:17:0B:AB:6D:C3
    Bit Rate=54 Mb/s
    RTS thrff Fragment thrff
    Link Quality=83/100 Signal level:-45 dBm Noise level:-88 dBm
    Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
    Tx excessive retries:0 Invalid misc:0 Missed beacon:0

    # ifconfig
    ra0 Link encap:Ethernet HWaddr 00:0E:2E:5E:7B:9E
    inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
    inet6 addr: fe80::20e:2eff:fe5e:7b9e/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:129327 errors:0 dropped:0 overruns:0 frame:0
    TX packets:5751 errors:437 dropped:437 overruns:0 carrier:0
    collisions:3135 txqueuelen:1000
    RX bytes:12372684 (11.7 MiB) TX bytes:3957 (3.8 KiB)
    Interrupt:50

    # dhcpd.conf
    subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.100 192.168.1.200;
    option domain-name-servers 216.178.92.98;
    # option domain-name "internal.example.org";
    option routers 192.168.1.1;
    option broadcast-address 192.168.1.255;
    default-lease-time 600;
    max-lease-time 7200;
    }
    -> I've tried setting domain-name-servers to both the localhost address, 192.168.1.1, and my ISP's DNS hosts with no luck

    # interfaces
    auto ra0
    iface ra0 inet static
    address 192.168.1.1
    netmask 255.255.255.0
    # wireless-mode ad-hoc
    # wireless-essid *___________*
    # wireless-channel 12
    -> the wireless options are provided in a separate .dat file and loaded at boot

    # route -n
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 ra0
    192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
    0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0

    /var/log/syslog, messages and daemon show no errors regarding the wifi driver, dhcpd, dnsmasq or ipmasq.

    Any suggestions?

    Thanks!

  6. #6
    Join Date
    Jan 2008
    Location
    kl
    Beans
    7
    Distro
    Ubuntu 7.10 Gutsy Gibbon

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

    how to encryption my wireless network?

    " You can also add encryption to this - see "man interfaces" for more details."

    i did'not get it.

  7. #7
    Join Date
    Oct 2007
    Beans
    21

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

    Ok well that didn't do anything. Now I am left with non functioning wireless. I can still connect to an access point, it seems to be issuing IPs but no connectivity. Hmm....maybe I'll just reload Ubuntu or upgrade to the 8.04 beta. Wireless sucks anyways!

  8. #8
    Join Date
    Apr 2008
    Beans
    2
    Distro
    Ubuntu 7.10 Gutsy Gibbon

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

    If things are still not working for you, you may want to try this tutorial. Also some might find it easier to use Webmin instead of the terminal.

    Combining this HOWTO and the above tutorial, I have 90% of internet connection sharing working. I just need to figure out why some sites load and others take forever.

  9. #9
    Join Date
    Apr 2008
    Beans
    490
    Distro
    Ubuntu 12.04 Precise Pangolin

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

    Great HowTo. It deserves a bump.
    |

  10. #10
    Join Date
    Jun 2005
    Beans
    85

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

    Quote Originally Posted by spikoley View Post
    Great HowTo. It deserves a bump.
    No longer current. As of Intrepid, Network Manager 0.7 provides much of this functionality, and is much easier to set up. See here for details:

    http://ubuntu-tutorials.com/2009/06/...et-connection/

Page 1 of 2 12 LastLast

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
  •