3

How do I remove the double

-A POSTROUTING -j MASQUERADE 

line that I have on a Ubuntu server?

This is what I have done:

root@ts:~# iptables -t nat -A POSTROUTING -j MASQUERADE
root@ts:~# sysctl -p /etc/sysctl.conf
net.ipv4.ip_forward = 1
root@ts:~# iptables-save > /etc/iptables.up.rules
root@ts:~# vi /etc/network/interfaces
root@ts:~# iptables-save 
# Generated by iptables-save v1.4.10 on Thu Sep 22 18:00:07 2011
*nat
:PREROUTING ACCEPT [184:27845]
:INPUT ACCEPT [32:6346]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -j MASQUERADE 
-A POSTROUTING -j MASQUERADE 
COMMIT
# Completed on Thu Sep 22 18:00:07 2011
root@ts:~# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
root@ts:~# 

4 Answers 4

7
# iptables -t nat -D POSTROUTING -j MASQUERADE
5

-D will delete the rule you already placed., Just type the same rule you did before and change the -A (append) to -D (delete).

Additionally, since you have no other rules in your table, you can flush all rules and re-add the nat rule. " iptables -F "

2

you don't need to count the rows, instead type:

iptables -L -v -t nat --line-numbers.

Now just use that row number on the left. Much easier.

1
    1.

$ iptables -L -v -t nat

count rows

and then

$ iptables -t nat -D POSTROUTING 5

where 5 is you row number for rules-to-delete

Or 2.

$ iptables-save > myfile

edit myfile in you favorite editor (delete row)

$ iptables-restore < myfile

You must log in to answer this question.

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