Internet Connection Sharing on Ubuntu & Windows with Ad-hoc 2.

A few months ago I made a quick tutorial about Internet Connection Sharing focusing to the case when we are sharing the connection from a machine with Windows installed to the other PC with Linux operating system. In this guide I’ll show you the contrary case, how to share your incoming connection with Linux.

First of all, make sure that you have installed the appropriate drivers for your network interfaces.

Let’s get started with my configuration: I have 2 laptops, one with Ubuntu 10.04 (Laptop 1) and the other with Windows XP (Laptop 2) installed. Both have 2 networking interfaces, Wireless and Ethernet – in the rest of the text just wlan and eth.

We need to share the incoming Internet connection from Ubuntu machine. This laptop is connecting with its network card to the modem with automatic IP address (through DHCP).
I’ll connect my laptops through Wireless. Here is the configuration for the first wireless card (wlan0) on the laptop which is directly connected to the modem:
Create a new Wireless connection, name it and set the mode to Ad-hoc.

Under the tab IPv4 Settings set the following parameters:

Gateway: Leave empty or set to the IP of your Ethernet card on this machine.

Type the following command in root terminal, do not use sudo:
First, configure the laptop for NAT-ing with the following command:
# iptables -t nat -A POSTROUTING -o ethN -j MASQUERADE # (1)
in my case N is 0, replace N with the number of the card which is directly connected to your modem.
Set IP Forwarding:
# echo 1 > /proc/sys/net/ipv4/ip_forward
Install dnsmasq using apt-get:
# apt-get install dnsmasq
and restart it:
# /etc/init.d/dnsmasq restart
Add the following line to /etc/sysctl.conf:
"net.ipv4.ip_forward = 1"
Reboot and repeat (1).

Before continuing with the next laptop make sure that you have working Internet connection on Laptop 1.

First you need to create an Ad-hoc network on your Windows machine too:

Because we are doing our sharing without any security, switch to Open network under Properties > Associations.

Set the following configuration for the Laptop 2 with Windows installed:

DNS: (must be the IP of the wireless card on Laptop 1).

Comments are welcome, happy surfing! 🙂


7 thoughts on “Internet Connection Sharing on Ubuntu & Windows with Ad-hoc 2.

  1. Ionut Adrian Luchian

    thanks for share. I tried for many many times but i couldn’t make it ro work. this step (1) i don’t understand it. have a nice day.

    1. akoskm Post author

      This means you need to repeat the command what you executed first. To make it clear I restructured that part a bit. Here is the sequence of commands you have to execute to make it work
      Note that I made this article for Ubuntu 10.04 which doesn’t mean that it won’t work with newest version, but it is possible that your network interface looks like different and the configuration options are renamed.

      Hope this helps.

  2. Dave Baxter

    Stuck in a hotel with creaky wifi so trying to share the wired lan. Epic fail on many fronts, but this came closest. However, following your guide, when either dnsmasq install’s or is restarted, it fails saying port 53 is already in use. This on Lubuntu (that identifies itseff as Ubuntu12.04.2)
    I’m now lost for the duration I suspect. Thanks for the time and work putting this together though.
    PS: I think you got your ip addresses swapped in the example, the text doesnt agree with the illustrations.

  3. Pingback: Ubuntu:How do I share my Wi-Fi via Wi-Fi Direct on my laptop? – Ubuntu Linux Questions

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s