Ubuntu / Fedora Box as Wifi Router




Have you ever got into situation where you need to access wireless without having WIFI AP / Router? If you are searching for solution to turn your Linux Box into wifi router, this article will guide you through.
I have tested this on Fedora 14 & Ubuntu 10.10, this should work with RHEL & CentOS also.

To configure Linux box as Wifi router all you need is
hostadp
dhcp server
ip forwarding
iptables masquerade for external interface i.e eth0

Ubuntu 10.10 Box as WIFI Router

apt-get install hostapd

Save following contents as /etc/hostapd/hostapd.conf

#
# This will give you a minimal, insecure wireless network.
# 
# DO NOT BE SATISFIED WITH THAT!!!
#
# For more information, look here:
#
#	http://wireless.kernel.org/en/users/Documentation/hostapd
#
 
ctrl_interface=/var/run/hostapd
#ctrl_interface_group=wheel
 
# Some usable default settings...
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
 
# Uncomment these for base WPA & WPA2 support with a pre-shared key
#wpa=3
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP
#rsn_pairwise=CCMP
 
# DO NOT FORGET TO SET A WPA PASSPHRASE!!
#wpa_passphrase=YourPassPhrase
 
# Most modern wireless drivers in the kernel need driver=nl80211
driver=nl80211
 
# Customize these for your local configuration...
interface=wlan0
hw_mode=g
channel=1
ssid=LinuxReaders
 
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=linuxreaderscom
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

In above config you’ll need to change ssid & password (wpa_passphrase).

To start hostapd

hostapd -d /etc/hostapd/hostapd.conf

Install & Configure DHCPD
Further config for wlan0

mentione wlan0 as interfaces in /etc/default/dhcp3-server

Assign IP to wlan0

ifconfig wlan0 inet 192.168.9.1 netmask 255.255.255.0


Enter followings in /etc/rc.local to get wifi working on every reboot.

echo 1 > /proc/sys/net/ipv4/ip_forward 
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
 
ifconfig wlan0 inet 192.168.9.1 netmask 255.255.255.0
hostapd -d /etc/hostapd/hostapd.conf &
/etc/init.d/dhcp3-server restart

Fedora Box as WIFI Router

yum install hostapd -y

Enter followings in /etc/hostapd/hostapd.conf

# Customize these for your local configuration...
interface=wlan0
hw_mode=g
channel=6
ssid=LinuxReaders
 
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=linuxreaderscom
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
chkconfig hostapd on
service hostapd restart

Install & Configure DHCPD (based on CentOS)

Further config for wlan0
make sure only wlan0 is configured in /etc/sysconfig/dhcpd

Assign IP to wlan0
ifconfig wlan0 address 192.168.9.1 netmask 255.255.255.0

Enter followings in /etc/rc.local

echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Once after running hostaspd you’ll find new wireless network
Read More about advance configuration


if you find any missing point in here, please let us know in comment section or tweet us at @linuxreaders. To get more articles like this, subscribe to our RSS feeds / Mails.
Read 240 articles by
  • Daniel

    I am running fedora 16, and I followed the the steps from this tutorial. After last step… service hostapd restart. I managed to connect to the internet to my android smartphone, but after restarting the system I couldn’t connect any more. What is the problem?

    • http://www.linuxreaders.com/ Dhaval Thakar

      did u run chkconfig hostapd on ? also make sure your iptables rules are saved in /etc/rc.d/rc.local in f16 fedora has changed rc.local location.

  • solomy

    i’ve used sudo apt-get install dhcp3-server through the terminal.but when i check /etc/dhcp/ there is nothing.i do not have dhcp.conf.please help thanks

    • http://www.linuxreaders.com/ Dhaval Thakar

      valid file is /etc/dhcp3/dhcpd.conf pl refer this link for dhcp server config on ubuntu

  • http://imptechs.com Tajinder Singh

    Thanks a lot for the guide. It will surely help me to configure my Data Card connection to be shared on my LAN. Right now a little busy, will try and post here if any problem occured.

  • Tiklu Ganguly

    Hi, First of all a big thanks to you. Using your link I just shared my mobile usb dongle for net connection. I just needed to use ppp0 in place for eth0. Thanks once more to save my day. Regards Tiklu

  • Pingback: Ubuntu Box as Wifi Router | TurboLinux Blog

  • Alexis Farmer

    These were the easiest instructions that I could find however I didn’t understand this bit: > mentione wlan0 as interfaces in /etc/default/dhcp3-server In your version of /etc/hostapd/hostapd.conf the wpa_passphrase is set twice, so that confused my at first, I uncommented the first occurence and set it to my password earlier in the .conf and then it gets overwritten later To get the forwarding working I installed firestarter. When it starts the wizard you tell it that the internet connected device is ppp0 and then select the wireless as the shared device and then everything works, you dont actually have to use firestarter after that.

    • http://www.linuxreaders.com/ Dhaval Thakar

      mentione wlan0 as interfaces in /etc/default/dhcp3-server because wifi interface tobe used to lease ips to other wifi based devices. in ubuntu /etc/hostapd/hostapd.conf there is single wpa_passphrase first one is commented, only second one applies. actual config starts with interface=wlan0, above all is default config appeared after installing hostapd. whereas in fedora no /etc/hostapd/hostapd.conf file created after package installation.

Trending Posts