CentOS OpenVPN一键安装包

rpm -q rpmforge-release

rpm -e rpmforge-release-0.5.1-1.el5.rf

 

新版 selinux 解决方案

 

semanage port -m -t openvpn_port_t -p tcp 443

 

semanage port -a -t openvpn_port_t -p udp 443




semanage port -l | grep 443

发现 http_port_t 占用 443

[root@xxxx ~]# semanage port -d -t http_port_t -p tcp 443
/usr/sbin/semanage: Port tcp/443 is defined in policy, cannot be deleted

 

[root@onion ~]# semanage port -a -t openvpn_port_t -p tcp 443
/usr/sbin/semanage: Port tcp/443 already defined

 

[root@onion ~]# /usr/sbin/semanage port -m -t openvpn_port_t -p tcp 443


开机启动


chkconfig openvpn on


MTU 设置 客户端 服务器 都需要


tun-mtu 1400
tun-mtu-extra 32
mssfix 1400



安装时候 注意 openvpn 版本

打开 sh 文件 更改 cp -R /usr/share/doc/openvpn-2.2.0/easy-rsa/ /etc/openvpn/

openvpn-2.2.0 为 当前版本好码 否则无法安装

 

 

下面这个也是一键安装包,跟上面那个不同的是,这个同时开启TCP 443和UDP 443并创建2个相应的客户端配置文件

wget http://wty.name/linux/sh/openvpn-tcp-udp.sh
sh ./openvpn-tcp-udp.sh

下面这个是OpenVPN添加用户的脚本

wget http://wty.name/linux/sh/openvpn-add-user.sh
sh ./openvpn-add-user.sh


转贴自    http://wty.name/centos-install-openvpn-with-a-key-package/comment-page-1/#comment-290

 

之前写过在《CentOS 安装和配置OpenVPN》的教程,今天发布一个OpenVPN的一键安装包。
将下面这行复制到你的linux ssh 控制台,并按下回车,过程中输入一些相关信息即可

wget http://wty.name/linux/sh/openvpn.sh;sh ./openvpn.sh;


安装完成后,把”/root/keys.tgz”下载回本地,解压至”C:\Program Files\OpenVPN\config”

下面这个也是一键安装包,跟上面那个不同的是,这个同时开启TCP 443和UDP 443并创建2个相应的客户端配置文件

wget http://wty.name/linux/sh/openvpn-tcp-udp.sh;sh ./openvpn-tcp-udp.sh;

下面这个是OpenVPN添加用户的脚本

wget http://wty.name/linux/sh/openvpn-add-user.sh;sh ./openvpn-add-user.sh;



文件  openvpn.sh

 

#!/bin/bash

ip=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F= '{print $2}'`

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
rpm -iv rpmforge-release-0.5.1-1.el5.rf.i386.rpm
rm -rf rpmforge-release-0.5.1-1.el5.rf.i386.rpm

yum -y install openvpn openssl openssl-devel
cd /etc/openvpn/
cp -R /usr/share/doc/openvpn-2.1.4/easy-rsa/ /etc/openvpn/
cd /etc/openvpn/easy-rsa/2.0/
chmod +rwx *
. ./vars
./clean-all
source ./vars

echo -e "\n\n\n\n\n\n\n" | ./build-ca
clear
echo "####################################"
echo "Feel free to accept default values"
echo "Wouldn't recommend setting a password here"
echo "Then you'd have to type in the password each time openVPN starts/restarts"
echo "####################################"
./build-key-server server
./build-dh
cp keys/{ca.crt,ca.key,server.crt,server.key,dh1024.pem} /etc/openvpn/

clear
echo "####################################"
echo "Feel free to accept default values"
echo "This is your client key, you may set a password here but it's not required"
echo "####################################"
./build-key client1
cd keys/

client="
client
remote $ip 443
dev tun
proto tcp
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
ns-cert-type server
comp-lzo
route-delay 2
route-method exe
verb 3"

echo "$client" > $HOSTNAME.ovpn

tar czf keys.tgz ca.crt ca.key client1.crt client1.csr client1.key $HOSTNAME.ovpn
mv keys.tgz /root/openvpn-client.tgz

opvpn='
port 443
proto tcp
dev tun
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
server 192.168.21.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway"
push "dhcp-option DNS 8.8.8.8"
keepalive 10 120
comp-lzo
persist-key
persist-tun'

echo "$opvpn" > /etc/openvpn/server.conf

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 192.168.21.0/24 -o eth0 -j MASQUERADE
iptables-save > /etc/sysconfig/iptables
sed -i "s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g" /etc/sysctl.conf
sysctl -p

/etc/init.d/openvpn start
clear

echo "OpenVPN has been installed
Download /root/openvpn-client.tgz using winscp or other sftp/scp client
Create a directory named vpn at C:\Program Files\OpenVPN\config\ and untar the content of /root/openvpn-client.tgz there"

 

 

openvpn-tcp-udp.sh

 

 

 

#!/bin/bash

ip=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F= '{print $2}'`

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
rpm -iv rpmforge-release-0.5.1-1.el5.rf.i386.rpm
rm -rf rpmforge-release-0.5.1-1.el5.rf.i386.rpm

yum -y install openvpn openssl openssl-devel
cd /etc/openvpn/
cp -R /usr/share/doc/openvpn-2.1.4/easy-rsa/ /etc/openvpn/
cd /etc/openvpn/easy-rsa/2.0/
chmod +rwx *
. ./vars
./clean-all
source ./vars

echo -e "\n\n\n\n\n\n\n" | ./build-ca
clear
echo "####################################"
echo "Feel free to accept default values"
echo "Wouldn't recommend setting a password here"
echo "Then you'd have to type in the password each time openVPN starts/restarts"
echo "####################################"
./build-key-server server
./build-dh
cp keys/{ca.crt,ca.key,server.crt,server.key,dh1024.pem} /etc/openvpn/

clear
echo "####################################"
echo "Feel free to accept default values"
echo "This is your client key, you may set a password here but it's not required"
echo "####################################"
./build-key client1
cd keys/

clienttcp="
client
remote $ip 443
dev tun
proto tcp
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
ns-cert-type server
comp-lzo
route-delay 2
route-method exe
verb 3"

echo "$clienttcp" > $HOSTNAME.tcp.ovpn

clientudp="
client
remote $ip 443
dev tun
proto udp
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
ns-cert-type server
comp-lzo
route-delay 2
route-method exe
verb 3"

echo "$clientudp" > $HOSTNAME.udp.ovpn


tar czf keys.tgz ca.crt ca.key client1.crt client1.csr client1.key $HOSTNAME.tcp.ovpn $HOSTNAME.udp.ovpn
mv keys.tgz /root/openvpn-client-tcp-udp.tgz

servertcp='
port 443
proto tcp
dev tun
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
server 192.168.21.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway"
push "dhcp-option DNS 8.8.8.8"
keepalive 10 120
comp-lzo
persist-key
persist-tun'

echo "$servertcp" > /etc/openvpn/server-tcp.conf

serverudp='
port 443
proto udp
dev tun
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
server 192.168.31.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway"
push "dhcp-option DNS 8.8.8.8"
keepalive 10 120
comp-lzo
persist-key
persist-tun'

echo "$serverudp" > /etc/openvpn/server-udp.conf


echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 192.168.21.0/24 -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 192.168.31.0/24 -o eth0 -j MASQUERADE
iptables-save > /etc/sysconfig/iptables
sed -i "s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g" /etc/sysctl.conf
sysctl -p

/etc/init.d/openvpn start
clear

echo "OpenVPN has been installed
Download /root/openvpn-client-tcp-udp.tgz using winscp or other sftp/scp client
Create a directory named vpn at C:\Program Files\OpenVPN\config\ and untar the content of /root/openvpn-client-tcp-udp.tgz there"

 

 

openvpn-add-user.sh

 

#!/bin/bash

ip=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F= '{print $2}'`

read -p "Please Enter New Username:" user
cd /etc/openvpn/easy-rsa/2.0/
. ./vars
source ./vars
./build-key $user
cd keys/

clienttcp="
client
remote $ip 443
dev tun
proto tcp
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert $user.crt
key $user.key
ns-cert-type server
comp-lzo
route-delay 2
route-method exe
verb 3"

echo "$clienttcp" > $HOSTNAME.$user.tcp.ovpn

clientudp="
client
remote $ip 443
dev tun
proto udp
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert $user.crt
key $user.key
ns-cert-type server
comp-lzo
route-delay 2
route-method exe
verb 3"

echo "$clientudp" > $HOSTNAME.$user.udp.ovpn

tar czf $HOSTNAME.$user.tgz ca.crt ca.key $user.crt $user.csr $user.key $HOSTNAME.$user.tcp.ovpn $HOSTNAME.$user.udp.ovpn
mv $HOSTNAME.$user.tgz /root

echo "Download /root/$HOSTNAME.$user.tgz using winscp or other sftp/scp client
Create a directory named vpn at C:\Program Files\OpenVPN\config\ and untar the content of $HOSTNAME.$user.tgz there"

 

 旧版 selinux 解决方案

 

安装时注意 关闭 selinux 因为 selinux 禁止 nobody 运行

低端口



方法1 
使用文本编辑工具打开 /etc/selinux/config 
把 SELINUX=enforcing 注释掉:#SELINUX=enforcing ,然后新加一行为:SELINUX=disabled 
保存,关闭。 
重启系统。 

方法2 
我们经常由于默认系统的安全性配置导致些莫名其妙的问题,比如SElinux本来是用于安全子系统的权限控制,可是搞不好就发现限制多多,我们可以用如下方法快速关闭SElinux 

  /usr/sbin/setenforce 0 立刻关闭 SELINUX 

  /usr/sbin/setenforce 1 立刻启用 SELINUX 

  加到系统默认启动里面 

  echo "/usr/sbin/setenforce 0" >> /etc/rc.local 

  这样就可以了




http://blog.erahere.com/%E9%85%8D%E7%BD%AEcentos6-1-sshd%E7%AB%AF%E5%8F%A3%E7%9A%84%E8%8B%A6%E9%80%BC%E4%B9%8B%E6%97%85/

Last modified onSunday, 14 October 2012 04:07

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 169
  • Published in Openvpn
  • Read 5267 times

Notice: Only variables should be assigned by reference in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 478
back to top