I'm trying to setup a VPN over SSH using PPPD (following the Arch Wiki). The command given is:
/usr/sbin/pppd updetach noauth silent nodeflate pty \
"/usr/bin/ssh root@remote-gw /usr/sbin/pppd nodetach notty noauth" \
ipparam vpn 10.0.8.1:10.0.8.2
I have successfully managed to set it up with appropriate modifications to the above command. To connect to the internal network on the server side, I had to set up forwarding using iptables on the server side (blindly following this SF post):
iptables -A FORWARD -i ppp0 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o ppp0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
I'd like to automate this. Now, eth0 is fixed, but the ppp0 may change (for example, someone else also has started a similar setup). How can I detect what interface was created by the pppd command on the server side? Parse ? Diff the output of dmesgip -o a? Can I get pppd to report it to me?
- Client is an up-to-date Arch Linux
- Server is an up-to-date Ubuntu 14.04
dmesg seems to be useless:
$ dmesg | grep -i ppp
[ 0.803033] PPP generic driver version 2.4.2
[135747.442807] PPP BSD Compression module registered
[135747.459013] PPP Deflate Compression module registered
No mention of a device being created. syslog seems to be more useful:
Apr 26 13:52:15 server pppd[12725]: pppd 2.4.5 started by muru, uid 0
Apr 26 13:52:15 server pppd[12725]: Using interface ppp0
Apr 26 13:52:15 server pppd[12725]: Connect: ppp0 <--> /dev/pts/7
Apr 26 13:52:15 server pppd[12725]: BSD-Compress (15) compression enabled
The Using interface ppp0 line seems to be what I want. I think I can get it thus:
awk '/started by muru/{getline; pppdev=$NF} END {print pppdev}'
Can I rely on the output of pppd for this?