欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Linux上PPTP VPN的一键安装以及设置开机启动的方法

程序员文章站 2022-06-08 12:50:18
这篇文章主要介绍了Linux上PPTP VPN的一键安装以及设置开机启动的方法,作者分别附上了CentOS和Ubuntu/Debian下使用的安装脚本,需要的朋友可以参考下... 15-06-25...

设置pptp vpn 开机启动

有的人懒的重启后手动开启服务,所以下面我再补上开机自动启动pptp vpn 和 iptables的命令

 

复制代码
代码如下:
#chkconfig pptpd on //开机启动pptp vpn服务</p> <p>#chkconfig iptables on //开机启动iptables

贴个openvz的pptp vpn 一件安装包吧:centos,fedora,redhat  6.x 使用的脚本(vps上从没安装过的可以试试这个脚本):  

复制代码
代码如下:
#!/bin/bash
# interactive pptp vpn install script for an openvz vps
# surport : cenost ,fedora 6.x
# augest 24, 2014 v1.00
#url : http://www.dabu.info/?p=2178</p> <p>echo "######################################################"
echo "interactive poptop install script for an openvz vps"
echo
echo "make sure to contact your provider and have them enable"
echo "iptables and ppp modules prior to setting up poptop."
echo "ppp can also be enabled from solusvm."
echo
echo "you need to set up the server before creating more users."
echo "a separate user is required per connection or machine."
echo "######################################################"
echo
echo
echo "######################################################"
echo "select on option:"
echo "1) set up new poptop server and create one user"
echo "2) create additional users"
echo "######################################################"
read x
if test $x -eq 1; then
echo "enter username that you want to create (eg. client1 or john):"
read u
echo "specify password that you want the server to use:"
read p</p> <p>## get the vps ip
#ip=`ifconfig venet0:0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://`</p> <p>echo
echo "######################################################"
echo "downloading and installing ppp and pptpd "
echo "######################################################"
yum install ppp -y
rpm -uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
yum install pptpd -y</p> <p>echo
echo "######################################################"
echo "creating server config"
echo "######################################################"
cp /etc/ppp/options.pptpd /etc/ppp/options.pptpd.bak
sed -i '70a ms-dns 8.8.8.8' /etc/ppp/options.pptpd</p> <p></p> <p></p> <p>
# setting up pptpd.conf
sed -i '101a localip 192.168.9.1' /etc/pptpd.conf
sed -i '102a remoteip 192.168.9.11-30' /etc/pptpd.conf</p> <p># adding new user
echo "$u * $p *" >> /etc/ppp/chap-secrets</p> <p>echo
echo "######################################################"
echo "forwarding ipv4 and enabling it on boot"
echo "######################################################"
cat >> /etc/sysctl.conf <<end
net.ipv4.ip_forward=1
end
sysctl -p</p> <p>echo
echo "######################################################"
echo "updating iptables routing and enabling it on boot"
echo "######################################################"
iptables -t nat -a postrouting -o eth0 -j masquerade
# saves iptables routing rules and enables them on-boot
iptables-save > /etc/iptables.conf</p> <p>cat > /etc/network/if-pre-up.d/iptables <<end
#!/bin/sh
iptables-restore < /etc/iptables.conf
end</p> <p>chmod +x /etc/network/if-pre-up.d/iptables
cat >> /etc/ppp/ip-up <<end
ifconfig ppp0 mtu 1400
end</p> <p>echo
echo "######################################################"
echo "restarting poptop"
echo "######################################################"
sleep 5
/etc/init.d/pptpd restart</p> <p>echo
echo "######################################################"
echo "server setup complete!"
echo "connect to your vps at $ip with these credentials:"
echo "username:$u ##### password: $p"
echo "######################################################"</p> <p># runs this if option 2 is selected
elif test $x -eq 2; then
echo "enter username that you want to create (eg. client1 or john):"
read u
echo "specify password that you want the server to use:"
read p</p> <p></p> <p># adding new user
echo "$u * $p *" >> /etc/ppp/chap-secrets</p> <p>echo
echo "######################################################"
echo "addtional user added!"
echo "connect to your vps at $ip with these credentials:"
echo "username:$u ##### password: $p"
echo "######################################################"</p> <p>else
echo "invalid selection, quitting."
exit
fi

#!/bin/bash
# interactive pptp vpn install script for an openvz vps
# surport : cenost ,fedora 6.x
# augest 24, 2014 v1.00
#url : http://www.dabu.info/?p=2178

echo "######################################################"
echo "interactive poptop install script for an openvz vps"
echo
echo "make sure to contact your provider and have them enable"
echo "iptables and ppp modules prior to setting up poptop."
echo "ppp can also be enabled from solusvm."
echo
echo "you need to set up the server before creating more users."
echo "a separate user is required per connection or machine."
echo "######################################################"
echo
echo
echo "######################################################"
echo "select on option:"
echo "1) set up new poptop server and create one user"
echo "2) create additional users"
echo "######################################################"
read x
if test $x -eq 1; then
echo "enter username that you want to create (eg. client1 or john):"
read u
echo "specify password that you want the server to use:"
read p

## get the vps ip
#ip=`ifconfig venet0:0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://`

echo
echo "######################################################"
echo "downloading and installing ppp and pptpd "
echo "######################################################"
yum install ppp -y
rpm -uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
yum install pptpd -y

echo
echo "######################################################"
echo "creating server config"
echo "######################################################"
cp /etc/ppp/options.pptpd /etc/ppp/options.pptpd.bak
sed -i '70a ms-dns 8.8.8.8' /etc/ppp/options.pptpd






# setting up pptpd.conf
sed -i '101a localip 192.168.9.1' /etc/pptpd.conf
sed -i '102a remoteip 192.168.9.11-30' /etc/pptpd.conf

# adding new user
echo "$u * $p *" >> /etc/ppp/chap-secrets

echo
echo "######################################################"
echo "forwarding ipv4 and enabling it on boot"
echo "######################################################"
cat >> /etc/sysctl.conf <<end
net.ipv4.ip_forward=1
end
sysctl -p

echo
echo "######################################################"
echo "updating iptables routing and enabling it on boot"
echo "######################################################"
iptables -t nat -a postrouting -o eth0 -j masquerade
# saves iptables routing rules and enables them on-boot
iptables-save > /etc/iptables.conf

cat > /etc/network/if-pre-up.d/iptables <<end
#!/bin/sh
iptables-restore < /etc/iptables.conf
end

chmod +x /etc/network/if-pre-up.d/iptables
cat >> /etc/ppp/ip-up <<end
ifconfig ppp0 mtu 1400
end

echo
echo "######################################################"
echo "restarting poptop"
echo "######################################################"
sleep 5
/etc/init.d/pptpd restart

echo
echo "######################################################"
echo "server setup complete!"
echo "connect to your vps at $ip with these credentials:"
echo "username:$u ##### password: $p"
echo "######################################################"

# runs this if option 2 is selected
elif test $x -eq 2; then
echo "enter username that you want to create (eg. client1 or john):"
read u
echo "specify password that you want the server to use:"
read p



# adding new user
echo "$u * $p *" >> /etc/ppp/chap-secrets

echo
echo "######################################################"
echo "addtional user added!"
echo "connect to your vps at $ip with these credentials:"
echo "username:$u ##### password: $p"
echo "######################################################"

else
echo "invalid selection, quitting."
exit
fi</p> <p>

复制下面代码到install.sh中,然后 sh isntall.sh。这个是只支持debian和ubuntu系列,centos不支持。

 

复制代码
代码如下:

#!/bin/bash
# interactive poptop install script for an openvz vps
# tested on debian 5, 6, and ubuntu 11.04
# april 2, 2013 v1.11
# http://www.putdispenserhere.com/pptp-debian-ubuntu-openvz-setup-script/</p> <p>echo "######################################################"
echo "interactive poptop install script for an openvz vps"
echo
echo "make sure to contact your provider and have them enable"
echo "iptables and ppp modules prior to setting up poptop."
echo "ppp can also be enabled from solusvm."
echo
echo "you need to set up the server before creating more users."
echo "a separate user is required per connection or machine."
echo "######################################################"
echo
echo
echo "######################################################"
echo "select on option:"
echo "1) set up new poptop server and create one user"
echo "2) create additional users"
echo "######################################################"
read x
if test $x -eq 1; then
echo "enter username that you want to create (eg. client1 or john):"
read u
echo "specify password that you want the server to use:"
read p</p> <p># get the vps ip
ip=`ifconfig venet0:0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://`</p> <p>echo
echo "######################################################"
echo "downloading and installing poptop"
echo "######################################################"
apt-get update
apt-get -y install pptpd</p> <p>echo
echo "######################################################"
echo "creating server config"
echo "######################################################"
cat > /etc/ppp/pptpd-options <<end
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
ms-dns 8.8.8.8
ms-dns 8.8.4.4
proxyarp
nodefaultroute
lock
nobsdcomp
end</p> <p># setting up pptpd.conf
echo "option /etc/ppp/pptpd-options" > /etc/pptpd.conf
echo "logwtmp" >> /etc/pptpd.conf
echo "localip $ip" >> /etc/pptpd.conf
echo "remoteip 10.1.0.1-100" >> /etc/pptpd.conf</p> <p># adding new user
echo "$u * $p *" >> /etc/ppp/chap-secrets</p> <p>echo
echo "######################################################"
echo "forwarding ipv4 and enabling it on boot"
echo "######################################################"
cat >> /etc/sysctl.conf <<end
net.ipv4.ip_forward=1
end
sysctl -p</p> <p>echo
echo "######################################################"
echo "updating iptables routing and enabling it on boot"
echo "######################################################"
iptables -t nat -a postrouting -j snat --to $ip
# saves iptables routing rules and enables them on-boot
iptables-save > /etc/iptables.conf</p> <p>cat > /etc/network/if-pre-up.d/iptables <<end
#!/bin/sh
iptables-restore < /etc/iptables.conf
end</p> <p>chmod +x /etc/network/if-pre-up.d/iptables
cat >> /etc/ppp/ip-up <<end
ifconfig ppp0 mtu 1400
end</p> <p>echo
echo "######################################################"
echo "restarting poptop"
echo "######################################################"
sleep 5
/etc/init.d/pptpd restart</p> <p>echo
echo "######################################################"
echo "server setup complete!"
echo "connect to your vps at $ip with these credentials:"
echo "username:$u ##### password: $p"
echo "######################################################"</p> <p># runs this if option 2 is selected
elif test $x -eq 2; then
echo "enter username that you want to create (eg. client1 or john):"
read u
echo "specify password that you want the server to use:"
read p</p> <p># get the vps ip
ip=`ifconfig venet0:0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://`</p> <p># adding new user
echo "$u * $p *" >> /etc/ppp/chap-secrets</p> <p>echo
echo "######################################################"
echo "addtional user added!"
echo "connect to your vps at $ip with these credentials:"
echo "username:$u ##### password: $p"
echo "######################################################"</p> <p>else
echo "invalid selection, quitting."
exit
fi

#!/bin/bash
# interactive poptop install script for an openvz vps
# tested on debian 5, 6, and ubuntu 11.04
# april 2, 2013 v1.11
# http://www.putdispenserhere.com/pptp-debian-ubuntu-openvz-setup-script/

echo "######################################################"
echo "interactive poptop install script for an openvz vps"
echo
echo "make sure to contact your provider and have them enable"
echo "iptables and ppp modules prior to setting up poptop."
echo "ppp can also be enabled from solusvm."
echo
echo "you need to set up the server before creating more users."
echo "a separate user is required per connection or machine."
echo "######################################################"
echo
echo
echo "######################################################"
echo "select on option:"
echo "1) set up new poptop server and create one user"
echo "2) create additional users"
echo "######################################################"
read x
if test $x -eq 1; then
echo "enter username that you want to create (eg. client1 or john):"
read u
echo "specify password that you want the server to use:"
read p

# get the vps ip
ip=`ifconfig venet0:0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://`

echo
echo "######################################################"
echo "downloading and installing poptop"
echo "######################################################"
apt-get update
apt-get -y install pptpd

echo
echo "######################################################"
echo "creating server config"
echo "######################################################"
cat > /etc/ppp/pptpd-options <<end
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
ms-dns 8.8.8.8
ms-dns 8.8.4.4
proxyarp
nodefaultroute
lock
nobsdcomp
end

# setting up pptpd.conf
echo "option /etc/ppp/pptpd-options" > /etc/pptpd.conf
echo "logwtmp" >> /etc/pptpd.conf
echo "localip $ip" >> /etc/pptpd.conf
echo "remoteip 10.1.0.1-100" >> /etc/pptpd.conf

# adding new user
echo "$u * $p *" >> /etc/ppp/chap-secrets

echo
echo "######################################################"
echo "forwarding ipv4 and enabling it on boot"
echo "######################################################"
cat >> /etc/sysctl.conf <<end
net.ipv4.ip_forward=1
end
sysctl -p

echo
echo "######################################################"
echo "updating iptables routing and enabling it on boot"
echo "######################################################"
iptables -t nat -a postrouting -j snat --to $ip
# saves iptables routing rules and enables them on-boot
iptables-save > /etc/iptables.conf

cat > /etc/network/if-pre-up.d/iptables <<end
#!/bin/sh
iptables-restore < /etc/iptables.conf
end

chmod +x /etc/network/if-pre-up.d/iptables
cat >> /etc/ppp/ip-up <<end
ifconfig ppp0 mtu 1400
end

echo
echo "######################################################"
echo "restarting poptop"
echo "######################################################"
sleep 5
/etc/init.d/pptpd restart

echo
echo "######################################################"
echo "server setup complete!"
echo "connect to your vps at $ip with these credentials:"
echo "username:$u ##### password: $p"
echo "######################################################"

# runs this if option 2 is selected
elif test $x -eq 2; then
echo "enter username that you want to create (eg. client1 or john):"
read u
echo "specify password that you want the server to use:"
read p

# get the vps ip
ip=`ifconfig venet0:0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://`

# adding new user
echo "$u * $p *" >> /etc/ppp/chap-secrets

echo
echo "######################################################"
echo "addtional user added!"
echo "connect to your vps at $ip with these credentials:"
echo "username:$u ##### password: $p"
echo "######################################################"

else
echo "invalid selection, quitting."
exit
fi