Ubuntu – How to redirect a URL to a custom IP address

dnsinternetnetworking

I have an Ubuntu machine that I'm using as my home Internet router. It uses a USB mobile broadband modem as its Internet connection, and shares this with another router (via the router's "Internet" port) which I use as my LAN.

How do I redirect requests from within my LAN for a given URL to a custom IP address (ex have google.com redirect to x.x.x.x)?

Best Answer

The easiest way to come about this is properly installing dnsmasq (which is a DNS cacheing server) then in the folder /etc/dnsmasq.d add a file for each domain you want to redirect.

For instance this is the contents of /etc/dnsmasq.d/hotmail.com on my system:

address=/hotmail.com/127.0.0.1
address=/www.hotmail.com/127.0.0.1

If I then ask the DNS server for the IP of hotmail.com i get 127.0.0.1 like this:

llp@cerberus:~$ nslookup hotmail.com
Server:     192.168.0.10
Address:    192.168.0.10#53

Name:   hotmail.com
Address: 127.0.0.1

llp@cerberus:~$

There are a bit more options you can set, they can all be found described in /etc/dnsmasq.conf

Related Question