adding local DNS resolution for a custom top level domain on macOS using macports

Recently I was testing some applications in a local kubernetes installation running in minikube, especially the access via an ingress. For this I defined the ingress endpoints using a custom otherwise not existing top level domain to produce names like application1.foobar or application2.foobar. (The list  of officially registered TLDs can be found at

Now in order to access these applications locally with an URL like http://application1.foobar/ I need to make the DNS resolution resolve this address to the IP address of my local minikube instance. This IP address can be retrieved with

minikube ip

which in this sample case returns

Now I could add the following line to my /etc/hosts file (which needs to be edited with sudo):  application1.foobar appiicaton2.foobar

but this is no nice solution as every time when a new application is added, the /etc/hosts file must be updated.

So instead I set up a local DNS server (using dnsmasq) which will resolve every call to an address with the .foobar top level domain to our IP address. Then I reconfigure the local name resolution process of macOS to use this DNS resolver for .foobar addresses – we want to keep the normal DNS resolution working.

Setting up dnsmasq

I am using MacPorts on my machines, other people prefer homebrew, both have dnsmasq as package available. The first step is the installation:

sudo port install dnsmasq

The next step is to edit the dnsmasq configuration, so that any request for an address in the .foobar domain ist resolved to our ip address. The macports installation has its configuration file at /opt/local/etc/dnsmasq.conf, this file must be edited with sudo vi /opt/local/etc/dnsmasq.conf and the following line must be added:


After changing the configuration the dnsmasq service is started with sudo port load dnsmasq. it can be stopped with the corresponding command sudo port unload dnsmasq.

Now the local running DNS server will return our IP for any host in the foobar domain:

$ dig application1.foobar @localhost +noall +answer

; <<>> DiG 9.10.6 <<>> application1.foobar @localhost +noall +answer
;; global options: +cmd
application1.foobar.	0	IN	A

$ dig adifferenthost.foobar @localhost +noall +answer

; <<>> DiG 9.10.6 <<>> adifferenthost.foobar @localhost +noall +answer
;; global options: +cmd
adifferenthost.foobar.	0	IN	A

$ dig even.subdomains.are.working.foobar @localhost +noall +answer

; <<>> DiG 9.10.6 <<>> even.subdomains.are.working.foobar @localhost +noall +answer
;; global options: +cmd
even.subdomains.are.working.foobar. 0 IN A

Configuring the system resolving process

The next step is to reconfigure the nameserver resolution of macOS to use our local running dnsmasq when requests for our .foobar domain come in. For this we need to add a file named foobar to the /etc/resolver directory (which may not yet exist on your machine) and add the following line:


This can be done with:

sudo mkdir -p /etc/resolver
echo "nameserver" | sudo tee -a /etc/resolver/foobar

After this you can check that this dns resolver is configured by issuing a scutil --dns command, the output contains an entry like this:

resolver #19
  domain   : foobar
  nameserver[0] :
  flags    : Request A records, Request AAAA records
  reach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)

or you could do a

$ ping application2.foobar
PING application2.foobar ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=0.559 ms
64 bytes from icmp_seq=1 ttl=64 time=0.472 ms

$ ping
PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=1.156 ms
64 bytes from icmp_seq=1 ttl=64 time=0.456 ms


setting up MacPorts apache2 with virtual hosts and PHP 5.6

I just needed an apache webserver with PHP 5.6 and some virtual hosts on my Mac running OSX El Capitan. The native OSX apache version comes with an older version of PHP which has no xdebug support, so I shut it down with

sudo apachectl stop


I installed the following ports:

sudo port install apache2 php56 php56-apache2handler php56-xdebug

Apache configuration

After installing the following commands are needed:

cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n php5

After that, the following changes must be made to /opt/local/apache2/conf/httpd.conf:

# add the following line where the modules are loaded
LoadModule php5_module modules/
#add the following line
Include conf/extra/mod_php56.conf
# set the ServerName
ServerName myhost.local
#uncomment the following line to have vhost configurations:
Include conf/extra/httpd-vhosts.conf

In the file /opt/local/apache2/conf/extra/httpd-vhosts.conf configure the virtual hosts:

<VirtualHost *:80>
  DocumentRoot "/path/to/where/the/docs/are"
  ServerName myvhost
  <Directory />
    DirectoryIndex index.html index.php
    AllowOverride All
    Options All
    Allow from all

And don’t forget to add the virtual host name (myvhost) as an alias to localhost in /etc/hosts.

The configuration can be checked with

/opt/local/apache2/bin/apachectl -t

Starting and stopping the server is done with:

sudo port load apache2
sudo port unload apache2

PHP configuration

in /opt/local/etc/php56 copy one of the provided sample files to php.ini and adjust it, especially the date.timezone setting. To configure xdebug, add the following section to php.ini (make sure the path to matches the installed version):



Apache VirtualHost on Mac OSX

note to self:

to set up a virtual host named viho for local web development testing on OSX El Capitan (and probably earlier):

  1. define an alias name in /etc/hosts:       localhost viho
    ::1             localhost viho
  2. setup the virtual host configuration file /etc/apache2/other/viho.conf:
    <VirtualHost *:80>
      DocumentRoot "/path/to/where/the/files/are"
      ServerName viho

browse to http://viho/ and enjoy.

Apache on Mac OSX El Capitan

Note to self:

To start or stop the Apache webserver on Mac OSX El Capitan, use the terminal:

sudo apachectl start

sudo apachectl stop

sudo apachectl restart

The configuration is found in /etc/apache2/httpd.conf. The default DocumentRoot directory is /Library/WebServer/Documents. Additional configuration files should be put in _/etc/apache2/other/*.conf_ files.

Run IntelliJ IDEA with actual Java version on OS X

With every update of IntelliJ IDEA, I stumble over this: IDEA wants to run on Java Version 6. As I don’t have this buggy outdated version on my Mac anymore, I always have to patch the config. To do this, locate the file named Info.plist in the Contents folder of the IntelliJ IDEA 14 directory. Open the file with TextEdit or any text editor of your choice and change the line




After that IJ will start using your default – hopefully actual – java version.

2015-06-21 Update: IntelliJ IDEA 15 EAP has it’s own custom Java8 built in, and also has the possibility to select the JDK to use when starting up. Cool.

removing the quarantine attribute

Since OSX 1.05, programs downloaded by Safari and other programs like get an extended quarantine attribute called This leads to the behaviour that when starting the program, the user is asked if she really wants to start the program together with the information where the program was loaded from.

This attribute is removed once the user who downloaded the file runs the program. Another way to remove the quarantine flag is the following command (the user running this command needs to be in the sudoers file):

sudo xattr -d /path_to_programm

MacBook Pro 2010 Crash (Nvidia)

Sometimes my MacBook Pro 2010 crashes, the crash report show problems with the nvidia driver. Sometimes it happens after waking up the systems, nut I also had crashes after a reboot during normal operation.

In the net I found the following hint, which helped me up to now:

In the directory ~/Library/Preferences/ByHost/ delete all files, that have “windowserver” in their name and reboot the computer.

shrink a sparsebundle

To shrink a dynamically growing drive image (the parameter -stdinpass is need for encrypted images):

hdiutil compact -stdinpass file.sparseimage

On a laptop running on battery power the parameter -batteryallowed is needed, otherwise there will be an error “function not implemented”.