Solved

Working with pon/poff in Ubuntu

Posted on 2006-07-18
5
851 Views
Last Modified: 2012-08-14
I've set up the following script to connect to the office VPN on a Ubuntu laptop:

--------8<--------
#!/bin/sh

case "$1" in
    on)
        sudo pon office
        # Need to wait for connection to establish
        sleep 5
        # Now set up routes
        sudo route add -net 192.168.1.0/24 ppp0
        sudo route add -net 192.168.96.0/20 ppp0
        ;;
    off)
        sudo route del -net 192.168.96.0/20 ppp0
        sudo route del -net 192.168.1.0/24 ppp0
        sudo pon office
        ;;
    *)
        echo "Usage: $0 {on|off}"
esac
--------8<--------

It works (i.e. I've got pppd working etc), which I'm feeling very pleased about, but something tells me that using sleep 5 in my script is a bit naff, and I've not done anything about connecting to the office domain name servers.

Here are my questions:

(1) Should I be setting up and taking down those routes in scripts in /etc/ppp/ip-up.d and /etc/ppp/ip-down.d, and if so how to I script it to be applied for "office" only?

(2) I notice what looks like a clever looking script for setting up DNS from the peer /etc/ppp/ip-up.d/0000usepeerdns, which uses resolvconf (which apt-get doesn't seem to know about in my set-up). Is this what I should be using to get my resolver to use the office DNS, and if so, what's the sensible way to get the right package for this?
0
Comment
Question by:rstaveley
  • 3
  • 2
5 Comments
 
LVL 17

Author Comment

by:rstaveley
ID: 17128851
I see that resolvconf isn't part of the Ubuntu distribution, because there are some bugs associated with it. Is there an alternative that's known to work?
0
 
LVL 39

Accepted Solution

by:
noci earned 250 total points
ID: 17140432
IMHO, in the off case I thing "sudo poff office" would work as intended

Ad 1)
From "man pppd":

      ipparam string
              Provides  an  extra  parameter to the ip-up and ip-down scripts.  If this option is given, the string supplied is given as the 6th
              parameter to those scripts.

And yes the up & down scripts are a better place to specify routeing ...
the ipparam should be in the options file for your office settings.

Ad 2)
Do you mean the file resolve.conf? it normaly resides in /etc.

What the code in 000usepeerdns does, is looking where the resolv.conf is, and save the old one & replace it with one that ppp created
in ip-down it undoes this rename.


0
 
LVL 39

Expert Comment

by:noci
ID: 17140443
btw, i meant /etc/resolv.conf in the previous remark, not /etc/resolve.conf

0
 
LVL 17

Author Comment

by:rstaveley
ID: 17141552
Thanks for the comments noci. I'll do as you suggest for 1.

Ref 2: The script is indeed resolvconf, which sets up /etc/resolv.conf with the DNS reported by the connection. Here's the Debian package: http://packages.debian.org/unstable/net/resolvconf. I guess I need to set up my Ubuntu repositories to get apt-get to get it. I'm explicitly overwriting resolv.conf with hard-coded values for the time being, which works for as long as the office VPN isn't changed. I'm still finding my way with Ubuntu.
0
 
LVL 39

Expert Comment

by:noci
ID: 17141680
Here is the code rewritten from gentoo:

in ip-up:
---8<---
if [ "$USEPEERDNS" ]; then

        # add the server supplied DNS entries to /etc/resolv.conf
        # (taken from debian's 0000usepeerdns)

        # follow any symlink to find the real file
        REALRESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)

        if [ "$REALRESOLVCONF" != "/etc/ppp/resolv.conf" ]; then

                # merge the new nameservers with the other options from the old configuration
                {
                        grep --invert-match '^nameserver[[:space:]]' $REALRESOLVCONF
                        cat /etc/ppp/resolv.conf
                } > $REALRESOLVCONF.tmp

                # backup the old configuration and install the new one
                cp -dpP $REALRESOLVCONF $REALRESOLVCONF.pppd-backup
                mv $REALRESOLVCONF.tmp $REALRESOLVCONF

                # correct permissions
                chmod 0644 /etc/resolv.conf
                chown root:root /etc/resolv.conf

        fi

fi
---8<---


end part of ip-down:
---8<---
if [ "$USEPEERDNS" ]; then

        # taken from debian's 0000usepeerdns
        # follow any symlink to find the real file
        REALRESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)

        if [ "$REALRESOLVCONF" != "/etc/ppp/resolv.conf" ]; then

                # if an old resolv.conf file exists, restore it
                if [ -e $REALRESOLVCONF.pppd-backup ]; then
                        mv $REALRESOLVCONF.pppd-backup $REALRESOLVCONF
                fi

        fi

fi
---8<---

Ther's more surounding it like resetting default gateway etc.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now