Leopard InternetSharing dhcpd detected another DHCP server exiting

标签 Mac

If you active Internet Sharing in a large LAN (e.g. your company). You can share your internet to a subnet until your mac touch another DHCP server. The InternetSharing process will exit, even cannot open again.

Look at you system.log. You will find some word like below: dhcpd: detected another DHCP server x.x.x.x, exiting.

There is a backend of Internet Sharing. You can find it at /usr/libexec/InternetSharing. It’s a binary executable file. When it running, it boot other server process: DHCP(bootpd), NAT(natd), DNS(named)

The issus is bootpd will exit when detected another DHCP server by default. Maybe you think change it’s config file. But wait. I have try that way. I make a file /etc/bootpd.plist and set detect_other_dhcp_server false. When I check InternetSharing, it rewrite my config file. And when I unchecked, it give my config file back. Amazed!

Ok. We must find another way. In bootpd man, there is an answer: If bootpd receives a SIGHUP (-1) signal, it will re-read its configuration and client binding files.

Let me try this:

  • create a file: /etc/bootpd.plist
  • open InternetSharing in sharing preferences panel
  • modify detect_other_dhcp_server to 0 in /etc/bootpd.plist
  • kill -HUP your_bootpd_pid

Look like it works. When bootpd process detected another DHCP server, it will talk about without shy.

Here is a ruby script: (usage: sudo ruby hup_bootpd.rb)

#!ruby
File.open("/etc/bootpd.plist", "r+") do |f|
	while l = f.gets
		if l =~ /detect_other_dhcp_server/
			puts "disable dhcp detect at line : #{f.lineno}"
			f.puts "\t<integer>0</integer>\n"
		end
	end
end

pid = `ps -e | grep bootpd | grep -v grep | awk '{print $1}'`

puts "tell bootpd reload configure : #{Process.kill('HUP', pid.to_i)}}"