Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:~# 
share|improve this question

4 Answers 4

up vote 5 down vote accepted
# iptables -t nat -D POSTROUTING -j MASQUERADE
share|improve this answer

-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 "

share|improve this answer

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.

share|improve this answer
    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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.