Easily Turn Your Ubuntu into a Virtual Router

Do you have a PSP or a Blackberry that supports wifi connection but without an ad-hoc wireless network capacity? I own these two devices and have been struggling to get their wireless work with my laptop’s internet connection. With the default network-manager of nm-applet, you can only create an ad-hoc wireless network share, which cannot be found by these devices. After some Google work, I finally found a solution, that is, hostapd


In Ubuntu 10.04, it seems extremely easy to have this hostapd work. First, of course, you need to install it. It is already in the official repositories. Just run this in the terminal:
sudo apt-get install hostapd

Then, open a text editor program, for example gedit. Copy the following into it.

interface=wlan0
driver=nl80211
ssid=
channel=1
hw_mode=g
auth_algs=1
wpa=3
wpa_passphrase=
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP


Please don’t forget to fill in the name of your network after “ssid=”, as well as the password after “wpa_passphrase=”.

After all these, save the file as hostapd.conf in your home folder.

Now, in your terminal:

sudo hostapd hostapd.conf

Turn the wifi connection on in your devices and enjoy the fast network share!

About these ads

~ by zhangyou on August 26, 2010.

28 Responses to “Easily Turn Your Ubuntu into a Virtual Router”

  1. what is nl80211?
    it’s not working my driver might be different

    • Sorry I did not make it clear enough. For different drivers you may need to first make sure the driver is supported by Hostapd, and then specify its name in the conf file.

  2. no dns on my ipod could use it stiill like normal ad-hoc

  3. Hey I am getting this error in this please tell me whats wrong …

    Could not set station 04:18:0f:a5:7b:76 flags for kernel driver (errno=95)

  4. Thanks. I tried to do the same on Linux Mint 11. But I get the error message that “could not set station —- flags for kerner driver (errno=95). Complete info is given below:

    [Using interface wlan0 with hwaddr 00:22:b0:66:3d:8e and ssid 'gautam'
    wlan0: STA a0:75:91:62:e1:99 IEEE 802.11: authenticated
    wlan0: STA a0:75:91:62:e1:99 IEEE 802.11: associated (aid 1)
    wlan0: STA a0:75:91:62:e1:99 RADIUS: starting accounting session 4E51159B-00000000
    wlan0: STA a0:75:91:62:e1:99 WPA: pairwise key handshake completed (RSN)
    wlan0: STA a0:75:91:62:e1:99 IEEE 802.11: disassociated
    Could not set station a0:75:91:62:e1:99 flags for kernel driver (errno=95).]

    Any suggestions please. Thanks once again

  5. hi
    i did what you said there is a message appear when i do
    sudo hostapd hostapd.conf
    this is message
    *****************************************************************************
    nl80211: Failed to set interface wlan0 into AP mode
    nl80211 driver initialization failed.
    ELOOP: remaining socket: sock=4 eloop_data=0x932fa60 user_data=0x9330000 handler=0x807c670
    ELOOP: remaining socket: sock=6 eloop_data=0x9331820 user_data=(nil) handler=0x8086770
    **************************************************************************
    so what happen and what is solution

    • Sorry I did not make it clear enough. For different drivers you may need to first make sure the driver is supported by Hostapd, and then specify its name in the conf file.
      I am sorry again.

  6. I tried this way but it says the following
    Configuration file: hostapd.conf
    Failed to set interface wlan0 to master mode.
    nl80211 driver initialization failed.
    ELOOP: remaining socket: sock=5 eloop_data=0x6cd420 user_data=(nil) handler=0x43d3a0
    manish@manish-laptop:~$

    Please help me out !!

  7. First of all, thank you for sharing this method! It is by far the easiest I found yet. I’m trying to give my (Archos) internet tablet a connection to the internet, shared by my PC, but it also doesn’t recognises ad-hoc. I follewed you’re instructions and everything goes well, until when I try to connect the network I’m sending. The internet tablet get’s stuck on “Obtaining Ip adres” This is what the terminal says:

    tim@ubuntu:~$ sudo hostapd hostapd.conf
    Configuration file: hostapd.conf
    Using interface wlan0 with hwaddr 00:22:5f:db:ed:71 and ssid ‘TimDroid’

    wlan0: STA 00:16:dc:5d:b2:e9 IEEE 802.11: authenticated
    wlan0: STA 00:16:dc:5d:b2:e9 IEEE 802.11: associated (aid 1)
    AP-STA-CONNECTED 00:16:dc:5d:b2:e9
    wlan0: STA 00:16:dc:5d:b2:e9 RADIUS: starting accounting session 4EEA669E-00000000
    wlan0: STA 00:16:dc:5d:b2:e9 WPA: pairwise key handshake completed (RSN)
    AP-STA-DISCONNECTED 00:16:dc:5d:b2:e9

    wlan0: STA 00:16:dc:5d:b2:e9 IEEE 802.11: authenticated
    wlan0: STA 00:16:dc:5d:b2:e9 IEEE 802.11: associated (aid 1)
    AP-STA-CONNECTED 00:16:dc:5d:b2:e9
    wlan0: STA 00:16:dc:5d:b2:e9 RADIUS: starting accounting session 4EEA669E-00000001
    wlan0: STA 00:16:dc:5d:b2:e9 WPA: pairwise key handshake completed (RSN)
    AP-STA-DISCONNECTED 00:16:dc:5d:b2:e9

    wlan0: STA 00:16:dc:5d:b2:e9 IEEE 802.11: authenticated
    wlan0: STA 00:16:dc:5d:b2:e9 IEEE 802.11: associated (aid 1)
    AP-STA-CONNECTED 00:16:dc:5d:b2:e9
    wlan0: STA 00:16:dc:5d:b2:e9 RADIUS: starting accounting session 4EEA669E-00000002

    And it keeps repeating this endlessly. Do you have any idea what I should add or alter?

    Many thanks! Tim

    • I also met this problem before with my Android phone. After a few days of trying this and that, here is what I did and it works great:

      The problem is the computer failed to provide an IP address for my device. So first I set up an ad-hoc wireless network in networkmanager, make sure it is set to use static IP address( 10.42.43.1, for example), the subnet mask can be 255.255.255.0, and make sure you fill in the right DNS server address.

      Now in terminal type in: sudo hostapd hostapd.conf

      Go to networkmanager, connect to the ad-hoc network you just created.

      Hostapd should be terminated automatically now because of the ad-hoc network you just connected.

      Finally run the “sudo hostapd hostapd.conf” command again.

      In your phone or tablet device, you should also use a static IP address. In my case, it is set to 10.42.43.2, and the gateway is of course 10.42.43.1. The rest should be the same as in your ad-hoc setting.

      I hope I make it clear enough and good luck with you!

  8. thanks for your nice tutorial.very clear and after reading all your comment reply I finally can connect to the wireless.

    but here came the problem. The wireless connect fine with my android device. but no service. I can’t surf the internet.

    Samsung Galaxy S2

  9. I tried to connect my galaxy mini to my PC. I got the following message repeatedly.
    wlan0: STA a0:75:91:62:e1:99 IEEE 802.11: authenticated
    wlan0: STA a0:75:91:62:e1:99 IEEE 802.11: associated (aid 1)
    wlan0: STA a0:75:91:62:e1:99 RADIUS: starting accounting session 4EFEC96A-00000001
    wlan0: STA a0:75:91:62:e1:99 WPA: pairwise key handshake completed (RSN)
    wlan0: STA a0:75:91:62:e1:99 IEEE 802.11: disassociated
    Could not set station a0:75:91:62:e1:99 flags for kernel driver (errno=95).

    Can anybody please help ?

  10. I tried to setup using the static IP method. Though the mobile connected to the PC, it is unable to connect to internet. When we setup the adhoc network in the PC, what should be the gateway address ? I gave the same address as that of the IP address.

  11. hi. thanks for this article. i try this i get error.
    Could not set station fc:c7:34:37:e3:f5 flags for kernel driver (errno=11).

    fc:c7:34:37:e3:f5 is my device mac address. i have try with ubuntu 11.10 and my samsung galaxy Ace device having android V2.2.4.

    mobile and laptop connection successfully but mobile can not obtain ip address from laptop. can u please help me!

  12. Hey, just a quick question. I was wondering if you had any idea how to do this on windows? My roommate just got a kindle as well, so it’s no longer efficient to just run wireless from my phone when its needed for downloads and whatnot, so I would like to leave a network available and running from my desktop 24/7. However I would really like to leave my computer booted to my windows partition so I can keep using my main programs. Thoughts?

    • try connectify or virtual router. both will work on windows. Sorry i know you asked that 2 months ago but i dunno if you got an answer :)

  13. hi i tried the method and it’s ok 100%
    i again give the right tutorial …though the author is right always..
    follow this…..====>
    Just run this in the terminal:

    sudo apt-get install hostapd

    u ll get install hostapd (though u can’t see in DASH HOME)

    OK NOW..

    Then, open a text editor program, for example gedit. Copy the following into it.

    that means open — gedit —from DASH HOME

    TYPE THE SAME WITH SOME CHANGES….

    =======================================
    interface=wlan0
    driver=nl80211
    ssid=
    channel=1
    hw_mode=g
    auth_algs=1
    wpa=3
    wpa_passphrase=
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP CCMP
    rsn_pairwise=CCMP
    =======================================

    KEEP IN MIND THAT IN ABOVE LINES…..
    ssid= (is your network provider, e.g. mine is reliance EVDO)
    SO I MODIFY ABOVE LINE AS THIS….

    ssid=reliance EVDO

    NOW
    wpa_passphrase= (is your desired password, e.g. mine is maulesh)
    SO I MODIFY ABOVE LINE AS THIS….

    wpa_passphrase=maulesh

    OK NOW DO THIS …AND SAVE FILE GENERATED IN gedit…

    AS NAME —– hostapd.conf (IN YOUR HOME DIRECTORY)

    OK NOW U FINISHED ONE PHASE TO MAKE YOUR UBUNUTU MACHINE VIRTUAL ROUTER….

    THE SECOND PHASE IS MORE IMPORTANT … (IF U FOLLOW OR UNDERSTAND ME CORRECTLY… THEN U WIN)

    NOW OPEN — network — from DASH HOME
    GO TO OR OPEN — wireless —-
    (see if wireless is ON or not …if OFF then ON it…)

    NOW PUT YOUR MOUSE CURSER TO THE RIGHT CORNER OF THE SCREEN AND CLICK … U SEE MANY NETWORKS THERE…

    CLICK
    — create new wireless network —

    U LL SEE A NEW WINDOW AS THIS (I CAN’T DRAW SO SEE AS BELOW)

    NEW WIRELESS NETWORK
    CONNECTION (NEW)
    NETWORK NAME (BLANK)
    WIRELESS SECURITY (WEP 128-BIT PASSPHRASE)
    KEY (BLANK)

    (CANCEL) (CREATE)

    NOW FOLLOW ME>>>>

    CONNECTION (NEW)

    NETWORK NAME (your network name -as in hostapd.conf) ((for me reliance EVDO))

    WIRELESS SECURITY (WPA & WPA2 PERSONAL) ((only select this to protect ur connection))

    KEY (your desired password -as in hostapd.conf) ((for me maulesh))

    NOW CLICK (CREATE)

    OK OK WAIT… JUST FOR SECONDS….

    AGAIN PUT YOUR MOUSE CURSER TO THE RIGHT CORNER OF THE SCREEN AND CLICK … U SEE MANY NETWORKS THERE…

    CLICK
    — connect to hidden wireless network —

    U LL SEE A NEW WINDOW AS THIS (I CAN’T DRAW SO SEE AS BELOW)

    CONNECTION (NEW)
    NETWORK NAME (BLANK)
    WIRELESS SECURITY (BLANK)

    (CANCEL) (CREATE)

    NOW CLICK ON CONNECTION … U LL DEFINITELY SEE YOUR CONFIGURED WIRELESS NETWORK (for me — reliance EVDO– )

    OK NOW SELECT UR CONFIGURED NETWORK AND CLICK

    (CONNECT)

    SO U VE NOW COMPLETED THE SECOND AND MOST IMPORTANT PHASE)

    JUST A FEW MINUTES TO OBSERVE OR CHECK WE R RIGHT/WRONG SO ..

    GO TO — terminal — from DASH HOME

    GIVE THIS COMMAND …. (don’t close this terminal until u r using network on other machine)

    sudo hostapd hostapd.conf

    AND NOW THE TERMINAL DANCE… N WE DANCE TOGETHER …
    CHECK UR WIFI — in tablet or pc….
    U LL NOTICE THE CONFIGURED NETWORK OPEN FOR U TO SERVE U BETTER ALWAYS…..
    BYE… THANKS FOR FOLLOW ME….
    my email is —- elc12thsep00@yahoo.co.in

    and of course very very fond of LINUX UBUNTU …. and its USERS…..

    THX…T.C….BYE….

  14. Thanks a lot Maulesh it was of great help

  15. it works fantastic!!! thanks

  16. dear sir, i used this method since 3 months .. and got success too . but please show the method to speed up guest pc’s internet speed through host pc. i noticed that the connection break and repair automatically, but by this method the internet speed is not enough as per expectaion..
    hoping of your good reply..maulesh

  17. thank you

  18. [...] via Zhangyou’s Blog. [...]

  19. “Easily Turn Your Ubuntu into a Virtual Router Zhangyou’s Blog” ended up being a remarkable blog post. If only there were significantly more blogs such as this excellent one on the word wide web. Nonetheless, thanks a lot for your personal precious time, Albertha

  20. My phone shows the connection. But, after “obtaining IP address from… ” it will say “Remembered” on ubuntu 11.10

  21. I get the following error:

    “$ sudo hostapd hostapd.conf

    [sudo] password for alessandro:

    Configuration file: hostapd.conf
    Failed to create interface mon.wlan0: -23 (Too many open files in system)
    Try to remove and re-create mon.wlan0
    Using interface wlan0 with hwaddr 5c:ac:4c:47:f4:c2 and ssid ‘ubuntu’
    wlan0: STA 38:aa:3c:cf:c7:89 IEEE 802.11: authenticated
    wlan0: STA 38:aa:3c:cf:c7:89 IEEE 802.11: associated (aid 1)
    AP-STA-CONNECTED 38:aa:3c:cf:c7:89
    wlan0: STA 38:aa:3c:cf:c7:89 RADIUS: starting accounting session 51E16F76-00000000
    wlan0: STA 38:aa:3c:cf:c7:89 WPA: pairwise key handshake completed (RSN)
    AP-STA-DISCONNECTED 38:aa:3c:cf:c7:89
    wlan0: STA 38:aa:3c:cf:c7:89 IEEE 802.11: disassociated
    unknown mgmt cb frame subtype 10
    AP-STA-DISCONNECTED 38:aa:3c:cf:c7:89
    Could not set station 38:aa:3c:cf:c7:89 flags for kernel driver (errno=11).

    what’s worng?

  22. Thanks this worked for me after I recompiled hostapd :)

  23. i get invalid SSID erropr

  24. Hi

    I’ve tried this but got this problem

    sid@sid-Ideapad-Z560:~$ sudo hostapd hostapd.conf
    Configuration file: hostapd.conf
    Could not set channel for kernel driver
    wlan0: Unable to setup interface.
    Could not connect to kernel driver.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: