Com sudo iptables -t nat --line-numbers -L
você deve ver algo assim:
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
Remova as regras PREROUTING
que afetam a porta 3128
:
sudo iptables -t nat --line-numbers -L | tac | \
awk '/redir ports 3128/ {system("sudo iptables -t nat -D PREROUTING ")}'
Agora verifique as regras novamente:
% 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
Explicação
iptables -vt nat -L
lista as regras necessárias
% 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
E precisamos das regras para a porta 3128
na ordem inversa, se você tiver mais de uma, e os números de linha
% sudo iptables -t nat --line-numbers -L | tac | awk '/redir ports 3128/'
1 REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 3128
um pouco awk
magic apaga as regras linha a linha
awk '/redir ports 3128/ {system("sudo iptables -t nat -D PREROUTING ")}'