Skip to content

Instantly share code, notes, and snippets.

@rqdaA

rqdaA/ap.sh Secret

Created March 21, 2024 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rqdaA/9fea933cc1512b881cf98a45eb0d3166 to your computer and use it in GitHub Desktop.
Save rqdaA/9fea933cc1512b881cf98a45eb0d3166 to your computer and use it in GitHub Desktop.
LinuxをAPにするやつ
#! /bin/bash
ETHER_DEV="eno2"
WIFI_DEV="wlo1"
DHCP_MASKED_IP="192.168.8.0/24"
ROUTER_IP="192.168.8.1/24"
if [ "$1" = "up" ]; then
sudo sysctl net.ipv4.ip_forward=1
sudo systemctl start iptables
sudo iptables -t nat -A POSTROUTING -s $DHCP_MASKED_IP -o $ETHER_DEV -j MASQUERADE
sudo ip addr add $ROUTER_IP dev $WIFI_DEV
sudo systemctl stop firewalld
sudo systemctl stop NetworkManager
sudo systemctl start hostapd
sudo systemctl start kea-dhcp4
elif [ "$1" = "down" ]; then
sudo sysctl net.ipv4.ip_forward=0
sudo systemctl stop iptables
sudo iptables -t nat -D POSTROUTING -s $DHCP_MASKED_IP -o $ETHER_DEV -j MASQUERADE
sudo ip addr flush dev $WIFI_DEV
sudo systemctl stop hostapd
sudo systemctl stop kea-dhcp4
sudo systemctl start firewalld
sudo systemctl start NetworkManager
else
echo "Usage: ./$0 [up | down]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment