转载

XEN VPS 额外支持

注意:以下安装 VPN 和增加交换分区只有 XEN 的 VPS 才支持,如果是 OPEN VZ 的 Linux,请忽略。

安装 PPTP VPN

安装 pptpd 服务

执行如下命令安装,遇到提示输入 Y/n 时,输入 Y 回车即可:
 apt-get install pptpd
执行结果如下:
root@289085:~# apt-get install pptpd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  bcrelay libpcap0.8 ppp
The following NEW packages will be installed:
  bcrelay libpcap0.8 ppp pptpd
0 upgraded, 4 newly installed, 0 to remove and 1 not upgraded.
Need to get 542 kB of archives.
After this operation, 1,872 kB of additional disk space will be used.
Do you want to continue [Y/n]? 
Get:1 http://archive.ubuntu.com/ubuntu/ oneiric/main libpcap0.8 i386 1.1.1-8 [117 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ oneiric/main ppp i386 2.4.5-5ubuntu1 [334 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ oneiric/main bcrelay i386 1.3.4-5ubuntu1 [10.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ oneiric/main pptpd i386 1.3.4-5ubuntu1 [80.4 kB]
Fetched 542 kB in 2s (242 kB/s)
Selecting previously deselected package libpcap0.8.
(Reading database ... 24582 files and directories currently installed.)
Unpacking libpcap0.8 (from .../libpcap0.8_1.1.1-8_i386.deb) ...
Selecting previously deselected package ppp.
Unpacking ppp (from .../ppp_2.4.5-5ubuntu1_i386.deb) ...
 Removing any system startup links for /etc/init.d/ppp ...
Selecting previously deselected package bcrelay.
Unpacking bcrelay (from .../bcrelay_1.3.4-5ubuntu1_i386.deb) ...
Selecting previously deselected package pptpd.
Unpacking pptpd (from .../pptpd_1.3.4-5ubuntu1_i386.deb) ...
Processing triggers for man-db ...
Processing triggers for ureadahead ...
Setting up libpcap0.8 (1.1.1-8) ...
Setting up ppp (2.4.5-5ubuntu1) ...
Setting up bcrelay (1.3.4-5ubuntu1) ...
Setting up pptpd (1.3.4-5ubuntu1) ...
Starting PPTP Daemon: pptpd.
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

 配置 pptpd

为了避免和本地网络冲突,我们创建VPN的IP范围为 192.168.10.21-192.168.10.100 执行如下命令:
echo 'localip 192.168.10.1-20' >> /etc/pptpd.conf
echo 'remoteip 192.168.10.21-100' >> /etc/pptpd.conf
echo 'ms-dns 8.8.8.8' >> /etc/ppp/pptpd-options
echo 'ms-dns 8.8.4.4' >> /etc/ppp/pptpd-options
echo 'nopcomp' >> /etc/ppp/pptpd-options
echo 'noaccomp' >> /etc/ppp/pptpd-options
继续增加 pptp 用户帐号: 格式为 [UserName] pptpd [Password] * ,我们增加一个 guest 密码 为 123456 的用户如下:
echo 'guest * 123456 *' >> /etc/ppp/chap-secrets
重启下pptpd:
/etc/init.d/pptpd restart
注意:如果需要在 iphone 上使用,请在 iphone 的 PPTP 设置页将 "加密级别" 设置为 "最高" ,否则将无法连接上。

 配置防火墙

打开 IP 转发:
echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
sysctl -p
配置防火墙:
 iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o eth0 -j MASQUERADE
 iptables-save > /etc/iptables-rules
 echo '#!/bin/sh' > /etc/network/if-up.d/iptablesload
 echo 'iptables-restore < /etc/iptables-rules' >> /etc/network/if-up.d/iptablesload
 echo 'exit 0' >> /etc/network/if-up.d/iptablesload
 chmod +x /etc/network/if-up.d/iptablesload
大功告成,可以使用 PPTP VPN 了。

增加交换分区大小

增加之前:
root@289085:~# free
             total       used       free     shared    buffers     cached
Mem:        506088      46008     460080          0       3624      21944
-/+ buffers/cache:      20440     485648
Swap:       262140          0     262140
运行如下命令增加256M交换内存
dd if=/dev/zero of=/mnt/256M.swap bs=1M count=256
chmod 600 /mnt/256M.swap
mkswap /mnt/256M.swap
swapon /mnt/256M.swap
echo '/mnt/256M.swap  none  swap  sw  0 0' >> /etc/fstab
增加之后:
root@289085:~# free
             total       used       free     shared    buffers     cached
Mem:        506088     312740     193348          0       3952     284180
-/+ buffers/cache:      24608     481480
Swap:       524280          0     524280

正文到此结束
Loading...