

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer

I have seen on many blogs, using this command to enable IP forwarding while using many network security/sniffing tools on linux


Can anyone explain me in layman terms, what essentially does this command do? Does it turn your system into router?

share|improve this question
python file to enable and disable portforwarding gist.github.com/addminuse/7747903cd420b15f17e0 – addminuse Dec 2 '15 at 9:43
up vote 27 down vote accepted

"IP forwarding" is a synonym for "routing." It is called "kernel IP forwarding" because it is a feature of the Linux kernel.

A router has multiple network interfaces. If traffic comes in on one interface that matches a subnet of another network interface, a router then forwards that traffic to the other network interface.

So, let's say you have two NICs, one (NIC 1) is at address, and the other (NIC 2) is If forwarding is enabled, and a packet comes in on NIC 1 with a "destination address" of, the router will resend that packet out of the NIC 2.

It's common for routers functioning as gateways to the Internet to have a default route whereby any traffic that doesn't match any NICs will go through the default route's NIC. So in the above example, if you have an internet connection on NIC 2, you'd set NIC 2 as your default route and then any traffic coming in from NIC 1 that isn't destined for something on will go through NIC 2. Hopefully there's other routers past NIC 2 that can further route it (in the case of the Internet, the next hop would be your ISP's router, and then their providers upstream router, etc.)

Enabling ip_forward tells your Linux system to do this. For it to be meaningful, you need two network interfaces (any 2 or more of wired NIC cards, Wifi cards or chipsets, PPP links over a 56k modem or serial, etc.).

When doing routing, security is important and that's where Linux's packet filter, iptables, gets involved. So you will need an iptables configuration consistent with your needs.

Note that enabling forwarding with iptables disabled and/or without taking firewalling and security into account could leave you open to vulnerabilites if one of the NICs is facing the Internet or a subnet you don't have control over.

share|improve this answer
Right, you'll want to do NAT if NIC 2 is a private IP. Linux can do NAT as well and iptables is the way to set it up. – LawrenceC Jul 13 '14 at 23:22
Does it need a NAT for data going from NIC 2 to NIC 1? – Guten Jul 14 '14 at 0:12
Typically NAT will work from the LAN to the WAN, so if NIC 2 has a private IP, and NIC 1 has a public 1, you do need NAT; specifically, the internet-facing interface (NIC 1 per above) needs a MASQUERADE rule in iptables's POSTROUTING on a chain to do that. See revsys.com/writings/quicktips/nat.html and i.stack.imgur.com/rzz83.png. – LawrenceC Jul 16 '14 at 11:14
In simple words, will it be right if I say that enabling IP forwarding means enabling the machine to pass a packet from one of its NIC to another of its NIC? Also, would it be true if I say enabling IP forwarding is not really required on a machine with a single IP/NIC ? – Sreeraj Nov 21 '14 at 6:37
@ultrasawblade In the case of IP forwarding enabled and having internet connection on NIC 2 and also as the default route, if it receives a packet destined for from NIC 1, what will the router do? – bobo May 14 '15 at 5:30

Your Answer


