Skip to content

Instantly share code, notes, and snippets.

@Exchizz
Last active July 12, 2018 11:19
Show Gist options
  • Save Exchizz/9dcf98b2fa3ba8d96fd2e6bbcbaa1447 to your computer and use it in GitHub Desktop.
Save Exchizz/9dcf98b2fa3ba8d96fd2e6bbcbaa1447 to your computer and use it in GitHub Desktop.
Script to set DNS in dnsmasq from dbus using perl.
#!/usr/bin/perl
# This is a slight variant on an example provided by Net::DBus.
use strict;
use warnings;
# Load the Net::DBus D-Bus binding.
use Net::DBus;
# Connect to the system bus.
my $bus = Net::DBus->system;
# Get a handle to the HAL service.
my $dnsmasq = $bus->get_service("org.freedesktop.NetworkManager.dnsmasq");
# Get a handle to the device manager.
my $manager = $dnsmasq->get_object("/uk/org/thekelleys/dnsmasq", "org.freedesktop.NetworkManager.dnsmasq");
my @DNS_PRI = ("8.8.8.8");
my @DNS_SEC = ("8.8.4.4");
my @DNS_IPS=(\@DNS_PRI, \@DNS_SEC);
$manager->SetServersEx(\@DNS_IPS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment