Re: Run a script when a connection is created?



2011/1/4 Paul Smith <paul mad-scientist net>:
> Is there any advanced feature of NM that will have it invoke a script
> when a new connection is created?  Most specifically I'm interested in
> replacing the default handling of /etc/resolv.conf updates with my own
> handling.
>
> What I'd really like is something similar to the facility in dhclient
> which allows you to define your own processing for resolv.conf updates,
> providing details about the search and nameserver entries which are
> being added for that interface via the environment or command line
> arguments or whatever.
>
> I've recently been put into a new position of needing to attach to two
> or more private subnets at the same time; each of these has their own
> internal DNS server which, in addition to serving global hostnames also
> resolves private hostnames... and I need to be able to access hosts on
> more than one private subnet at the same time.
>
> The default behavior of NM in this situation doesn't work for me: only
> the DNS servers from the "last" VPN connection I create are used and so
> private hosts on the earlier subnets can't be resolved.
>
> I've been banging my head against this for a week or so, hand-tweaking
> resolv.conf etc.  I've installed, messed with, and ultimately
> uninstalled the resolvconf package (I'm on Ubuntu 10.10): it's a nice
> idea but it requires all modifiers of resolv.conf to be changed to use
> resolvconf instead, and (for example) the openconnect VPN package
> doesn't do this.
>
> I've come up with a way to make this work by using dnsmasq as a local
> proxy DNS server, and adding "server" lines to force it to use different
> DNS servers for different network domains.  When I configure it by hand
> it works quite well.  However, in order to make this work seamlessly I
> need to get NM to give me control over the updates to resolv.conf, so I
> can instead update the dnsmasq configuration.
>
> Even if I could just run a generic "post-connect" script I could work
> out the changes I need to make by examining the contents
> of /etc/resolv.conf after the connection comes up, and do them myself.
>


put a script in /etc/NetworkManager/dispatcher.d/ and chmod +x the script

example.sh:
#!/bin/sh
if [[ $2 == 'up' ]]; then
    # do what you want
fi


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]