Routing to virtual localhost sites on LAN devices with Squid in Ubuntu

I just got an 4th gen iPad to test mobile sites with. Unfortunately there is no proper jailbreak for it yet so editing the hosts file on the machine itself was out of the question.

As it happens the Squid proxy server can be used to browse through. If it is set up correctly the local /etc/hosts file on the machine it is installed on, and which you are doing the development on, takes precedence. You should then be able to automatically access local virtual sites such as local.domain.com or www.domain.loc from your pads and phones which are also connected to the LAN.

First up you don’t want your IP to hop around, I set mine to a quite high value (100) to avoid conflicts in my /etc/network/interfaces file:

auto lo
iface lo inet loopback

iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1

auto eth0

You might also have to remove the default network manager: sudo apt-get remove network-manager network-manager-gnome

Restart: /etc/init.d/networking restart

Install Squid3: apt-get install squid3

Edit the Squid config file: sudo geany /etc/squid3/squid.conf

Search for a line beginning with acl localnet src 192.168

Fix it so that it applies to your situation and uncomment it, mine looks like this: acl localnet src 192.168.1.1/24

Uncomment another line looking like this: http_access allow localnet

Restart Squid: /etc/init.d/squid3 restart

Update for Ubuntu 16.04, this is currently my working config lines:

acl localhost src 127.0.0.1/32
acl localnet src 192.168.0.0/24	# RFC1918 possible internal network
http_access allow !Safe_ports
http_access allow CONNECT !SSL_ports
http_access allow localhost manager
http_access allow manager
http_access allow to_localhost
http_access allow localnet
http_access allow localhost
http_access allow all

Go to your wifi settings in your iPad and change the proxy settings, this is what it looks like but in my case the port is the default Squid port 3128 and the IP of the proxy server is of course 192.168.1.100.

Open your virtual domain, eg www.domain.loc and test away!

Related Posts

Tags: , ,