2

I'm running squid3 in my Ubuntu 14.04 and tried remote proxy use for study purposes . When I try remote access with another computer in the University LAN, I encounter empty cache log. So I have tried

iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

Then my squid is stop working, soon after starting. How can I revert the changes which I made using the above command??

1
  • Close Voters, what is unclear?
    – A.B.
    Dec 12, 2015 at 14:28

1 Answer 1

1

With sudo iptables -t nat --line-numbers -L you should see something like this:

Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination         
1    REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 3128

Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
num  target     prot opt source               destination

Remove the PREROUTING rule(s) affecting port 3128:

sudo iptables -t nat --line-numbers -L | tac | \
    awk '/redir ports 3128/ {system("sudo iptables -t nat -D PREROUTING "$1)}'

Now check the rules again:

% sudo iptables -t nat --line-numbers -L
Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
num  target     prot opt source               destination

Explanation

iptables -vt nat -L lists the needed rules

% sudo iptables -vt nat -L
Chain PREROUTING (policy ACCEPT 11 packets, 1957 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REDIRECT   tcp  --  eth0   any     anywhere             anywhere             tcp dpt:http redir ports 3128

Chain INPUT (policy ACCEPT 2 packets, 194 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 152 packets, 14386 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 152 packets, 14386 bytes)
 pkts bytes target     prot opt in     out     source               destination

And we need the rules for port 3128 in reverse order, if you have more than one, and the line-numbers

% sudo iptables -t nat --line-numbers -L | tac | awk '/redir ports 3128/'
1    REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 3128

a little bit awk magic deletes the rules line by line

awk '/redir ports 3128/ {system("sudo iptables -t nat -D PREROUTING "$1)}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .