No, it won’t affect your system if you do it the way I have done with a separate USB wifi adapter. I suggest you proceed as follows:
Firstly, plug in the wifi adapter you intend to use for the hotspot and determine its device name. It will probably be wlan1 but you can check with the following command.
sudo /usr/sbin/iwconfig
Note: the adapter doesn’t need to be configured with Yast.
Secondly, install the following 3 packages and whatever dependencies they pull in: [FONT=courier new]hostapd, dnsmasq and yad. hostapd allows you to create the hotspot (access point) and dnsmasq provides dhcp services on the sub-network associated with hotspot. Note that I chose 192.168.9.0 as my subnet to avoid clashing with other wifi providers. Use this, unless you have a real reason to change.
Then write configuration files for hostapd and dnsmasq as shown below.[/FONT]
grb@pippin:~> cat /etc/hostapd.conf
interface=wlan1
driver=nl80211
ssid=pippinAP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=pipperone
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
grb@pippin:~> cat /etc/dnsmasq.conf
#Name:Default
#Type:DNSMASQ
# disables dnsmasq reading any other files like /etc/resolv.conf for nameservers
no-resolv
# Interface to bind to
interface=wlan1
# Specify starting_range,end_range,lease_time
dhcp-range=192.168.9.2,192.168.9.10,12h
# dns addresses to send to the clients (NB: google servers)
server=8.8.8.8
server=8.8.4.4
Adjust the parameters in blue to suit your set-up. Check that both services start OK.
Thirdly, add the following script as ~/bin/hotspot.sh and make it executable.
grb@pippin:~> cat ./bin/hotspot.sh
#!/bin/bash
### configure
# setup for my ASUS N13 usb dongle
wifi_interface='wlan1'
adapter_id='0b05:1784'
# choose a subnet for the hotspot
# and an IP for the interface
subnet='192.168.9.0/24'
IP='192.168.9.1/24'
###########################################################
# try and locate the external interface automatically
ext_interface=$(ip route | grep default | cut -d' ' -f5)
user=$(whoami)
logname=$(logname)
### Return codes
# 0 - all OK
# 4 - user had insufficient privileges
# 150 - no adapter found
function check_user {
### check the script is being run with root privileges
if $user != 'root' ]; then
kdialog --title='Hotspot' \
--sorry "This script must be run with root privileges. \
Please use 'sudo $(basename $0)'"
exit 4
fi
}
function check_adapter {
### check the wifi adapter is attached
adapter_attached=$(lsusb | grep -ic $adapter_id)
if $adapter_attached -ne 1 ]; then
su -l $logname -c "kdialog --display=:0.0 \
--title 'Hotspot' \
--sorry 'Cannot find the wifi adapter.
Please connect the ASUS N-13 adapter and retry.'"
exit 150
fi
}
function stop_wifi_ap {
### stop services dhcpd server and hostapd
systemctl stop hostapd
systemctl stop dnsmasq
### disable IP forwarding
sysctl -w net.ipv4.ip_forward=0 1> /dev/null
iptables -t nat -D POSTROUTING -s $subnet -o $ext_interface -j MASQUERADE 2>/dev/null
### remove static IP address from the wifi interface
ip address del $IP dev $wifi_interface 2> /dev/null
}
function start_wifi_ap {
### give a static IP to the wifi interface
ip link set dev $wifi_interface up
ip address add $IP dev $wifi_interface
### enable IP forwarding
iptables -t nat -A POSTROUTING -s $subnet -o $ext_interface -j MASQUERADE
sysctl -w net.ipv4.ip_forward=1 1> /dev/null
### start services - dhcpd server and hostapd
systemctl start hostapd
systemctl start dnsmasq
}
function start_notifier {
su -l $logname -c 'yad --display=:0.0 \
--notification \
--image="/home/grb/scripts/hotspot/ap_up.png" \
--text "Click to close Hotspot"'
}
function stop_notifier {
pkill yad
}
function stop {
stop_wifi_ap
stop_notifier
exit
}
function start {
check_adapter
### regard this as a forced start so kill any current processes first
stop_wifi_ap
stop_notifier
start_wifi_ap
# causes script to block until icon is clicked
start_notifier
stop
}
function auto {
# Does nothing at this stage. See comment below
:
}
### main
check_user
if $# -lt 1 ]; then
auto
else
### start/stop wifi access point
case "$1" in
start) start ;;
stop) stop ;;
*) echo "Usage: $0 {start|stop}"
exit 1 ;;
esac
fi
############################################
# The intention was to have an 'auto' mode in addition to
# 'start' and 'stop'.
# In auto mode, the notifier would be started as a sub-process (i.e. non blocking)
# and this script would listen for clicks on the notifier.
Again, adjust the parameters in blue.
The adapter_id can be found by running the command
grb@pippin:~> lsusb
Bus 001 Device 010: ID 0b05:1784 ASUSTek Computer, Inc. USB-N13 802.11n Network Adapter (rev. A1) [Ralink RT3072]
Bus 002 Device 008: ID 0402:7675 ALi Corp.
Bus 003 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
....
Download a suitable icon and save it somewhere in your home directory. I used this icon http://www.veryicon.com/icon/64/System/Crystal%20Clear%20Actions/Irkick%20Flash.png and saved it as ~/scripts/ap_up.png. Adjust the script above to suit what you do.
At this stage you should be able to test that it all works by running the following command, in a terminal window (Konsole)
sudo hotspot.sh start
After entering the root password, the icon downloaded above should appear in the system tray and the light on the adapter should start to flash. All being well, you will be able to connect to the hotspot from your phone.
To bring the hotspot down, either click on the icon in the system tray or hit CTL-c in the terminal.
To make everything simple I added a desktop icon containing the following code
grb@pippin:~> cat ./Desktop/Hotspot.desktop
[Desktop Entry]
Comment[en_US]=
Comment=
Comment[en_GB]=
Exec=sudo hotspot.sh start
GenericName[en_US]=
GenericName=
GenericName[en_GB]=
Icon=/home/grb/scripts/hotspot/ap_up.png
MimeType=
Name=Hotspot
Name[en_GB]=Hotspot
Path=
StartupNotify=false
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=
Again, adjust the code to suit the icon name/location you chose.
Finally, to avoid having to provide a password each time, I used YAST to add the command [FONT=courier new]/home/USERNAME/bin/hotspot.sh start to the list of sudo rules. So now I simply click on the desktop icon to bring up the hotspot, and click on the tray icon to bring it down again.
I set my system up a while ago, so I hope I haven’t left out too much. Anyway let me know if you run into problems.
Graeme[/FONT]