Coder Social home page Coder Social logo

hotspot's Introduction

hotspot

shell script for setup and management of hotspot (hostapd) functions on rpi platform

functions:

  • try
  • start
  • stop
  • restart
  • retry
  • status
  • setup
  • setchan [channel]
  • syslog [lines]
  • ovpn [start|stop]
  • tor [start|stop]
  • version
  • wlan [start|stop]
  • modpar <dnsmasq|hostapd|self> <name> [value]

will use onboard wlan adaptor for hotspot functionality and
the on board ethernet port or an optional external usb wlan adaptor (e.g. EW-7811Un Realtek RTL8188CUS)
for internet access.

best wlan channel for hotspot functionality will be determined automatically by least used frequency spectrum.

actions will be logged to /tmp/hotspot and syslog
pls. see examples in troubleshooting section.

for full installation and setup sequence, pls. see installation and setup section at the bottom of this file

installation

rpi login as root required

root:# cd /usr/local/sbin
root:# rm hotspot                  # just remove old hotspot script
root:# wget https://raw.githubusercontent.com/rudiratlos/hotspot/master/hotspot
root:# chmod +x hotspot
root:# apt-get update
root:# apt-get upgrade

setup

will install all required packages (e.g. iw tor hostapd dnsmasq),
setting parameters and create config files:

  • /etc/sysctl.conf (activate line net.ipv4.ip_forward=1)
  • /etc/rc.local
  • /etc/issues
  • /etc/dhcpcd.conf
  • /etc/dnsmasq.conf
  • /etc/default/hostapd
  • /etc/hostapd/hostapd.conf
  • /etc/tor/torrc

Existing files will be backed up with a date extension (YYYYMMDDhhmmss).

hotspot setup
hotspot try

above command sequence will create a hotspot with following default parameter:

ssid: <HOSTNAME>wlan-<MAC3ByteAdr> (e.g. RPIwlan-abcdef)
pwd: hallohallo
country: DE

next commands will create all config files and adjusts parameter to your environment.

hotspot setup
hotspot modpar hostapd ssid myHotspotID 
hotspot modpar hostapd wpa_passphrase myHotspotPassword
hotspot modpar hostapd country SE

hotspot try

start

start all hotspot associated functions:

  • terminate connection on wlan0
  • create device ap0 and assign IP addr
  • start dnsmasq
  • start hostapd
hotspot start

try

will start hotspot if following condition is met:

  • wlan0 or eth0 not connected
  • wlan0 and eth0 IP addresses are on same IP subnet (wlan0 connection will be stopped)
hotspot try

stop [nowlan]

stop hotspot functions:

  • stop hostapd
  • stop dnsmasq
  • optional: restart wlan
hotspot stop

restart

executes following hotspot sequence:

  • hotspot stop nowlan
  • sleep 20 seconds (settling time)
  • hotspot start
hotspot restart

retry

executes following hotspot sequence:

  • hotspot stop nowlan
  • sleep 20 seconds (settling time)
  • hotspot try
hotspot retry

modpar

change parameter value in config file

format: hotspot modpar <dnsmasq|hostapd|self> <name> [value]

file selector:
dnsmasq                 /etc/dnsmasq.conf
hostapd                 /etc/hostapd/hostapd.conf
self                    /usr/local/sbin/hotspot

name			parameter name
value			parameter value

examples:

hotspot modpar hostapd ssid myHotspotID     # set parameter ssid=myHotspotID
hotspot modpar hostapd country_code DE      # set parameter country_code=DE

special hostapd parameter

autostart

During boot process /etc/rc.local will look for file content #autostart=1 and will execute hotspot try command.

hotspot modpar hostapd autostart 1          # enable  autostart
hotspot modpar hostapd autostart 0          # disable autostart

ovpnstart

start openvpn automatically

hotspot modpar hostapd ovpnstart 1         # enable  ovpnstart
hotspot modpar hostapd ovpnstart 0         # disable ovpnstart

adjust specific openvpn parameter

hotspot modpar self ovpn_dev tun3          # change ovpn device for iptables

to work correctly, ovpn_dev has to be the same, that is defined in .ovpn config file (parameter dev).

torstart

start tor service automatically

hotspot modpar hostapd torstart 1           # enable  torstart
hotspot modpar hostapd torstart 0           # disable torstart

useiptables

hotspot script will look for file content #useiptables=1 or #useiptables=0 and will execute iptables commands for activation and deactivation.

hotspot modpar hostapd useiptables 1        # executing iptable commands
hotspot modpar hostapd useiptables 0        # no iptable commands

openvpn

start or stop openvpn experimental
requires following files:
config: /etc/openvpn/client/hotspot.ovpn
passwd: /etc/openvpn/client/hotspot.pwd
pls. see ovpnstart parameter for automatic starting openvpn and modifying parameter

hotspot ovpn start                          # start tor service
hotspot ovpn stop                           # stop  tor service

tor

start or stop tor service experimental
pls. see torstart parameter for automatic starting tor service.

hotspot tor start                           # start tor service
hotspot tor stop                            # stop  tor service

syslog [lines]

show hotspot related syslog entries

hotspot syslog
hotspot syslog 5

version

show hotspot script version

hotspot version

installation and setup

rpi login as root required

root:# cd /usr/local/sbin
root:# rm hotspot                           # just remove old hotspot script
root:# wget https://raw.githubusercontent.com/rudiratlos/hotspot/master/hotspot
root:# chmod +x hotspot
root:# apt-get update
root:# apt-get upgrade                      # optional

root:# hotspot setup

root:# hotspot modpar hostapd ssid myHotspotID 
root:# hotspot modpar hostapd wpa_passphrase myHotspotPassword
root:# hotspot modpar hostapd country SE
root:# hotspot modpar hostapd autostart 1   # optional autostart enable
root:# hotspot modpar hostapd useiptables 1 # optional

root:# reboot                               # if autostart enable or use hotspot try

troubleshooting

log entries will be sent to the file /tmp/hotspot.log and syslog utility

following commands will show you hotspot script activity

hotspot syslog
cat /tmp/hotspot.log
tail -500 /var/log/syslog | grep -a "hotspot:"
cat /var/log/syslog | grep -a "hotspot:"

these commands will show 5 log entries of involved SW packages caused by hotspot command sequence

hotspot syslog 5
tail -500 /var/log/syslog | grep -a -A 5 "hotspot:"
cat /var/log/syslog | grep -a -A 5 "hotspot:"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.