# Configure firewall uci rename firewall.@zone[0]="lan" uci rename firewall.@zone[1]="wan" uci rename firewall.@forwarding[0]="lan_wan" uci del_list firewall.lan.device="tun0" uci add_list firewall.lan.device="tun0" uci -q delete firewall.vpn uci set firewall.ovpn="rule" uci set firewall.ovpn.name="Allow-OpenVPN" uci set firewall.ovpn.src="wan" uci set firewall.ovpn.dest_port="1194" uci set firewall.ovpn.proto="udp" uci set firewall.ovpn.target="ACCEPT" uci commit firewall /etc/init.d/firewall restart OpenWRT Firewall
生成服务器和客户端证书
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# Configuration parameters export EASYRSA_PKI="/etc/easy-rsa/pki" export EASYRSA_REQ_CN="ovpnca" # Remove and re-initialize the PKI directory easyrsa --batch init-pki # Generate DH parameters # 此步会较久 easyrsa --batch gen-dh # Create a new CA easyrsa --batch build-ca nopass # Generate a keypair and sign locally for a server easyrsa --batch build-server-full server nopass # Generate a keypair and sign locally for a client easyrsa --batch build-client-full client nopass
#!/bin/sh ########################################################### # checkpsw.sh (C) 2004 Mathias Sundman <mathias@openvpn.se> # # This script will authenticate OpenVPN users against # a plain text file. The passfile should simply contain # one row per user with the username first followed by # one or more space(s) or tab(s) and then the password.
if [ "${CORRECT_PASSWORD}" = "" ]; then echo "${TIME_STAMP}: User does not exist: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE} exit 1 fi
if [ "${password}" = "${CORRECT_PASSWORD}" ]; then echo "${TIME_STAMP}: Successful authentication: username=\"${username}\"." >> ${LOG_FILE} exit 0 fi
# Provide VPN instance management ls /etc/openvpn/*.conf \ | while read -r OVPN_CONF do OVPN_ID="$(basename ${OVPN_CONF%.*} | sed -e "s/\W/_/g")" uci -q delete openvpn.${OVPN_ID} uci set openvpn.${OVPN_ID}="openvpn" uci set openvpn.${OVPN_ID}.enabled="1" uci set openvpn.${OVPN_ID}.config="${OVPN_CONF}" done uci commit openvpn /etc/init.d/openvpn restart