Class: JDCMicro::Switcher::Linux

Inherits:
Base show all
Defined in:
lib/micro/switcher/linux.rb

Instance Method Summary collapse

Methods inherited from Base

#domain, #initialize, #ip, #nat?, #offline!, #offline?, #online!, #ready?, #reset_to_nat!, #running?, #set_host_dns!, #start!, #unset_host_dns!, #vmx

Constructor Details

This class inherits a constructor from JDCMicro::Switcher::Base

Instance Method Details

#set_nameserver(domain, ip) ⇒ Object



4
5
6
7
8
# File 'lib/micro/switcher/linux.rb', line 4

def set_nameserver(domain, ip)
  JDCMicro.run_command("sudo", "sed -i'.backup' '1 i nameserver #{ip}' /etc/resolv.conf")
  # lock resolv.conf so Network Manager doesn't clear out the file when offline
  JDCMicro.run_command("sudo", "chattr +i /etc/resolv.conf")
end

#unset_nameserver(domain, ip) ⇒ Object



10
11
12
13
# File 'lib/micro/switcher/linux.rb', line 10

def unset_nameserver(domain, ip)
  JDCMicro.run_command("sudo", "chattr -i /etc/resolv.conf")
  JDCMicro.run_command("sudo", "sed -i'.backup' '/#{ip}/d' /etc/resolv.conf")
end