Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -e
- set -u
- set -x
- WIFI_INTERFACE=wlan0
- VIRT_WIFI_INTERFACE=wlan1
- BRIDGE_INTERFACE=br0
- ETH_INTERFACE=eth0
- IP_NET_PREFIX=10.0.0
- IP_NETMASK=255.255.255.0
- # Install Deps
- apt-get install -y --no-install-recommends \
- bridge-utils \
- crda \
- dnsmasq \
- haveged \
- hostapd \
- rng-tools
- # Set Wifi to good country
- iw reg set DE
- #Stop unused services/interfaces
- service hostapd stop
- service dnsmasq stop
- ifdown "${ETH_INTERFACE}" || : # Stop interface or nothing
- ifdown "${BRIDGE_INTERFACE}" || : # Stop interface or nothing
- # Create the "virtual" Wifi interface for access point
- [ $(iw dev | grep "${VIRT_WIFI_INTERFACE}" | wc -l) -eq 1 ] || \
- iw dev "${WIFI_INTERFACE}" interface add "${VIRT_WIFI_INTERFACE}" type __ap
- # Set the Ethernet interface in manual mode
- cat <<EOF >/etc/network/interfaces.d/eth0
- auto eth0
- iface eth0 inet manual
- EOF
- ifup "${ETH_INTERFACE}"
- # Create the bridge and associate the Ethernet to this
- cat <<EOF >/etc/network/interfaces.d/eth0
- auto ${BRIDGE_INTERFACE}
- iface ${BRIDGE_INTERFACE} inet static
- address ${IP_NET_PREFIX}.1
- netmask ${IP_NETMASK}
- network ${IP_NET_PREFIX}.0
- broadcast ${IP_NET_PREFIX}.255
- gateway ${IP_NET_PREFIX}.1
- bridge_ports ${ETH_INTERFACE}
- EOF
- ifup "${BRIDGE_INTERFACE}"
- # Configure hostpad to serve AP to "interface=" and be added to "bridge"
- cat <<EOF >> /etc/hostapd/hostapd.conf
- ssid=PI3
- wpa_passphrase=raspberry
- interface=${VIRT_WIFI_INTERFACE}
- bridge=${BRIDGE_INTERFACE}
- country_code=DE
- auth_algs=3
- channel=6
- driver=nl80211
- hw_mode=g
- max_num_sta=5
- rsn_pairwise=CCMP
- wpa=2
- wpa_key_mgmt=WPA-PSK
- wpa_pairwise=TKIP CCMP
- EOF
- echo 'DAEMON_CONF="/etc/hostapd/hostapd.conf"' >> /etc/default/hostapd
- # Configure dnsmasq
- mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bkp
- touch /etc/dnsmasq.conf
- echo "interface=${BRIDGE_INTERFACE}" >> /etc/dnsmasq.conf
- echo "dhcp-range=${IP_NET_PREFIX}.1,${IP_NET_PREFIX}.254,12h" >> /etc/dnsmasq.conf
- # Enable NAT and forwarding
- sysctl -w net.ipv4.ip_forward=1
- iptables -t nat -A POSTROUTING -j MASQUERADE
- # Start services
- service dnsmasq start
- service hostapd start
- sleep 5
- brctl show
- ip addr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement