Skip to content

Commit

Permalink
Maybe handle DNS when DHCP is in use
Browse files Browse the repository at this point in the history
  • Loading branch information
swelljoe committed Sep 1, 2017
1 parent 7c4122e commit 1bbc507
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/Virtualmin/Config/Plugin/Net.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,26 @@ sub actions {
$self->spin();
eval {
if (foreign_check("net")) {

#print "Configuring resolv.conf to use my DNS server\n";
foreign_require("net", "net-lib.pl");
my $dns = net::get_dns_config();
if (indexof("127.0.0.1", @{$dns->{'nameserver'}}) < 0) {
unshift(@{$dns->{'nameserver'}}, "127.0.0.1");
net::save_dns_config($dns);
}

# Check to see if we're configured with dhcp
my @dhcp = grep { $_->{'dhcp'} } net::boot_interfaces();
if (@dhcp) {
log_debug("Detected DHCP-configured network. This isn't ideal.");
my $lref;
if (-e '/etc/dhcp/dhclient.conf') {
$lref = read_file_lines('/etc/dhcp/dhclient.conf');
if (indexof("prepend domain-name-servers 127.0.0.1;", @{$lref}) < 0) {
log_debug("Adding name server 127.0.0.1 to dhcp configuration.");
push ( @{$lref}, 'prepend domain-name-servers 127.0.0.1;' );
}
}
}
# Restart Postfix so that it picks up the new resolv.conf
foreign_require("virtual-server");
virtual_server::stop_service_mail();
Expand Down

0 comments on commit 1bbc507

Please sign in to comment.