{"id":482,"date":"2011-01-28T00:30:38","date_gmt":"2011-11-29T13:51:50","guid":{"rendered":"http:\/\/kraftek.com\/blog\/building-a-vpn-with-ppp-over-ssh-within-2-linuxes\/"},"modified":"2025-02-28T19:31:56","modified_gmt":"2025-02-28T19:31:56","slug":"building-a-vpn-with-ppp-over-ssh-within-2-linuxes","status":"publish","type":"post","link":"\/blog\/index.php\/building-a-vpn-with-ppp-over-ssh-within-2-linuxes\/","title":{"rendered":"Building a VPN with ppp over ssh within 2 linuxes"},"content":{"rendered":"\n<p>To build a Virtual Private Network within two remote machines, you might follow the howto at<br>http:\/\/www.tldp. org\/HOWTO\/VPN-HOWTO\/index.html<br>which is very detailed, or, if you have two slackware 10.x<br>with default 2.4.x kernels, just use the procedure described in this document.<br>This OBSOLETES the ssh reverse telnet entry previously detailed in this blog.<\/p>\n\n\n\n<p><br>Requirements:<br>\u2013 2 machines, machineA and machineB.<br>\u2013 machineA will be the ppp client and machineB the ppp server<br>\u2013 machineA MUST have access to machineB through ssh.<br>\u2013 pty-redir in machineA from http:\/\/www.shinythings.com\/pty-redir\/<br>\u2013 No extra ethernet interfaces needed.<br>At machine A:<br>Make a file at \/scripts\/rtelnet\/rt.ksh with contents:<br>#!\/bin\/bash<br>ADATE=`date \u201c+%Y-%m-%d-%H:%M\u201d`<br>PS=`ps -ef | grep -v grep |grep ppp | wc -l`<br>if [ $PS -gt 0 ]; then<br>echo \u201cno need to retunnel $ADATE\u201d >> \/dev\/null<br>else<br>echo \u201cnow retunneling ppp: $ADATE\u201d >> \/root\/rtelnet.log<br>K=`ps -fe | grep ssh | grep -i Batchmode | awk \u2018{ print $2 }\u2019`<br>kill -9 $K >> \/root\/rtelnet.log<br>\/usr\/sbin\/pty-redir \/usr\/bin\/ssh -C -t -e none -o \u2018Batchmode yes\u2019 vpn@machineB > \/tmp\/vpn-device<br>sleep 10<br>\/usr\/sbin\/pppd `cat \/tmp\/vpn-device` 192.168.40.253: 192.168.40.254<br>fi<\/p>\n\n\n\n<p><br>You can choose 192.168.x.x addresses or 172.16.x addresses at your own will\u2026<br>Then make a link to this file at \/etc\/cron.hourly:<br>machineA# ln -s \/scripts\/rtelnet\/rt.ksh \/etc\/cron.hourly\/rt.ksh<br>At machine B:<br>Create user vpn with shell \/usr\/sbin\/pppd, and allow him to execute pppd:<br>machineB# useradd -d \/home\/vpn -m vpn -s \/usr\/sbin\/pppd<br>machineB# mkdir -p \/home\/vpn\/.ssh; chown vpn \/home\/vpn\/.ssh<br>machineB# chmod u+s \/usr\/sbin\/pppd<br>At machine A:<br>Copy a ssh key to allow root to login as user vpn in machine B<br>machineA# scp \/root\/.ssh\/id_dsa.pub machineB:\/home\/vpn\/.ssh\/authorized_keys<br>At machine B:<br>machineB# chown vpn \/home\/vpn\/.ssh\/authorized_keys<br>machineB# chmod -fR 700 \/home\/vpn\/.ssh<\/p>\n\n\n\n<p><br>Edit \/etc\/ppp\/options, and make sure you have enabled:<br>noauth<br>proxyarp<br>ipcp-accept-local<br>ipcp-accept-remote<\/p>\n\n\n\n<p><br>You might then run the script manually at machineA:<br>machineA#\/scripts\/rtelnet\/rt.ksh<br>Or wait until the crontab executes it hourly.<br>You can see the results as having a ppp interface when you type ifconfig -a:<br>machineA# ifconfig -a<br>eth0 Link encap:Ethernet HWaddr 00:11:43:01:BF:97<br>inet addr:150.100.106.32 Bcast:150.100.106.255 Mask:255.255.255.0<br>UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1<br>RX packets:1442299 errors:0 dropped:0 overruns:0 frame:8<br>TX packets:791769 errors:0 dropped:0 overruns:0 carrier:0<br>collisions:108549 txqueuelen:1000<br>RX bytes:725406260 (691.8 Mb) TX bytes:113886692 (108.6 Mb)<br>Interrupt:11<br>lo Link encap:Local Loopback<br>inet addr:127.0.0.1 Mask:255.0.0.0<br>UP LOOPBACK RUNNING MTU:16436 Metric:1<br>RX packets:7662 errors:0 dropped:0 overruns:0 frame:0<br>TX packets:7662 errors:0 dropped:0 overruns:0 carrier:0<br>collisions:0 txqueuelen:0<br>RX bytes:9507700 (9.0 Mb) TX bytes:9507700 (9.0 Mb)<br>ppp0 Link encap:Point-to-Point Protocol<br>inet addr:192.168.40.253 P-t-P:192.168.40.254 Mask:255.255.255.255<br>UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1<br>RX packets:116175 errors:0 dropped:0 overruns:0 frame:0<br>TX packets:111813 errors:0 dropped:0 overruns:0 carrier:0<br>collisions:0 txqueuelen:3<br>RX bytes:31145420 (29.7 Mb) TX bytes:7337890 (6.9 Mb)<\/p>\n\n\n\n<p><br>Now do the same in machineB:<br>machineB# ifconfig -a<br>eth0 Link encap:Ethernet HWaddr 00:0C:76:AC:C7:AD<br>inet addr:201.154.187.65 Bcast:201.154.187.67 Mask:255.255.255.252<br>UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1<br>RX packets:1128235 errors:0 dropped:0 overruns:0 frame:0<br>TX packets:798177 errors:0 dropped:0 overruns:0 carrier:0<br>collisions:0 txqueuelen:1000<br>RX bytes:1028702533 (981.0 Mb) TX bytes:139249041 (132.7 Mb)<br>Interrupt:10 Base address:0x4000<br>lo Link encap:Local Loopback<br>inet addr:127.0.0.1 Mask:255.0.0.0<br>UP LOOPBACK RUNNING MTU:16436 Metric:1<br>RX packets:94489 errors:0 dropped:0 overruns:0 frame:0<br>TX packets:94489 errors:0 dropped:0 overruns:0 carrier:0<br>collisions:0 txqueuelen:0<br>RX bytes:550735249 (525.2 Mb) TX bytes:550735249 (525.2 Mb)<br>ppp0 Link encap:Point-to-Point Protocol<br>inet addr:192.168.40.254 P-t-P:192.168.40.253 Mask:255.255.255.255<br>UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1<br>RX packets:111998 errors:0 dropped:0 overruns:0 frame:0<br>TX packets:116406 errors:0 dropped:0 overruns:0 carrier:0<br>collisions:0 txqueuelen:3<br>RX bytes:7353046 (7.0 Mb) TX bytes:31169104 (29.7 Mb)<\/p>\n\n\n\n<p><br>You\u2019ll see machine A as 192.168.40.253 and machineB as 192.168.40.254.<br>Go ahead and ping\u2019em, nmap\u2019em, use their samba resources, or whatever you want, you have a network<br>within them!<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To build a Virtual Private Network within two remote machines, you might follow the howto athttp:\/\/www.tldp. org\/HOWTO\/VPN-HOWTO\/index.htmlwhich is very detailed, or, if you have two slackware 10.xwith default 2.4.x kernels, just use the procedure described in this document.This OBSOLETES the ssh reverse telnet entry previously detailed in this blog. Requirements:\u2013 2 machines, machineA and machineB.\u2013 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=482"}],"version-history":[{"count":2,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/482\/revisions"}],"predecessor-version":[{"id":1655,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/482\/revisions\/1655"}],"wp:attachment":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}