8

I am using XUbuntu 17.10 and i have created a wifi hotspot, the problem is i want to use the hotspot for samba and other things that don't require an internet connection. how do i create a wifi hotspot that doesn't share my internet connection? is this even possible?

  • How are you connecting the host computer(the machine which broadcasts the hotspot) to the internet? Ethernet? – Yaksha Oct 29 '17 at 6:14
  • I am using a Huawei 3G Modem @Yaksha, it is connected through a USB Port – zola Oct 29 '17 at 6:21
3
+25

A simple solution is to use create_ap. From their site:

create_ap is a tool that helps you create an open, or encrypted AP at any channel, hide your SSID, disable communication between clients (client isolation), IEEE 802.11n & 802.11ac support, Internet sharing methods: NATed or Bridged or None (no Internet sharing)

For your case you want to create an AP with the linux pc without sharing the internet from your dongle to clients, but can do other Lan stuff, like file sharing.

Your wifi card needs to support creating AP

  1. Install some packages:

    sudo apt install util-linux bash procps hostapd iproute2 iw haveged net-tools dnsmasq iptables
    
  2. Get the create_ap package. From the terminal do

    git clone https://github.com/oblique/create_ap
    cd create_ap
    sudo make install
    
  3. After installation, check the name of your modem and wifi card with ifconfig (deprecated) or:

    iwconfig
    

    the wifi card usually is wlan0 or wlp2s0 and usb modem is eth0. yours might be different

  4. Now start hotspot from your linux without internet:

    sudo create_ap -n wlp2s0 MyAccessPoint
    

You can then connect clients. Your internet would not be shared but you can do samba and other things without internet

1

Here is a script that will create Hotspot but not share the Ethernet Internet with the WiFi devices. You will have to change the network interface name according to your system.

Type ip link to find them. Also, make sure you have installed dnsmasq and hostapd.

sudo apt-get install ifconfig dnsmasq hostapd

Before running the script you will have to stop any Network Management Tool which is controlling WiFi.

eth-to-wifi-route.sh

#!/bin/bash

# Share Eth with WiFi Hotspot
#
# This script is created to work with Raspbian Stretch
# but it can be used with most of the distributions
# by making few changes. 
#
# Make sure you have already installed `dnsmasq` and `hostapd`
# Please modify the variables according to your need
# Don't forget to change the name of network interface
# Check them with `ifconfig`

ip_address="192.168.2.1"
netmask="255.255.255.0"
dhcp_range_start="192.168.2.2"
dhcp_range_end="192.168.2.100"
dhcp_time="12h"
eth="eth0" # replace it with Huawei 3G Modem interface
wlan="wlan0"
ssid="Arpit-Raspberry"
psk="arpit1997"

sudo rfkill unblock wlan &> /dev/null
sleep 2

#sudo iptables -F
#sudo iptables -t nat -F
#sudo iptables -t nat -A POSTROUTING -o $eth -j MASQUERADE  
#sudo iptables -A FORWARD -i $eth -o $wlan -m state --state RELATED,ESTABLISHED -j ACCEPT  
#sudo iptables -A FORWARD -i $wlan -o $eth -j ACCEPT 

#sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

sudo ifconfig $wlan $ip_address netmask $netmask

sudo ip route del 0/0 dev $wlan &> /dev/null
a=`route | awk "/${eth}/"'{print $5+1;exit}'`
sudo route add -net default gw $ip_address netmask 0.0.0.0 dev $wlan metric $a

echo -e "interface=$wlan \n\
bind-interfaces \n\
server=8.8.8.8 \n\
domain-needed \n\
bogus-priv \n\
dhcp-range=$dhcp_range_start,$dhcp_range_end,$dhcp_time" > /etc/dnsmasq.conf

sudo systemctl restart dnsmasq

echo -e "interface=$wlan\n\
driver=nl80211\n\
ssid=$ssid\n\
hw_mode=g\n\
ieee80211n=1\n\
wmm_enabled=1\n\
macaddr_acl=0\n\
auth_algs=1\n\
ignore_broadcast_ssid=0\n\
wpa=2\n\
wpa_key_mgmt=WPA-PSK\n\
wpa_passphrase=$psk\n\
rsn_pairwise=CCMP" > /etc/hostapd/hostapd.conf

sudo systemctl restart hostapd
sudo systemctl status hostapd &> /dev/null
if [ "$?" != 0 ];then
    echo "Some Network Management tool is running, which is stopping" 
    echo "hostapd to be configured."
    echo "Please stop that and again run the script."
fi

I have commented the iptable and packet forwarding commands. If anytime you need to give internet to the devices just uncomment them.

Run the script

sudo bash eth-to-wifi-route.sh

Source: eth-to-wifi-route.sh

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.