Nat and packet limits with iptables

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Special Forums IP Networking Nat and packet limits with iptables
# 1  
Nat and packet limits with iptables

Hi all,

I have a following situation:

- I want certain source IPs to be natted to a different destination IP and Port. Following is how I am achieving it:

/usr/local/sbin/iptables -t nat -A PREROUTING -p tcp -s
  --dport 1500 -j DNAT --to-destination

Above runs on and is working perfectly fine.

- Now, I want that if there are more than, say 20 packets per minute from source IP then further packets should be dropped.

Above is what I am having difficulty to achieve.

I have done the following but is not working:
/usr/local/sbin/iptables -t nat -A PREROUTING -p tcp -s 
  --dport 1500 -m limit --limit 20/m --limit-burst 5 -j DNAT --to-destination

/usr/local/sbin/iptables -t nat -A PREROUTING -p tcp -s
  --dport 1500 -j LOG --log-level 4 --log-prefix " Packet Limit exceeded: "

/usr/local/sbin/iptables -A INPUT -p tcp -s --dport 1500 -j DROP

Can someone help me get the correct statement or confirm whether I can achieve the above requirement through IP tables.

Many thanks for your help.


---------- Post updated at 08:16 AM ---------- Previous update was at 06:44 AM ----------

Sorry... My mistake... the following IPtables command runs perfectly fine on the server where source actualy goes to first. It is not running on

/usr/local/sbin/iptables -t nat -A PREROUTING -p tcp -s
  --dport 1500 -j DNAT --to-destination

Last edited by Scott; 07-25-2013 at 10:24 AM.. Reason: Code tags
# 2  
Seems possible:
Man Page for iptables (all Section 8) - The UNIX and Linux Forums
       This  module  matches at a limited rate using a token bucket filter.  A
       rule using this extension  will	match  until  this  limit  is  reached
       (unless	the `!' flag is used).	It can be used in combination with the
       LOG target to give limited logging, for example.

       --limit rate[/second|/minute|/hour|/day]
	      Maximum average matching rate: specified as a  number,  with  an
	      optional	`/second',  `/minute',	`/hour', or `/day' suffix; the
	      default is 3/hour.

# 3  
Thanks DGPickett for your input.

My issue is how to use limit with NAT packets? My above IPtable command is not working...
# 4  
I suppose you need to use the right address, pre or post-NAT, not sure which, but if post-NAT, the NAT pool for that network needs to be distinct. I would expect IPtables to do NAT after filtering, but maybe it is up to you to order the rules right.

This option may only work on a filtering rule, not on a NAT rule, again not sure.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #982
Difficulty: Medium
NetBSD is a free and open-source Unix-like operating system based on the Berkeley Software Distribution (BSD).
True or False?

10 More Discussions You Might Find Interesting

1. Cybersecurity

Openvpn nat and iptables

good day good people hi first to tell that firewall and vpn is working as expected, but I notice something strange. I have host system ip) firewall is blocking everything except port to vpn. I have vpn on virtualized system (CentOS both host and virtual). ... (0 Replies)
Discussion started by: end
0 Replies

2. UNIX for Dummies Questions & Answers

Soft and hard limits for nproc value in /etc/security/limits.conf file (Linux )

OS version : RHEL 6.5 Below is an excerpt from /etc/security/limits.conf file for OS User named appusr in our server appusr soft nproc 2047 appusr hard nproc 16384 What will happen if appusr has already spawned 2047 processes and wants to spawn 2048th process ? I just want to know... (3 Replies)
Discussion started by: kraljic
3 Replies

3. IP Networking

NAT via iptables - Won't work!!

Hi guys I'm running on debian on a small embedded system. I have a ppp interface that is connected to the internet (and works). My unit also has wifi access point (which works and I can connect to it). I want to allow connections to the wifi to be able to use the internet from ppp0... (1 Reply)
Discussion started by: alirezan1
1 Replies

4. IP Networking

Debugging NAT / prerouting issues (iptables)

Hello, Recently I discovered an issue with packet routing in the latest Android releases (4.4+ KitKat & Lollipop). It seems that the problem Android specific, but essentially it comes from the Linux kernel. I already filed a bug report to Google. You can see the details by searching for... (0 Replies)
Discussion started by: Vladislav
0 Replies

5. Cybersecurity

iptables in a NAT scenario

Hi, I am learning IPTables have this question. My server is behind a firewall that does a PAT & NAT to the LAN address. Internet IP: Port: 10022 Server LAN IP: port: 22 Allowed Internet IPs:, I want to allow a set of IPs are to be able to... (1 Reply)
Discussion started by: capri_guy84
1 Replies

6. Red Hat

NAT Loopback and iptables

Hello, please can you help and explain me. I have two servers. Both are RHEL6. I use the first one like router and the second one for apache. Router forwards 80 port on the second server and I can open that from the internet (, for example). But I can not open if i try to... (0 Replies)
Discussion started by: 6765656755
0 Replies

7. IP Networking

iptables NAT prerouting & postrouting

Good morning, I'm a newbie of iptables and as far as I've seen on tutorials on the Internet it seems that both prerouting and postrouting NAT chains are undergone both by a packet that goes from an internal LAN to the Internet and of a one that goes in the opposite direction (from the Internet to... (0 Replies)
Discussion started by: giac85
0 Replies

8. Debian

Iptables Nat forward port 29070

Hello, the Nat and the forward worked on my debian server up to the reboot of machines. The following rules*: /sbin/iptables -t nat -A PREROUTING -p tcp -i eth2 -d --dport 29070 -j DNAT --to-destination /sbin/iptables -A FORWARD -p tcp -i eth2 -o eth0 -d... (0 Replies)
Discussion started by: titoms
0 Replies

9. IP Networking

How to configure Full Cone NAT using iptables ?

Hi Experts; I want to find the right iptables commands combination to address the following need: - NEs are NATed thru the linux box (using iptables) towards the WAN cloud, where the NTP servers are situated. - In order to achieve redundancy, the NTP Servers are in a load balancing cluster... (0 Replies)
Discussion started by: lvl1s7a
0 Replies

10. UNIX for Advanced & Expert Users

iptables internal NAT with two public IP

Hello Guys, I have a debian machine that work as a firewall (iptables + squid 2.6) with two physical interfaces: eth0 (public interface) and eth1 (internal interface LAN). I have created an alias eth1:1 in order to have two subnets on same physical interface: cat/etc/network/interfaces auto... (0 Replies)
Discussion started by: sincity2006
0 Replies

Featured Tech Videos