linksys router (ddwrt) + proxy server


How I setup proxy to work with linksys router with ddwrt firmware?

Legend:
router ip: 192.168.1.1
proxy server ip: 192.168.1.100
proxy port: 3128
local lan: 192.168.1.0/24

1. bash script to add to the router;

####### SCRIPTA #####
#!/bin/sh
INTERNAL_NETWORK="192.168.1.0/24"
ROUTER_IP="192.168.1.1"
PROXY_SERVER="192.168.1.100"
PROXY_PORT="3128"
if [ -z $TRANSPARENT_PROXY ]; then
/usr/sbin/iptables -t nat -A PREROUTING -i br0 -s $INTERNAL_NETWORK -d $INTERNAL_NETWORK -p tcp --dport 80 -j ACCEPT
/usr/sbin/iptables -t nat -A PREROUTING -i br0 -s ! $PROXY_SERVER -p tcp --dport 80 -j DNAT --to $PROXY_SERVER:$PROXY_PORT
/usr/sbin/iptables -t nat -A POSTROUTING -o br0 -s $INTERNAL_NETWORK -p tcp -d $PROXY_SERVER -j SNAT --to $ROUTER_IP
/usr/sbin/iptables -t filter -I FORWARD -s $INTERNAL_NETWORK -d $PROXY_SERVER -i br0 -o br0 -p tcp --dport $PROXY_PORT -j ACCEPT
export TRANSPARENT_PROXY="1"
else
echo "This script has already run!"
echo "If it hasn't, unset \$TRANSPARENT_PROXY manually via the shell."
fi
#########

2. save the script that will work after reboot:

a) Login to the router as admin (root):

ssh root@192.168.1.1

b) paste the script:

# nvram set rc_firewall=" paste edited script here "

press ENTER

c) save script:

# nvram commit

d) Test if script is saved

# nvram get rc_firewall

8 responses to “linksys router (ddwrt) + proxy server”

  1. How can i set login and password? I have a login and password. And i want to connect proxy server with wrt160nl and want to be internet on wrt160nl.

  2. Username and password is part off proxy configuration. So firstly depends on which software you use for proxy.

  3. Hi, I just install a WRT160NL in my lab, I wanted to know if I can configure my proxy settings in my router and allow my network users to access the internet using this credentials.

  4. This is just a script which redirects all users from port 80 to port 3128 on proxy server and then to the internet.

  5. Hey There. I found your blog using msn. This is a really well written article.
    I will be sure to bookmark it and return to read
    more of your useful information. Thanks for the post. I’ll certainly return.

Leave a Reply