Merge pull request #407 from dopplerreflect/master

Add option to create dhcp-host values into dnsmasq.conf
This commit is contained in:
Lakindu Akash 2024-09-23 04:48:28 +05:30 committed by GitHub
commit c46049b9ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 78 additions and 25 deletions

View File

@ -1,90 +1,123 @@
## Features ## Features
* Create an AP (Access Point) at any channel.
* Choose one of the following encryptions: WPA, WPA2, WPA/WPA2, Open (no encryption).
* 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).
* Choose the AP Gateway IP (only for 'NATed' and 'None' Internet sharing methods).
* You can create an AP with the same interface you are getting your Internet connection.
* You can pass your SSID and password through pipe or through arguments (see examples).
- Create an AP (Access Point) at any channel.
- Choose one of the following encryptions: WPA, WPA2, WPA/WPA2, Open (no encryption).
- 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).
- Choose the AP Gateway IP (only for 'NATed' and 'None' Internet sharing methods).
- You can create an AP with the same interface you are getting your Internet connection.
- You can pass your SSID and password through pipe or through arguments (see examples).
- Optionally assign IP addresses to specified hosts via dnsmasq's `dhcp-host` configuration option.
## Dependencies ## Dependencies
### General ### General
* bash (to run this script)
* util-linux (for getopt) - bash (to run this script)
* procps or procps-ng - util-linux (for getopt)
* hostapd - procps or procps-ng
* iproute2 - hostapd
* iw - iproute2
* iwconfig (you only need this if 'iw' can not recognize your adapter) - iw
* haveged (optional) - iwconfig (you only need this if 'iw' can not recognize your adapter)
- haveged (optional)
### For 'NATed' or 'None' Internet sharing method ### For 'NATed' or 'None' Internet sharing method
* dnsmasq
* iptables
- dnsmasq
- iptables
## Installation ## Installation
### Generic ### Generic
git clone https://github.com/lakinduakash/linux-wifi-hotspot git clone https://github.com/lakinduakash/linux-wifi-hotspot
cd linux-wifi-hotspot/src/scripts cd linux-wifi-hotspot/src/scripts
make install make install
### ArchLinux ### ArchLinux
pacman -S create_ap pacman -S create_ap
### Gentoo ### Gentoo
emerge layman emerge layman
layman -f -a jorgicio layman -f -a jorgicio
emerge net-wireless/create_ap emerge net-wireless/create_ap
## Examples ## Examples
### No passphrase (open network): ### No passphrase (open network):
create_ap wlan0 eth0 MyAccessPoint create_ap wlan0 eth0 MyAccessPoint
### WPA + WPA2 passphrase: ### WPA + WPA2 passphrase:
create_ap wlan0 eth0 MyAccessPoint MyPassPhrase create_ap wlan0 eth0 MyAccessPoint MyPassPhrase
### AP without Internet sharing: ### AP without Internet sharing:
create_ap -n wlan0 MyAccessPoint MyPassPhrase create_ap -n wlan0 MyAccessPoint MyPassPhrase
### Bridged Internet sharing: ### Bridged Internet sharing:
create_ap -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase create_ap -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase
### Bridged Internet sharing (pre-configured bridge interface): ### Bridged Internet sharing (pre-configured bridge interface):
create_ap -m bridge wlan0 br0 MyAccessPoint MyPassPhrase create_ap -m bridge wlan0 br0 MyAccessPoint MyPassPhrase
### Internet sharing from the same WiFi interface: ### Internet sharing from the same WiFi interface:
create_ap wlan0 wlan0 MyAccessPoint MyPassPhrase create_ap wlan0 wlan0 MyAccessPoint MyPassPhrase
### Choose a different WiFi adapter driver ### Choose a different WiFi adapter driver
create_ap --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase create_ap --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase
### No passphrase (open network) using pipe: ### No passphrase (open network) using pipe:
echo -e "MyAccessPoint" | create_ap wlan0 eth0 echo -e "MyAccessPoint" | create_ap wlan0 eth0
### WPA + WPA2 passphrase using pipe: ### WPA + WPA2 passphrase using pipe:
echo -e "MyAccessPoint\nMyPassPhrase" | create_ap wlan0 eth0 echo -e "MyAccessPoint\nMyPassPhrase" | create_ap wlan0 eth0
### Enable IEEE 802.11n ### Enable IEEE 802.11n
create_ap --ieee80211n --ht_capab '[HT40+]' wlan0 eth0 MyAccessPoint MyPassPhrase create_ap --ieee80211n --ht_capab '[HT40+]' wlan0 eth0 MyAccessPoint MyPassPhrase
### Client Isolation: ### Client Isolation:
create_ap --isolate-clients wlan0 eth0 MyAccessPoint MyPassPhrase create_ap --isolate-clients wlan0 eth0 MyAccessPoint MyPassPhrase
### Assign IP address to a hosts listed in /etc/hosts:
create_ap --dhcp-hosts "host1 host2" wlan0 eth0 MyAccessPoint MyPassPhrase
### Assign IP address to two hosts not listed in /etc/hosts:
create_ap --dhcp-hosts "host1,192.168.12.2 host2,192.168.12.3" wlan0 eth0 MyAccessPoint MyPassPhrase
Use a space to separate multiple `dhcp-host` definitions. Reference [dnsmasq.conf.example](https://github.com/imp/dnsmasq/blob/770bce967cfc9967273d0acfb3ea018fb7b17522/dnsmasq.conf.example#L238) for other valid ways to define hosts, such as by MAC address.
## Systemd service ## Systemd service
Using the persistent [systemd](https://wiki.archlinux.org/index.php/systemd#Basic_systemctl_usage) service Using the persistent [systemd](https://wiki.archlinux.org/index.php/systemd#Basic_systemctl_usage) service
### Start service immediately: ### Start service immediately:
systemctl start create_ap systemctl start create_ap
### Start on boot: ### Start on boot:
systemctl enable create_ap systemctl enable create_ap
## License ## License
FreeBSD FreeBSD
- Copyright (c) 2013, oblique - Copyright (c) 2013, oblique
- Copyright (c) 2019, lakinduakash - Copyright (c) 2019, lakinduakash

View File

@ -14,7 +14,7 @@
# dnsmasq # dnsmasq
# iptables # iptables
VERSION=0.4.8 VERSION=0.4.9
PROGNAME="$(basename $0)" PROGNAME="$(basename $0)"
# make sure that all command outputs are in english # make sure that all command outputs are in english
@ -63,6 +63,11 @@ usage() {
echo " back to managed" echo " back to managed"
echo " --mac <MAC> Set MAC address" echo " --mac <MAC> Set MAC address"
echo " --dhcp-dns <IP1[,IP2]> Set DNS returned by DHCP" echo " --dhcp-dns <IP1[,IP2]> Set DNS returned by DHCP"
echo " --dhcp-hosts <H1[,H2]> Add list of dnsmasq.conf 'dhcp-host=' values"
echo " If ETC_HOSTS=1, it will use the ip addresses for the named hosts in that /etc/hosts."
echo " Othwise, the following syntax would work --dhcp-hosts \"host1,192.168.12.2 host2,192.168.12.3\""
echo " See https://github.com/imp/dnsmasq/blob/770bce967cfc9967273d0acfb3ea018fb7b17522/dnsmasq.conf.example#L238"
echo " for other valid dnsmasq dhcp-host parameters."
echo " --daemon Run create_ap in the background" echo " --daemon Run create_ap in the background"
echo " --pidfile <pidfile> Save daemon PID to file" echo " --pidfile <pidfile> Save daemon PID to file"
echo " --logfile <logfile> Save daemon messages to file" echo " --logfile <logfile> Save daemon messages to file"
@ -640,6 +645,7 @@ GATEWAY=192.168.12.1
WPA_VERSION=2 WPA_VERSION=2
ETC_HOSTS=0 ETC_HOSTS=0
ADDN_HOSTS= ADDN_HOSTS=
DHCP_HOSTS=
DHCP_DNS=gateway DHCP_DNS=gateway
NO_DNS=0 NO_DNS=0
NO_DNSMASQ=0 NO_DNSMASQ=0
@ -672,7 +678,7 @@ REDIRECT_TO_LOCALHOST=0
CONFIG_OPTS=(CHANNEL GATEWAY WPA_VERSION ETC_HOSTS DHCP_DNS NO_DNS NO_DNSMASQ HIDDEN MAC_FILTER MAC_FILTER_ACCEPT ISOLATE_CLIENTS CONFIG_OPTS=(CHANNEL GATEWAY WPA_VERSION ETC_HOSTS DHCP_DNS NO_DNS NO_DNSMASQ HIDDEN MAC_FILTER MAC_FILTER_ACCEPT ISOLATE_CLIENTS
SHARE_METHOD IEEE80211N IEEE80211AC IEEE80211AX HT_CAPAB VHT_CAPAB DRIVER NO_VIRT COUNTRY FREQ_BAND SHARE_METHOD IEEE80211N IEEE80211AC IEEE80211AX HT_CAPAB VHT_CAPAB DRIVER NO_VIRT COUNTRY FREQ_BAND
NEW_MACADDR DAEMONIZE DAEMON_PIDFILE DAEMON_LOGFILE DNS_LOGFILE NO_HAVEGED WIFI_IFACE INTERNET_IFACE NEW_MACADDR DAEMONIZE DAEMON_PIDFILE DAEMON_LOGFILE DNS_LOGFILE NO_HAVEGED WIFI_IFACE INTERNET_IFACE
SSID PASSPHRASE USE_PSK ADDN_HOSTS) SSID PASSPHRASE USE_PSK ADDN_HOSTS DHCP_HOSTS)
FIX_UNMANAGED=0 FIX_UNMANAGED=0
LIST_RUNNING=0 LIST_RUNNING=0
@ -1074,7 +1080,7 @@ for ((i=0; i<$#; i++)); do
fi fi
done done
GETOPT_ARGS=$(getopt -o hc:w:g:de:nm: -l "help","hidden","hostapd-debug:","hostapd-timestamps","redirect-to-localhost","mac-filter","mac-filter-accept:","isolate-clients","ieee80211n","ieee80211ac","ieee80211ax","ht_capab:","vht_capab:","driver:","no-virt","fix-unmanaged","country:","freq-band:","mac:","dhcp-dns:","daemon","pidfile:","logfile:","dns-logfile:","stop:","list","list-running","list-clients:","version","psk","no-haveged","no-dns","no-dnsmasq","mkconfig:","config:" -n "$PROGNAME" -- "$@") GETOPT_ARGS=$(getopt -o hc:w:g:de:nm: -l "help","hidden","hostapd-debug:","hostapd-timestamps","redirect-to-localhost","mac-filter","mac-filter-accept:","isolate-clients","ieee80211n","ieee80211ac","ieee80211ax","ht_capab:","vht_capab:","driver:","no-virt","fix-unmanaged","country:","freq-band:","mac:","dhcp-dns:","daemon","pidfile:","logfile:","dns-logfile:","stop:","list","list-running","list-clients:","version","psk","no-haveged","no-dns","no-dnsmasq","mkconfig:","config:","dhcp-hosts:" -n "$PROGNAME" -- "$@")
[[ $? -ne 0 ]] && exit 1 [[ $? -ne 0 ]] && exit 1
eval set -- "$GETOPT_ARGS" eval set -- "$GETOPT_ARGS"
@ -1130,6 +1136,11 @@ while :; do
ADDN_HOSTS="$1" ADDN_HOSTS="$1"
shift shift
;; ;;
--dhcp-hosts)
shift
DHCP_HOSTS="$1"
shift
;;
-n) -n)
shift shift
SHARE_METHOD=none SHARE_METHOD=none
@ -1796,6 +1807,13 @@ EOF
[[ -n "$MTU" ]] && echo "dhcp-option-force=option:mtu,${MTU}" >> $CONFDIR/dnsmasq.conf [[ -n "$MTU" ]] && echo "dhcp-option-force=option:mtu,${MTU}" >> $CONFDIR/dnsmasq.conf
[[ $ETC_HOSTS -eq 0 ]] && echo no-hosts >> $CONFDIR/dnsmasq.conf [[ $ETC_HOSTS -eq 0 ]] && echo no-hosts >> $CONFDIR/dnsmasq.conf
[[ -n "$ADDN_HOSTS" ]] && echo "addn-hosts=${ADDN_HOSTS}" >> $CONFDIR/dnsmasq.conf [[ -n "$ADDN_HOSTS" ]] && echo "addn-hosts=${ADDN_HOSTS}" >> $CONFDIR/dnsmasq.conf
if [[ -n "$DHCP_HOSTS" ]]; then
for HOST in $DHCP_HOSTS; do
echo "dhcp-host=${HOST}" >> $CONFDIR/dnsmasq.conf
done
fi
if [[ -n "$DNS_LOGFILE" ]]; then if [[ -n "$DNS_LOGFILE" ]]; then
cat << EOF >> $CONFDIR/dnsmasq.conf cat << EOF >> $CONFDIR/dnsmasq.conf
log-queries log-queries

View File

@ -27,3 +27,5 @@ INTERNET_IFACE=eth0
SSID=MyAccessPoint SSID=MyAccessPoint
PASSPHRASE=12345678 PASSPHRASE=12345678
USE_PSK=0 USE_PSK=0
DHCP_HOSTS=