Ubuntu automatically creates a Shell script for VPNServer-PPTP
#! /Bin/basffe ["$ UID "! = "0"]; then echo "please use sudo to run $0" exit 1 fiif ["$ #"! = "5"]; then echo "Usage: (5 parameters)" echo "$0 localip remoteip username password networkSegment/NetMask" echo "" echo "such: $0 192.168.1.1 192.168.1.1-254 tmp 192.168.1.0/24 "echo" $0 192.168.1.1 10.0.0.2-130 myuser mypassword 10.0.0.0/24 "exit 1 fiwhich pptpd>/dev/nullif [" $? "! = "0"]; then apt-get install-y pptpdfi #1. config/etc/pptpd. confsed-I "s % localip % # local_old_ip % g"/etc/pptpd. confsed-I "s % remoteip % # remote_old_ip % g"/etc/pptpd. confecho "localip $1">/etc/pptpd. conf # This is the IP address of your current host echo "remoteip $2">/etc/pptpd. conf # This is the IP address pool configured for the Client #2. add DNS, config/etc/ppp/optionssed-I "s % ms-dns % # old-dns % g"/etc/ppp/optionsecho "ms-dns 114.114.114.114">/etc/ ppp /Optionsecho "ms-dns 10.0.101.10">/etc/ppp/optionsecho "ms-dns 8.8.8.8">/etc/ppp/options #3. add Server name/etc/ppp/pptpd-options # sed-I "s % name pptpd % name $ 1% g"/etc/ppp/pptpd-optionssed-I "s % name % # na_me % g "/etc/ppp/pptpd-optionsecho" name $1 ">/etc/ppp/pptpd-optionsecho" logfile/var/log/pptp. log ">/etc/ppp/pptpd-options #4. server user name and password configuration/etc/ppp/chap-secrets # (location): # user name server name (can be set to *) password allowed Logon ip address (which can be set *) echo "\" $3 \ "$1 \" $4 \ "*">/etc/ppp/chap-secrets # such: "tmp" 192.168.1.1 "tmp" * #5. view the running port # netstat-tnlpu | grep pptpd # pptp port is tcp1723. You can see port 1723 echo 1>/proc/sys/net/ipv4/ip_forward # modify the kernel settings, enable it to support forwarding # To make it permanently effective, enable it to support forwarding # config/etc/sysctl. conf # echo "net. ipv4.ip _ forward = 1 ">/etc/sysctl. conf # change the post nominal value to 1 and save the file sed-I "s % net. ipv4.ip _ forward = 1% # net_old _. ipv4.ip _ forward = 1% g "/et C/sysctl. conf # change the post nominal value to 1 and save the file echo "net. ipv4.ip _ forward = 1 ">/etc/sysctl. conf # change the post-par value to 1, and save the file sysctl-p # takes effect immediately #6. step 4 after enabling port forwarding, The vro port forwarding # Forward the local tcp1723 port #7. without this field, you can only access intranet resources, added accessible Internet # iptables-t nat-a postrouting-s 10.0.0.0/24-o eth0-j MASQUERADEiptables-t nat-a postrouting-s $5-o eth0-j MASQUERADE #7.1 When openwrt cannot access the Internet # After pptpd is installed and configured in OpenWrt by default, although it can be connected through a vpn, it cannot be connected to the Internet through a router. Some people on the Internet say that adding POSTROUTING masquerade rules in iptables is ineffective after the old man tests. # After repeated exploration, I found that the packets on the Internet were dropped by the rst after the client dialed the vpn, so I thought the firewall was a ghost. # After Reading iptable, it is really complicated and several links are added. I thought it would be because I had a name in the FORWORD chain, so I added a rule and found that I could finally access the internet. Let's share it. # Iptables-A forwarding_rule-s 10.1.56.0/24-j ACCEPTiptables-A forwarding_rule-s $5-j ACCEPT #8. possible problem 1: the account and password cannot be verified during the connection. logfile displays: pppd [26133]: Couldn't open the/dev/ppp device: no such file or directory # True?/dev/pppls/dev/pppif ["$? "! = "0"]; then mknod/dev/ppp c 108 0fi #8. Restart the pptpd service. Otherwise, the IP address segment obtained by the client will not take effect./etc/init. d/pptpd restartexit 0