Skip to content

Instantly share code, notes, and snippets.

@totti2
Last active April 7, 2018 16:16
Show Gist options
  • Save totti2/e59c1bbf5c2e5ea3c52dc36cf12c8276 to your computer and use it in GitHub Desktop.
Save totti2/e59c1bbf5c2e5ea3c52dc36cf12c8276 to your computer and use it in GitHub Desktop.

Revisions

  1. totti2 revised this gist Apr 2, 2018. No changes.
  2. totti2 revised this gist Apr 2, 2018. No changes.
  3. totti2 revised this gist Apr 2, 2018. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions ap_config.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    ```
    #!/bin/bash
    if [ "$WIFIPASS" == "" ]
    then
    @@ -31,7 +30,7 @@ save_original /etc/dhcpcd.conf
    + static ip_address=192.168.1.1/24
    EOT

    #
    # Not necessary, but in case someone needs it:
    # BRIDGE
    #
    #save_original /etc/network/interfaces
    @@ -129,9 +128,10 @@ save_original /etc/rc.local
    exit 0
    EOT

    #sudo brctl addbr br0
    #sudo brctl addif br0 eth0
    # Not necessary, but in case someone needs it:
    # BRIDGE
    #
    # sudo brctl addbr br0
    # sudo brctl addif br0 eth0
    sudo systemctl start hostapd
    sudo systemctl start dnsmasq
    ```
    sudo systemctl start dnsmasq
  4. totti2 revised this gist Apr 1, 2018. 1 changed file with 24 additions and 26 deletions.
    50 changes: 24 additions & 26 deletions ap_config.sh
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@ then
    source dependencies.sh
    fi
    sudo systemctl stop dhcpcd
    sudo systemctl stop dnsmasq
    sudo systemctl stop hostapd
    @@ -22,43 +23,40 @@ sudo systemctl stop hostapd
    #
    save_original /etc/dhcpcd.conf
    exc patch /etc/dhcpcd.conf <<EOT
    @@ -55,3 +55,7 @@
    @@ -55,3 +55,5 @@
    #interface eth0
    #fallback static_eth0
    +denyinterfaces wlan1
    +denyinterfaces eth0
    +interface wlan1
    + static ip_address=192.168.1.1/24
    EOT
    #
    # BRIDGE
    #
    save_original /etc/network/interfaces
    exc patch /etc/network/interfaces <<EOT
    @@ -5,3 +5,8 @@
    # Include files from /etc/network/interfaces.d:
    source-directory /etc/network/interfaces.d
    +
    +# Bridge setup
    +auto br0
    +iface br0 inet manual
    +bridge_ports eth0 wlan1
    EOT
    #
    # BRIDGE
    #
    #save_original /etc/network/interfaces
    # exc patch /etc/network/interfaces <<EOT
    #@@ -5,3 +5,8 @@
    #
    # # Include files from /etc/network/interfaces.d:
    # source-directory /etc/network/interfaces.d
    #+
    #+# Bridge setup
    #+auto br0
    #+iface br0 inet manual
    #+bridge_ports eth0 wlan1
    #EOT
    sudo service dhcpcd restart
    sudo service dhcpcd start
    #
    # ACCES POINT
    #
    save_original /etc/hostapd/hostapd.conf
    exc patch /etc/hostapd/hostapd.conf <<EOT
    @@ -0,0 +1,17 @@
    @@ -0,0 +1,16 @@
    +interface=wlan1
    +bridge=br0
    +#driver=nl80211
    +driver=nl80211
    +ssid=$APName
    +hw_mode=g
    +channel=6
    @@ -70,8 +68,8 @@ save_original /etc/hostapd/hostapd.conf
    +wpa_key_mgmt=WPA-PSK
    +#wpa_pairwise=TKIP # You better do not use this weak encryption (only used by old client devices
    +rsn_pairwise=CCMP
    +ieee80211n=1 # 802.11n support
    +wmm_enabled=1 # QoS support
    +ieee80211n=1
    +wmm_enabled=1
    +ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
    EOT
    @@ -132,8 +130,8 @@ save_original /etc/rc.local
    EOT
    sudo brctl addbr br0
    sudo brctl addif br0 eth0
    #sudo brctl addbr br0
    #sudo brctl addif br0 eth0
    sudo systemctl start hostapd
    sudo systemctl start dnsmasq
    ```
  5. totti2 revised this gist Mar 22, 2018. No changes.
  6. totti2 revised this gist Mar 22, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ap_config.sh
    Original file line number Diff line number Diff line change
    @@ -57,8 +57,8 @@ save_original /etc/hostapd/hostapd.conf
    exc patch /etc/hostapd/hostapd.conf <<EOT
    @@ -0,0 +1,17 @@
    +interface=wlan1
    +bridge=br0 #
    +#driver=nl80211 #
    +bridge=br0
    +#driver=nl80211
    +ssid=$APName
    +hw_mode=g
    +channel=6
  7. totti2 revised this gist Mar 22, 2018. 1 changed file with 64 additions and 57 deletions.
    121 changes: 64 additions & 57 deletions ap_config.sh
    Original file line number Diff line number Diff line change
    @@ -14,58 +14,59 @@ fi
    sudo systemctl stop dnsmasq
    sudo systemctl stop hostapd
    # setup the config files
    save_original /etc/network/interfaces
    #exc cp etc/network/interfaces /etc/network/interfaces # depreciated in stretch
    # set static IP for wifi device
    # ======================
    # SETUP THE CONFIG FILES
    # ======================
    #
    # STATIC IP / BRIDGE
    #
    save_original /etc/dhcpcd.conf
    #exc patch /etc/dhcpcd.conf <<EOT # worked without this patch
    #@@ -39,3 +39,4 @@
    # # A hook script is provided to lookup the hostname if not set by the DHCP
    # # server, but it should not be run by default
    # nohook lookup-hostname
    #+denyinterfaces wlan0
    exc patch /etc/dhcpcd.conf <<EOT
    @@ -55,3 +55,5 @@
    exc patch /etc/dhcpcd.conf <<EOT
    @@ -55,3 +55,7 @@
    #interface eth0
    #fallback static_eth0
    +interface wlan1 # wlan0 for internal wifi-device
    +denyinterfaces wlan1
    +denyinterfaces eth0
    +interface wlan1
    + static ip_address=192.168.1.1/24
    EOT
    sudo service dhcpcd restart
    #save_original /etc/init.d/hostapd
    #exc patch /etc/init.d/hostapd <<EOT
    #@@ -16,7 +16,7 @@
    # PATH=/sbin:/bin:/usr/sbin:/usr/bin
    # DAEMON_SBIN=/usr/sbin/hostapd
    # DAEMON_DEFS=/etc/default/hostapd
    #-DAEMON_CONF=
    #+DAEMON_CONF=/etc/hostapd/hostapd.conf
    # NAME=hostapd
    # DESC="advanced IEEE 802.11 management"
    # PIDFILE=/run/hostapd.pid
    #EOT
    #
    # BRIDGE
    #
    save_original /etc/network/interfaces
    exc patch /etc/network/interfaces <<EOT
    @@ -5,3 +5,8 @@
    # Include files from /etc/network/interfaces.d:
    source-directory /etc/network/interfaces.d
    +
    +# Bridge setup
    +auto br0
    +iface br0 inet manual
    +bridge_ports eth0 wlan1
    EOT
    sudo service dhcpcd restart
    # Setup AP
    #
    # ACCES POINT
    #
    save_original /etc/hostapd/hostapd.conf
    exc patch /etc/hostapd/hostapd.conf <<EOT
    @@ -0,0 +1,18 @@
    exc patch /etc/hostapd/hostapd.conf <<EOT
    @@ -0,0 +1,17 @@
    +interface=wlan1
    +driver=nl80211
    +#ssid=$APName
    +ssid=BusFunk
    +bridge=br0 #
    +#driver=nl80211 #
    +ssid=$APName
    +hw_mode=g
    +channel=6
    +macaddr_acl=0
    +auth_algs=1
    +ignore_broadcast_ssid=0
    +wpa=2
    +#wpa_passphrase=$WIFIPASS
    +wpa_passphrase=BassFank
    +wpa_passphrase=$WIFIPASS
    +wpa_key_mgmt=WPA-PSK
    +#wpa_pairwise=TKIP # You better do not use this weak encryption (only used by old client devices
    +rsn_pairwise=CCMP
    @@ -74,38 +75,38 @@ exc patch /etc/hostapd/hostapd.conf <<EOT
    +ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
    EOT
    save_original /etc/default/hostapd.conf
    exc patch /etc/default/hostapd.conf <<EOT
    @@ -16,7 +16,7 @@
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON_SBIN=/usr/sbin/hostapd
    DAEMON_DEFS=/etc/default/hostapd
    -DAEMON_CONF=
    +DAEMON_CONF=/etc/hostapd/hostapd.conf
    NAME=hostapd
    DESC="advanced IEEE 802.11 management"
    PIDFILE=/run/hostapd.pid
    save_original /etc/default/hostapd
    exc patch /etc/default/hostapd <<EOT
    @@ -7,7 +7,7 @@
    # file and hostapd will be started during system boot. An example configuration
    # file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz
    #
    -#DAEMON_CONF=""
    +DAEMON_CONF="/etc/hostapd/hostapd.conf"
    # Additional daemon options to be appended to hostapd command:-
    # -d show more debug messages (-dd for even more)
    EOT
    # Setup dhcp server
    #
    # DHCP-SERVER
    #
    save_original /etc/dnsmasq.conf
    exc patch /etc/dnsmasq.conf <<EOT
    @@ -668,3 +668,7 @@
    exc patch /etc/dnsmasq.conf <<EOT
    @@ -668,3 +668,6 @@
    # Delays sending DHCPOFFER and proxydhcp replies for at least the specified number of seconds.
    dhcp-mac=set:client_is_a_pi,B8:27:EB:*:*:*
    dhcp-reply-delay=tag:client_is_a_pi,2
    +
    +interface=wlan1 # Use the require wireless interface - usually wlan0
    + dhcp-range=192.168.1.2,192.168.1.20,255.255.255.0,24h
    +
    EOT
    sudo systemctl start hostapd
    sudo systemctl start dnsmasq
    # Add routing and masquerade
    #
    # ROUTING AND MASQUERADE
    #
    save_original /etc/sysctl.conf
    exc patch /etc/sysctl.conf <<EOT
    exc patch /etc/sysctl.conf <<EOT
    @@ -25,7 +25,7 @@
    #net.ipv4.tcp_syncookies=1
    @@ -121,12 +122,18 @@ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
    save_original /etc/rc.local
    exc patch /etc/rc.local <<EOT
    exc patch /etc/rc.local <<EOT
    @@ -17,4 +17,5 @@
    printf "My IP address is %s\n" "$_IP"
    fi
    +iptables-restore < /etc/iptables.ipv4.nat
    exit 0
    EOT
    sudo brctl addbr br0
    sudo brctl addif br0 eth0
    sudo systemctl start hostapd
    sudo systemctl start dnsmasq
    ```
  8. totti2 revised this gist Mar 21, 2018. 1 changed file with 0 additions and 40 deletions.
    40 changes: 0 additions & 40 deletions ap_config.sh
    Original file line number Diff line number Diff line change
    @@ -129,44 +129,4 @@ exc patch /etc/rc.local <<EOT
    +iptables-restore < /etc/iptables.ipv4.nat
    exit 0
    EOT
    #save_original /etc/dhcp/dhcpd.conf
    #exc cat <<EOT >>/etc/dhcp/dhcpd.conf # different approach in stretch
    #ddns-update-style none;
    #ignore client-updates;
    #authoritative;
    #option local-wpad code 252 = text;
    #
    #subnet
    #10.0.0.0 netmask 255.255.255.0 {
    ## --- default gateway
    #option routers
    #10.0.0.1;
    ## --- Netmask
    #option subnet-mask
    #255.255.255.0;
    ## --- Broadcast Address
    #option broadcast-address
    #10.0.0.255;
    ## --- Domain name servers, tells the clients which DNS servers to use.
    #option domain-name-servers
    #10.0.0.1, 8.8.8.8, 8.8.4.4;
    #option time-offset
    #0;
    #range 10.0.0.3 10.0.0.13;
    #default-lease-time 1209600;
    #max-lease-time 1814400;
    #}
    #EOT
    # Add Patch for /etc/default/isc-dhcp-server # use dnsmasq instead
    #save_original /etc/default/isc-dhcp-server
    #exc patch /etc/default/isc-dhcp-server <<EOT
    #@@ -18,4 +18,4 @@
    #
    # # On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
    # # Separate multiple interfaces with spaces, e.g. "eth0 eth1".
    #-INTERFACES=""
    #+INTERFACES="wlan0"
    #EOT
    ```
  9. totti2 renamed this gist Mar 21, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. totti2 renamed this gist Mar 19, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. totti2 created this gist Mar 19, 2018.
    172 changes: 172 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,172 @@
    ```
    #!/bin/bash
    if [ "$WIFIPASS" == "" ]
    then
    read -p "Wifi Network name: " APName
    read -p "Wifi Password: " WIFIPASS
    fi
    if [ -z "$exc" ]
    then
    source functions.sh
    source dependencies.sh
    fi

    sudo systemctl stop dnsmasq
    sudo systemctl stop hostapd

    # setup the config files

    save_original /etc/network/interfaces
    #exc cp etc/network/interfaces /etc/network/interfaces # depreciated in stretch

    # set static IP for wifi device
    save_original /etc/dhcpcd.conf
    #exc patch /etc/dhcpcd.conf <<EOT # worked without this patch
    #@@ -39,3 +39,4 @@
    # # A hook script is provided to lookup the hostname if not set by the DHCP
    # # server, but it should not be run by default
    # nohook lookup-hostname
    #+denyinterfaces wlan0
    exc patch /etc/dhcpcd.conf <<EOT
    @@ -55,3 +55,5 @@
    #interface eth0
    #fallback static_eth0

    +interface wlan1 # wlan0 for internal wifi-device
    + static ip_address=192.168.1.1/24
    EOT
    sudo service dhcpcd restart

    #save_original /etc/init.d/hostapd
    #exc patch /etc/init.d/hostapd <<EOT
    #@@ -16,7 +16,7 @@
    # PATH=/sbin:/bin:/usr/sbin:/usr/bin
    # DAEMON_SBIN=/usr/sbin/hostapd
    # DAEMON_DEFS=/etc/default/hostapd
    #-DAEMON_CONF=
    #+DAEMON_CONF=/etc/hostapd/hostapd.conf
    # NAME=hostapd
    # DESC="advanced IEEE 802.11 management"
    # PIDFILE=/run/hostapd.pid
    #EOT

    # Setup AP
    save_original /etc/hostapd/hostapd.conf
    exc patch /etc/hostapd/hostapd.conf <<EOT
    @@ -0,0 +1,18 @@
    +interface=wlan1
    +driver=nl80211
    +#ssid=$APName
    +ssid=BusFunk
    +hw_mode=g
    +channel=6
    +macaddr_acl=0
    +auth_algs=1
    +ignore_broadcast_ssid=0
    +wpa=2
    +#wpa_passphrase=$WIFIPASS
    +wpa_passphrase=BassFank
    +wpa_key_mgmt=WPA-PSK
    +#wpa_pairwise=TKIP # You better do not use this weak encryption (only used by old client devices
    +rsn_pairwise=CCMP
    +ieee80211n=1 # 802.11n support
    +wmm_enabled=1 # QoS support
    +ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
    EOT

    save_original /etc/default/hostapd.conf
    exc patch /etc/default/hostapd.conf <<EOT
    @@ -16,7 +16,7 @@
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON_SBIN=/usr/sbin/hostapd
    DAEMON_DEFS=/etc/default/hostapd
    -DAEMON_CONF=
    +DAEMON_CONF=/etc/hostapd/hostapd.conf
    NAME=hostapd
    DESC="advanced IEEE 802.11 management"
    PIDFILE=/run/hostapd.pid
    EOT

    # Setup dhcp server
    save_original /etc/dnsmasq.conf
    exc patch /etc/dnsmasq.conf <<EOT
    @@ -668,3 +668,7 @@
    # Delays sending DHCPOFFER and proxydhcp replies for at least the specified number of seconds.
    dhcp-mac=set:client_is_a_pi,B8:27:EB:*:*:*
    dhcp-reply-delay=tag:client_is_a_pi,2
    +
    +interface=wlan1 # Use the require wireless interface - usually wlan0
    + dhcp-range=192.168.1.2,192.168.1.20,255.255.255.0,24h
    +
    EOT

    sudo systemctl start hostapd
    sudo systemctl start dnsmasq

    # Add routing and masquerade
    save_original /etc/sysctl.conf
    exc patch /etc/sysctl.conf <<EOT
    @@ -25,7 +25,7 @@
    #net.ipv4.tcp_syncookies=1

    # Uncomment the next line to enable packet forwarding for IPv4
    -#net.ipv4.ip_forward=1
    +net.ipv4.ip_forward=1

    # Uncomment the next line to enable packet forwarding for IPv6
    # Enabling this option disables Stateless Address Autoconfiguration
    EOT

    sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

    save_original /etc/rc.local
    exc patch /etc/rc.local <<EOT
    @@ -17,4 +17,5 @@
    printf "My IP address is %s\n" "$_IP"
    fi

    +iptables-restore < /etc/iptables.ipv4.nat
    exit 0
    EOT

    #save_original /etc/dhcp/dhcpd.conf
    #exc cat <<EOT >>/etc/dhcp/dhcpd.conf # different approach in stretch
    #ddns-update-style none;
    #ignore client-updates;
    #authoritative;
    #option local-wpad code 252 = text;
    #
    #subnet
    #10.0.0.0 netmask 255.255.255.0 {
    ## --- default gateway
    #option routers
    #10.0.0.1;
    ## --- Netmask
    #option subnet-mask
    #255.255.255.0;
    ## --- Broadcast Address
    #option broadcast-address
    #10.0.0.255;
    ## --- Domain name servers, tells the clients which DNS servers to use.
    #option domain-name-servers
    #10.0.0.1, 8.8.8.8, 8.8.4.4;
    #option time-offset
    #0;
    #range 10.0.0.3 10.0.0.13;
    #default-lease-time 1209600;
    #max-lease-time 1814400;
    #}
    #EOT

    # Add Patch for /etc/default/isc-dhcp-server # use dnsmasq instead
    #save_original /etc/default/isc-dhcp-server
    #exc patch /etc/default/isc-dhcp-server <<EOT
    #@@ -18,4 +18,4 @@
    #
    # # On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
    # # Separate multiple interfaces with spaces, e.g. "eth0 eth1".
    #-INTERFACES=""
    #+INTERFACES="wlan0"
    #EOT
    ```