X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=vpn-server-setup;h=a4b203bb7e6371021c1d40540df76e43377491a8;hb=05f5ee9aa2a7e237d28155f0330380ce610b0ccf;hp=312ddff11071a03c98cc9c174c5df60aaebd7a75;hpb=aa9be22d2798d15580907238cfdbf8f3ffd7364d;p=vpn-setup diff --git a/vpn-server-setup b/vpn-server-setup index 312ddff..a4b203b 100755 --- a/vpn-server-setup +++ b/vpn-server-setup @@ -27,19 +27,22 @@ usage: ${0##*/} [OPTIONS] [IPV6_ADDR/BITS] -6 IP6_NETWORK Do ip6 nat for this network. ipv6 will work without nat, but you may want it in certain circumstances. -d Do not push dns +-i INTERFACE_NAME name of tun interface -n NAME default = server. 2 servers on the same host need different names. -p PORT default 1194 -r Do not push default route -s Do not start openvpn -h --help print help +IPV6_ADDR/BITS Ipv6 address of the vpn interface. + Sets up a vpn server which pushes gateway route and dns server so all traffic goes through the vpn. requires systemd, and might have some debian specific paths. For ipv6, we assume ipv6_addr routes to the server. -You can save all the keys by storing /etc/openvpn/easy-rsa/keys, and +You can save all the keys by storing /etc/openvpn/easy-rsa-NAME/keys, and the script will not generate them if it sees they exist already. For future updates to this script, this is a good place to @@ -56,13 +59,14 @@ route=true start=true ip4=10.8.0 name=server -temp=$(getopt -l help 4:6:dn:p:rsh "$@") || usage 1 +temp=$(getopt -l help 4:6:di:n:p:rsh "$@") || usage 1 eval set -- "$temp" while true; do case $1 in -4) ip4=$2; shift 2 ;; -6) ip6net=$2; shift 2 ;; -d) dns=false; shift ;; + -i) ifname=$2; shift 2 ;; -n) name=$2; shift 2 ;; -p) port=$2; shift 2 ;; -r) route=false; shift ;; @@ -77,7 +81,7 @@ read -r ip6 ip6route <<<"$@" source /a/bin/distro-functions/src/package-manager-abstractions -pi-nostart openvpn openssl resolvconf easy-rsa uuid-runtime +pi-nostart openvpn openssl easy-rsa uuid-runtime if [[ -e /lib/systemd/system/openvpn-server@.service ]]; then vpn_service=openvpn-server@$name @@ -158,8 +162,12 @@ if ! $keys_exist; then fi fi - -gzip -dc /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz >$conf +if [[ -e /usr/share/doc/openvpn/examples/sample-config-files/server.conf ]]; then + cat /usr/share/doc/openvpn/examples/sample-config-files/server.conf >$conf +else + # pre-bullsye name + gzip -dc /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz >$conf +fi cafile=$server_dir/ca-$name.crt cp $ca_origin $cafile @@ -220,6 +228,12 @@ push "dhcp-option DNS $ip4.1" EOF fi +if [[ $ifname ]]; then + cat >>$conf <>$conf <