#TIL : Curl override Name Resolution with specific IP address

You can overrride the Name Resolution with specific IP address without adding the hostname to /etc/hosts file by using --resolve option.

Syntax :

1
--resolve <host:port:address>

It will resolve IP address when connect to host on port

Example :

This will connect 127.0.0.1

1
$ curl --resolve google.com:80:127.0.0.1 "http://google.com/"

But this won’t connect 127.0.0.1, because we use 443 port for https

1
$ curl --resolve google.com:80:127.0.0.1 "https://google.com/"

For cover all ports, use * wildcard

1
$ curl --resolve google.com:*:127.0.0.1 "https://google.com/"

#TIL : View DNS history of a domain

You can check the history of a domain (A Record). It’s useful in case you forgot the old IP of domain.

Check it here : http://viewdns.info/iphistory/

Example : this is Github A record history http://viewdns.info/iphistory/?domain=github.com

#TIL : Setup wildcard domains .test for development in MacOS

Too tired of setting your local domain each time you create new virtual development domain, etc helloworld.test, unit.test point to 127.0.0.1

There is a better way to achieve that by using dnsmasq, then set up a wildcard domains for development. In this case I use .test because .dev has been owned by Google and they strictly use HTTPS in mainly browsers.

Install dnsmasq

1
$ brew install dnsmasq

Adding .test wildcard to config file

1
$ echo 'address=/.test/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf

Setup dnsmasq as a startup service

1
$ sudo brew services start dnsmasq

Then add 127.0.0.1 (dnsmasq IP) as first DNS resolver

1
System Preferences > Network > Wi-Fi > Advanced... > DNS > add 127.0.0.1 > move it to top of the list.

Checking everything is worked by listing all resolvers

1
$ scutil --dns

Try it out

1
2
$ nslookup -type=a something.test
$ ping helloworld.test

#TIL : Flush DNS cache on iOS device

There are 2 simple ways to clear DNS cache on iOS devices :

  1. (FASTER) Just enable the Airplane Mode, wait 10 seconds and disable it
  2. (SLOWER) Reboot the device ! ;) You know this always be classic answer for many questions :D

#TIL : Getting your external IP

We can get our external IP address by following ways :

  1. Call http request : curl http://wtfismyip.com/text or curl http://ifconfig.me/ip
  2. Lookup A record for hostname nslookup myip.opendns.com resolver1.opendns.com (this only works when you use resolver of OpenDNS)

Bonus : curl https://v6.ident.me/ for IPv6