我在FreeNAS上并在监狱中安装了OpenVPN。我想使用OpenVPN将端口移植到我的监狱。我按照这个guide使用OpenVPN进行了移植,但它不起作用。
#! /bin/bash
#
# Enable port forwarding
#
# Requirements:
# your Private Internet Access user and password as arguments
#
# Usage:
# ./port_forward.sh <user> <password>
error( )
{
echo "$@" 1>&2
exit 1
}
error_and_usage( )
{
echo "$@" 1>&2
usage_and_exit 1
}
usage( )
{
echo "Usage: `dirname $0`/$PROGRAM <user> <password>"
}
usage_and_exit( )
{
usage
exit $1
}
version( )
{
echo "$PROGRAM version $VERSION"
}
port_forward_assignment( )
{
echo 'Loading port forward assignment information..'
if [ "$(uname)" == "Linux" ]; then
if type ip >/dev/null 2>/dev/null; then
local_ip=`ip addr show tun0 | grep "inet " | head -n 1 | sed 's/^ *//g' | cut -d\ -f2 | tee /tmp/vpn_ip`
elif ifconfig tun0 | grep -oE "inet addr: "; then
local_ip=`ifconfig tun0 | grep -oE "inet addr: *10\.[0-9]+\.[0-9]+\.[0-9]+" | tr -d "a-z :" | tee /tmp/vpn_ip`
else
local_ip=`ifconfig tun0 | grep "inet " | sed 's/^ *//g' | cut -d\ -f2 | tee /tmp/vpn_ip`
fi
fi
if [ "$(uname)" == "Darwin" ]; then
local_ip=`ifconfig tun0 | grep "inet " | cut -d\ -f2|tee /tmp/vpn_ip`
fi
client_id=`cat /tmp/vpn_client_id`
json=`wget -q --post-data="user=$USER&pass=$PASSWORD&client_id=$client_id&local_ip=$local_ip" -O - 'https://www.privateinternetaccess.com/vpninfo/port_forward_assignment' | head -1`
echo $json
}
EXITCODE=0
PROGRAM=`basename $0`
VERSION=1.0
USER=$1
PASSWORD=$2
while test $# -lt 2
do
case $1 in
--usage | --help | -h )
usage_and_exit 0
;;
--version | -v )
version
exit 0
;;
*)
error_and_usage "Unrecognized option: $1"
;;
esac
shift
done
if [ ! -f /tmp/vpn_client_id ]; then
if [ "$(uname)" == "Linux" ]; then
echo head -n 100 /dev/urandom | md5sum | tr -d " -" >> /tmp/vpn_client_id
fi
if [ "$(uname)" == "Darwin" ]; then
echo head -n 100 /dev/urandom | md5 -r | tr -d " -" >> /tmp/vpn_client_id
fi
fi
port_forward_assignment
exit 0
起初我得到了一个未找到的命令&#34;错误,但那是因为shebang线的空间。然后,我编辑了脚本,现在我得到了一个不同的错误&#34;缺少重定向的名称&#34;。
root@transmission_1:/usr/local/etc/openvpn # ./port-forward.sh <myusername> <mypassword>
Missing name for redirect.
root@transmission_1:/usr/local/etc/openvpn # bash port-forward.sh <myusername> <mypassword>
Missing name for redirect.
root@transmission_1:/usr/local/etc/openvpn #
我读过这可能是因为我没有使用bash。但是,我尝试使用命令&#34; bash&#34;执行脚本。在行的开头,所以我认为我应该没问题,但它仍然输出相同的错误。作为一个注释,我使用&#34; jexec tranmission_1 tcsh&#34;登录监狱。命令。我还尝试在bash shell中登录jail,但后来我遇到了其他错误(语法蚀刻或错误的解释器)。
[root@freenas ~]# jexec transmission_1 bash
[root@transmission_1 /]# cd /usr/local/etc/openvpn
[root@transmission_1 /usr/local/etc/openvpn]# ./port_forward.sh <myusername> <mypassword>
bash: syntax error near unexpected token `<'
[root@transmission_1 /usr/local/etc/openvpn]# bash port_forward.sh <myusername> <mypassword>
bash: syntax error near unexpected token `<'
[root@transmission_1 /usr/local/etc/openvpn]# ./port_forward.sh myusername mypassword
bash: ./port_forward.sh: /bin/bash: bad interpreter: No such file or directory
[root@transmission_1 /usr/local/etc/openvpn]#
我真的不是一个程序员,但我设法在控制台做了一些事情。但是,我不知道如何处理这些错误。
首先,我应该使用tcsh还是bash登录?根据我的登录方式,我会遇到不同的错误。如果在tcsh中,如何传递&#34;缺少重定向错误的名称&#34;?
谢谢!