Configure a Linux system as a wifi router or hotspot

Linux Wifi Router

This article provide a simple and precise steps to create a Wi-Fi Hotspot or router on Ubuntu / Debian / Fedora / CentOS / RHEL/ Arch Linux system using nmcli command line network management tool. If you don’t have a wifi router and you want to share internet connection to other folks through your laptop, this is the right article for you.


Topic

  • How to configure a Linux system as a wifi router or hotspot?
  • Setup Linux wifi hotspot
  • Share internet through Linux wifi hotspot
  • Configure Linux wifi hotspot on Ubuntu/Debian/Centos/Arch Linux/RHEL
  • Configure Linux wifi router on Ubuntu/Debian/Centos/Arch Linux/RHEL


Prerequisites for Linux hotspot or wifi router

  • Make sure your laptop or system has a active internet connection either through the LAN interface or through a USB dongle.

  • For our testing I used a Airtel 4g dongle which provides internet connection to the laptop. If you have a active LAN internet you can use that too.

  • Identify the wireless device name. In our case the device name is wlan0. You may have the device name as wlp*.

# ip link show|grep wl
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000

  • Check whether the wireless device has support for access point(ap) mode. This ap mode is needed to setup the wifi interface as a wifi hotsopt or access point.
# iw list| grep -A 8 "Supported interface modes:"
    Supported interface modes:
         * IBSS
         * managed
         * AP <<<<<<<<<<<<<<<< Here
         * AP/VLAN
         * monitor
         * P2P-client
         * P2P-GO
         * P2P-device

  • Make sure NetworkManager is enabled and working.


Linux Wifi router or hotspot configuration

  • Create a profile for hotspot. Here hotspot or wifi name is LinsHotspot.
# WIFIINT="wlan0"
# WIFI_SSID="LinsHotspot"
# nmcli con add type wifi ifname $WIFIINT con-name $WIFI_SSID autoconnect yes ssid $WIFI_SSID

  • Set wifi access point method as shared.
nmcli con modify $WIFI_SSID 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared

  • Set your wifi hotspot security type(wpa-psk) and password.
# nmcli con modify $WIFI_SSID wifi-sec.key-mgmt wpa-psk
# nmcli con modify $WIFI_SSID wifi-sec.psk "type_pass_here"

  • Bring up the hotspot connection.
# nmcli con up $WIFI_SSID

  • Now check your connection status.
# nmcli connection show $WIFI_SSID

# nmcli connection show 
NAME          UUID                       TYPE       DEVICE    
Hostspot      fd3r1fc-dkjjjwe-oko12      wifi       wlan0 

  • Now check the hotspot router or interface IP address.
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 21:79:19:5e:3b:80 brd ff:ff:ff:ff:ff:ff
    inet 10.42.0.1/24 brd 10.42.0.255 scope global noprefixroute wlp6s0
       valid_lft forever preferred_lft forever
[...]

  • By default wifi hotspot get 10.42.0.1 IP address and the network is 10.42.0.0/24. In the background NetworkManager runs a DHCP server through dnsmasq which will provide IP address to all wifi users from 10.42.0..0/24 network.

  • Now scan the wifi hotspot on your mobile or laptop or any wifi supported device to connect to your hotspot. Upon scanning you will see hotspot name LinsHotspot.


You May Also Like

avatar

About the Author: TekFik

TekFik is a technical blogging site helps techies and engineers to solve their day to day issues and also allows everyone to share knowledge and feedback. Please feel free to contact us at tekfik.rd@gmail.com if there is anything.

Leave a Reply

Your email address will not be published. Required fields are marked *