I use an external squid transparent proxy for my clients. We recently switched to a RouterOS firewall and I discovered a great way to route traffic to my proxy without having to configure each client's proxy settings.
I dug around on the internet and found
this lovely guide that describes pretty close to what i'm looking for.
The way we handled it in the past was to redirect port 80 traffic from the firewall to the ip and port number of our squid proxy. MikroTik offers ways I can do this while still preserving the source ip address. Before i setup my new config anyone who didn't have their client proxy setup was listed as the filewall's ip address in squid's logs.
Here's my setup
Firewall/Mikrotik 192.168.1.1
Squid Proxy 192.168.1.2 (Proxy port 8080)
Clients 192.168.100-192.168.1.199
I already have the mangle and masquerading setup for my main firewall so I'm only going to list the settings that affect and redirect http traffic to my proxy server.
First I setup an address list of the client ip addresses i wanted to be redirected to my proxy server. In my case its my dhcp pool addresses
/ip firewall address-list
add address=192.168.1.100-192.168.1.199 list=Proxy_Clients
Then i setup mangle to tag web traffic for rerouting later
/ip firewall mangle
chain=prerouting action=mark-routing new-routing-mark=to_proxy passthrough=yes protocol=tcp src-address-list=Proxy_Clients dst-port=80
Next i setup a custom route for the marked packets
/ip route
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=192.168.1.2 routing-mark=to_proxy scope=30 target-scope=10
What we're doing now is routing all traffic from clients 192.168.1.100-192.168.1.199 on port 80 to the proxy server.
The last piece of the puzzle is to setup the proxy server (squid) to redirect all traffic on port 80 to the proxy port (8080). This is easily done with iptables.
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to 192.168.1.2:8080
That should do it. Now you are forwarding all port 80 traffic to the squid proxy. Most importantly is you are preserving the source ip address. This way if you want to use squid reporting you can track your users usage by ip address.
Most of the information i used to get this solution was borrowed from
this website. I changed up the syntax a little to fit my needs. My next project is to figure out how to exclude streaming services (netflix) from being forwarded to the proxy server. I've already toyed with using ip blocks. The biggest problem i've run into there is adding all netflix's ip ranges to an address list. I keep finding new ones.
For those interested: Here's my modified mangle rule for not forwarding netflix traffic to the proxy, but forwarding everything else.
/ip firewall mangle
chain=prerouting action=mark-routing new-routing-mark=to_proxy passthrough=yes protocol=tcp src-address-list=Proxy_Clients dst-address-list=!Netflix dst-port=80
My address list for netflix
/ip firewall address-list
add address=69.164.0.0/18 list=Netflix
add address=208.111.128.0/18 list=Netflix
add address=68.142.64.0/18 list=Netflix
add address=108.175.32.0/20 list=Netflix