By
zhaodg
2015-04-26
更新日期:2015-04-29
更新centos7源 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 $ vim /etc/yum.repos.d/epel.repo [epel] name =Extra Packages for Enterprise Linux 7 - $basearchmirrorlist =https://mirrors.fedoraproject.org/metalink ?repo=epel-7 &arch=$basearchfailovermethod =priority enabled =1 gpgcheck =0 gpgkey =file :///etc/pki/rpm-gpg/R PM-G PG-K EY-E PEL-7 [epel-debuginfo] name =Extra Packages for Enterprise Linux 7 - $basearch - Debug mirrorlist =https://mirrors.fedoraproject.org/metalink ?repo=epel-debug-7 &arch=$basearchfailovermethod =priority enabled =0 gpgkey =file :///etc/pki/rpm-gpg/R PM-G PG-K EY-E PEL-7 gpgcheck =1 [epel-source ] name =Extra Packages for Enterprise Linux 7 - $basearch - Source mirrorlist =https://mirrors.fedoraproject.org/metalink ?repo=epel-source -7 &arch=$basearchfailovermethod =priority enabled =0 gpgkey =file :///etc/pki/rpm-gpg/R PM-G PG-K EY-E PEL-7 gpgcheck =1 $ yum makecache
安装及配置 检测PPP是否开启 1 2 3 4 #开启成功的标识 cat: /dev/ ppp: 没有那个设备或地址# or cat: /dev/ ppp: No such file or directory # or cat: /dev/ ppp: No such device or address
安装软件及依赖
设置VPN账号密码 1 2 3 4 5 $ echo "账号 pptpd 密码 *" >> /etc/ppp/chap-secrets # /etc/ppp/chap-secrets 账号密码格式说明 # Secrets for authentication using CHAP # client server secret IP addresses # 注意:上面的用户名和密码都区分大小写
修改/etc/pptpd.conf文件 搜索localip
,去掉下面字段前面的#,然后保存退出
1 2 localip 192.168.0.1 remoteip 192.168.0.234 -238 ,192.168.0.245
修改/etc/ppp/options.pptpd文件 搜索ms-dns
,去掉搜索到的两行ms-dns
前面的#,并修改为下面的字段
1 2 ms-dns 8.8.8.8 ms-dns 8.8.4.4
修改/etc/sysctl.conf文件 在conf末尾添加下面的代码,使内核支持转发
运行如下命令,是内核转发修改生效
添加iptables转发规则 1.适用于OpenVZ架构
1 iptables -t nat -A POSTROUTING -s 172.16 .36.0 /24 -j SNAT --to-source `ifconfig | grep 'inet' | grep 'netmask' | grep 'broadcast' | grep -v '127.0.0.1' | cut -d : -f 2 | awk 'NR==1 {print $2}'
2.适用于XEN架构(Linode采用)
1 iptables -t nat -A POSTROUTING -s 192.168.0.0 /24 -o eth0 -j MASQUERADE
配置iptables转发规则:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 $ iptables -A FORWARD -p tcp --syn -s 192.168 .0 .0 /24 -j TCPMSS --set-mss 1356 $ iptables -t nat -A POSTROUTING -s 192.168 .0 .0 /24 -o eth0 -j MASQUERADE $ /usr/libexec/iptables/iptables.init save$ mknod /dev/ppp c 108 0 $ chmod +x /etc/rc.d/rc.local$ echo "1" > /proc/sys /net/ipv 4/ip_forward$ echo "mknod /dev/ppp c 108 0" >> /etc/rc.local$ echo "echo \"1\">/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local$ echo "iptables -A INPUT -p tcp --dport 1723 -j ACCEPT" >> /etc/rc.local$ echo "iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT" >> /etc/rc.local$ echo "iptables -A INPUT -p gre -j ACCEPT" >> /etc/rc.local$ echo "iptables -A OUTPUT -p gre -j ACCEPT" >> /etc/rc.local$ echo "iptables -A FORWARD -p tcp --syn -s 192.168.0.0/24 -j TCPMSS --set-mss 1356" >> /etc/rc.local$ echo "iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE" >> /etc/rc.local$ systemctl restart iptables$ systemctl restart pptpd$ iptables -t nat -A POSTROUTING -s 192.168 .0 .0 /24 -o eth0 -j MASQUERADE
开机自动启动
MAC使用自建VPN
配置服务器、账号、密码等
点击 VPN(PPTP) -> Advanced-> Options-> 把Send all traffic over VPN connection 选择上
脚本部署 链接:https://github.com/zhaodg/pptpd-centos7-install-script
使用方法:
1.Update centos7 yum
1 $ sh install-centos7-yum-pero.sh
2.Install pptpd and run it
参考链接
http://www.wanghailin.cn/centos-7-vpn/
http://www.wanghailin.cn/scka/centos7-yum-pero/
http://blog.xuzeshui.com/archives/121.html
http://www.longlan.net/2013/06/04/736/