ubuntu下搭建vpn历程(转贴)

1、卸载pptpd和iptables,重新安装pptpd

#卸载pptpd
$ apt-get autoremove pptpd
$ apt-get purge pptpd
#卸载iptables
$ apt-get autoremove iptables*
$ apt-get purge iptables*
#安装pptpd
$ apt-get install pptpd

2、配置pptpd

(1)首先,编辑pptpd.conf文件,设置localip和remoteip

$ vim /etc/pptpd.conf

查找到localip和remoteip,打开注释进行设置。将localip设置为你的vps的服务器公网ip,不知道可以通过ifconfig查看。remoteip是设置给VPN用户分配的IP段,我这里设置为10.100.0.2-100。

localip VPS_IP
remoteip 10.100.0.2-100

(2)修改dns设置,设置为google的DNS

$ vim /etc/ppp/pptpd-options

查找到ms-dns,配置dns如下:

ms-dns 8.8.8.8
ms-dns 8.8.4.4

(3)设置VPN的账号密码

编辑chap-secrets文件

$ vim /etc/ppp/chap-secrets

在chap-secrets文件中添加一行配置

#client server secret IP address
liuchungui pptpd 123456 *

其中,liuchungui是VPN的用户名,使用的VPN服务类型是pptpd,密码是123456,*代表不限制IP

3、启动pptpd服务

$ /etc/init.d/pptpd restart

输入上面命令,如果提示`

  • Restarting PoPToP Point to Point Tunneling Server pptpd [ OK ] `
    就说明启动成功了

4、设置系统的ipv4的转发开关

$ vim /etc/sysctl.conf

编辑/etc/sysctl.conf文件,找到net.ipv4.ip_forward=1,把这行的注释打开并保存。
运行:sysctl -p 让上面的修改立即生效。

5、配置iptables

(1)安装iptables

$ apt-get install iptables

(2)添加一个NAT,这里特别注意:eth1是vps的ip网卡接口,可以通过ifconfig查看

$ iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o eth1 -j MASQUERADE

(3)设置MTU,防止包过大

$ iptables -A FORWARD -s 10.100.0.0/24 -p tcp -m tcp –tcp-flags SYN,RST SYN -j TCPMSS –set-mss 1200

(4)再添加一个NAT,45.62.119.172就是你的vps的公网ip

$ iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -j SNAT –to-source 45.62.119.172

(5)将iptables规则保存,令重启后规则不丢失:

$ iptables-save > /etc/iptables-rules

(6)编辑网卡文件,加载网卡时自动加载规则

$ vim /etc/network/interfaces

interfaces文件末尾加上:pre-up iptables-restore < /etc/iptables-rules

(7)安装iptables配置持久化

$ apt-get install iptables-persistent

(8)运行保存配置命令

$ service iptables-persistent start

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>