Advertisement
Guest User

Untitled

a guest
May 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -e
  4. set -u
  5. set -x
  6.  
  7. WIFI_INTERFACE=wlan0
  8. VIRT_WIFI_INTERFACE=wlan1
  9. BRIDGE_INTERFACE=br0
  10. ETH_INTERFACE=eth0
  11. IP_NET_PREFIX=10.0.0
  12. IP_NETMASK=255.255.255.0
  13.  
  14. # Install Deps
  15. apt-get install -y --no-install-recommends \
  16. bridge-utils \
  17. crda \
  18. dnsmasq \
  19. haveged \
  20. hostapd \
  21. rng-tools
  22.  
  23. # Set Wifi to good country
  24. iw reg set DE
  25.  
  26. #Stop unused services/interfaces
  27. service hostapd stop
  28. service dnsmasq stop
  29. ifdown "${ETH_INTERFACE}" || : # Stop interface or nothing
  30. ifdown "${BRIDGE_INTERFACE}" || : # Stop interface or nothing
  31.  
  32. # Create the "virtual" Wifi interface for access point
  33. [ $(iw dev | grep "${VIRT_WIFI_INTERFACE}" | wc -l) -eq 1 ] || \
  34. iw dev "${WIFI_INTERFACE}" interface add "${VIRT_WIFI_INTERFACE}" type __ap
  35.  
  36. # Set the Ethernet interface in manual mode
  37. cat <<EOF >/etc/network/interfaces.d/eth0
  38. auto eth0
  39. iface eth0 inet manual
  40. EOF
  41.  
  42. ifup "${ETH_INTERFACE}"
  43.  
  44. # Create the bridge and associate the Ethernet to this
  45. cat <<EOF >/etc/network/interfaces.d/eth0
  46. auto ${BRIDGE_INTERFACE}
  47. iface ${BRIDGE_INTERFACE} inet static
  48. address ${IP_NET_PREFIX}.1
  49. netmask ${IP_NETMASK}
  50. network ${IP_NET_PREFIX}.0
  51. broadcast ${IP_NET_PREFIX}.255
  52. gateway ${IP_NET_PREFIX}.1
  53. bridge_ports ${ETH_INTERFACE}
  54. EOF
  55.  
  56. ifup "${BRIDGE_INTERFACE}"
  57.  
  58. # Configure hostpad to serve AP to "interface=" and be added to "bridge"
  59. cat <<EOF >> /etc/hostapd/hostapd.conf
  60. ssid=PI3
  61. wpa_passphrase=raspberry
  62. interface=${VIRT_WIFI_INTERFACE}
  63. bridge=${BRIDGE_INTERFACE}
  64. country_code=DE
  65. auth_algs=3
  66. channel=6
  67. driver=nl80211
  68. hw_mode=g
  69. max_num_sta=5
  70. rsn_pairwise=CCMP
  71. wpa=2
  72. wpa_key_mgmt=WPA-PSK
  73. wpa_pairwise=TKIP CCMP
  74. EOF
  75. echo 'DAEMON_CONF="/etc/hostapd/hostapd.conf"' >> /etc/default/hostapd
  76.  
  77. # Configure dnsmasq
  78. mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bkp
  79. touch /etc/dnsmasq.conf
  80. echo "interface=${BRIDGE_INTERFACE}" >> /etc/dnsmasq.conf
  81. echo "dhcp-range=${IP_NET_PREFIX}.1,${IP_NET_PREFIX}.254,12h" >> /etc/dnsmasq.conf
  82.  
  83. # Enable NAT and forwarding
  84. sysctl -w net.ipv4.ip_forward=1
  85. iptables -t nat -A POSTROUTING -j MASQUERADE
  86.  
  87. # Start services
  88. service dnsmasq start
  89. service hostapd start
  90.  
  91. sleep 5
  92.  
  93. brctl show
  94. ip addr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement