H68K 2023款pro ,新玩具上一键部署路由和AP等功能

系统环境

root@hinlink-h68k:~# root@hinlink-h68k:~# uname -a
Linux hinlink-h68k 5.10.110-rk35xx #1 SMP Sun Mar 19 16:54:42 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

一个基于ubuntu系统的armbian系统

#!/bin/bash
usage() {
	echo "用法: sh 执行脚本.sh [instll|status|install_ssh]"
	exit 1
}

status(){
echo "更新软件包"
apt-get update
}
install_ssh(){
echo "正在安装ssh密钥"
}
install(){
echo "更新软件包"
apt-get update
echo "正在安装isc-dhcp-server hostapd iptables-persistent"
apt-get install isc-dhcp-server hostapd iptables-persistent -y

echo "配置路由和AP"

echo "正在替换forward配置/etc/sysctl.conf"
sed -i '/net.ipv4.ip_forward/d;$a\net.ipv4.ip_forward=1' /etc/sysctl.conf
sed -i '/net.ipv6.conf.all.forwarding/d;$a\net.ipv6.conf.all.forwarding=1' /etc/sysctl.conf
echo "正在覆盖配置/etc/netplan/armbian-default.yaml"
sudo sh -c "echo 'network:
    version: 2
    renderer: NetworkManager
    ethernets:
        eth0:
            dhcp4: yes
            #nameservers:
            #    addresses:
            #    - 114.114.114.114
            #    - 8.8.8.8
        eth1:
            dhcp4: no
            addresses:
            - 192.168.1.1/24
            dhcp4: false
        enP2p33s0:
            dhcp4: no
            addresses:
            - 192.168.3.1/24
            dhcp4: false
        enP1p17s0:
            dhcp4: no
            addresses:
            - 192.168.2.1/24
            dhcp4: false' > /etc/netplan/armbian-default.yaml"

echo "追加配置/etc/dhcp/dhcpd.conf"

sudo sh -c "echo '
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.10 192.168.1.233;
  option routers 192.168.1.1;
}
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.2.255;
subnet 192.168.2.0 netmask 255.255.255.0 {
  range 192.168.2.10 192.168.2.233;
  option routers 192.168.2.1;
}
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.3.255;
subnet 192.168.3.0 netmask 255.255.255.0 {
  range 192.168.3.10 192.168.3.233;
  option routers 192.168.3.1;
}

option subnet-mask 255.255.255.0;
option broadcast-address 192.168.0.255;
subnet 192.168.0.0 netmask 255.255.255.0 {
  range 192.168.0.10 192.168.0.233;
  option routers 192.168.0.1;
}
' >> /etc/dhcp/dhcpd.conf"
sed -i '/ns1.example.org/d;$a\option domain-name-servers 114.114.114.114,114.114.114.114;' /etc/dhcp/dhcpd.conf

echo "替换监听接口配置 /etc/default/isc-dhcp-server"
sed -i '/INTERFACESv4/d;$a\INTERFACESv4="eth1 enP2p33s0 enP1p17s0"' /etc/default/isc-dhcp-server
sed -i '/INTERFACESv6/d;$a\INTERFACESv6="eth1 enP2p33s0 enP1p17s0"' /etc/default/isc-dhcp-server


echo "设置网络NAT"
sudo iptables -F
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo "正在保存规则配置"
iptables-save > /etc/iptables/rules.v4
#echo "正在设置为开机配置"
#sh -c "echo '
#auto eth0
#iface eth0 inet dhcp
#  pre-up iptables-restore < /etc/iptables/rules.v4
#' >> /etc/network/interfaces"

sh -c "echo '

#ETH1
auto eth1
allow-hotplug eth1
iface eth1 inet static
    address 192.168.1.1/24

#ETH3
auto enP1p17s0
allow-hotplug enP1p17s0
iface enP1p17s0 inet static
    address 192.168.2.1/24

#ETH2
auto enP2p33s0
allow-hotplug enP2p33s0
iface enP2p33s0 inet static
    address 192.168.3.1/24
#有线网卡
auto wlp1s0
allow-hotplug wlp1s0
iface wlp1s0 inet static
    address 192.168.0.1
    netmask 255.255.255.0
    gateway 192.168.0.1
	
' >> /etc/network/interfaces"

echo "正在配置hostapd"
sh -c "echo '
interface=wlp1s0
driver=nl80211
hw_mode=a
ieee80211n=1
ieee80211ac=1
ieee80211d=1
ieee80211h=1
require_ht=1
require_vht=1
wmm_enabled=1
country_code=US
vht_oper_chwidth=1
channel=149
vht_oper_centr_freq_seg0_idx=155
ht_capab=[HT40-][HT40+][SHORT-GI-40][DSSS_CCK-40]
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
#WIFI名称
ssid=AP
#WIFI名密码
wpa_passphrase=12345678

' > /etc/hostapd/hostapd.conf"
echo "执行生效"
netplan apply
sed -i '/DAEMON_CONF/d;$a\DAEMON_CONF="/etc/hostapd/hostapd.conf"' /etc/default/hostapd
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
echo "WIFI:AP"
echo "密码:12345678"
echo "重启"
reboot
}
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
	"install")
		install
		;;
	"install_ssh")
		install_ssh
		;;
	"status")
		status
		;;
	*)
		usage
		;;
esac

猜你喜欢

转载自blog.csdn.net/u013833472/article/details/130397932