47 lines
1.3 KiB
Bash
Executable File
47 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# call by install.sh
|
|
|
|
# install package
|
|
apt-get install -y hostapd dnsmasq
|
|
|
|
# disable *dhcpcd* *wlan0* interface
|
|
if [ -z "$(grep denyinterfaces /etc/dhcpcd.conf)" ] ; then
|
|
echo 'denyinterfaces wlan0' >> /etc/dhcpcd.conf
|
|
fi
|
|
|
|
# edit network interface
|
|
mkdir -p /etc/network/interfaces.d
|
|
cp -f etc/network/interfaces.d/wlan0 /etc/network/interfaces.d/wlan0
|
|
|
|
# configure hostapd
|
|
if [ ! -f /etc/hostapd/hostapd.conf ]; then
|
|
cp -f etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf
|
|
fi
|
|
sed -i 's|^#\?DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|' /etc/default/hostapd
|
|
|
|
# configure dnsmasq
|
|
if [ -f /etc/dnsmasq.conf ]; then
|
|
mv -f /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
|
|
fi
|
|
|
|
cp -f etc/dnsmasq.conf /etc/dnsmasq.conf
|
|
|
|
# enable IPv4 forwarding
|
|
sed -i 's|^#\?net.ipv4.ip_forward=.*|net.ipv4.ip_forward=1|' /etc/sysctl.conf
|
|
|
|
# iptables
|
|
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
|
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
|
|
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
|
|
iptables-save > /etc/iptables.ipv4.nat
|
|
|
|
# iptables restore on boot
|
|
sed -i '/exit 0/i\
|
|
iptables-restore < /etc/iptables.ipv4.nat' /etc/rc.local
|
|
|
|
# enable service
|
|
systemctl unmask hostapd.service
|
|
systemctl enable hostapd.service
|
|
systemctl enable dnsmasq.service
|