iptables not logging a FORWARD rule

I am trying to learn iptables and virtualbox.

I have 3 Centos7 VMs configured as follows with iptables configured on VM2. All interfaces are configured as "host only adapter" in virtual box as /24 networks:

VM1 - - - - - - - - -  - - VM2- - - - - - - - - - -VM3   

iptables is configured on VM2 as follows:

LINE 1: -A INPUT -s -d -j LOG
LINE 2: -A FORWARD -s -d -j LOG
LINE 3: -A FORWARD -s -d -j LOG
LINE 4: -A FORWARD -s -d -j LOG

When I send data using scapy -- send(IP(src="n.n.n.n", dst="y.y.y.y")/TCP()) -- the traffic flow described on LINES 1, 2 and 4 is logged. But the flow from LINE 3 is not.

I have tried LINE 3 using INPUT and OUTPUT rules without success.

What am I missing?

LVL 16
Steve JenningsSr Manager Cloud Networking OpsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
INPUT & OUTPUT are not applicable on packets that are forwarded using the ROUTING engine.
There are no nat rules involved?   (In that case those are processes first (PREROUTING) or last (POSTROUTING).

INPUT only is used in INCOMING packets into the system, OUTPUT only for packets leaving the system (both not for forwarding).
FORWARDING is the passthrough chain.

Didn't you swap the addresses & I would expect in INPUT and on FORWARD with the addresses mentioned in your schema.
Steve JenningsSr Manager Cloud Networking OpsAuthor Commented:
Thanks for the comment noci . . . no, the addresses in the primitive pic and the iptables are as shown. iptables logs -> as "FORWARD" even though is an address on VM2 and it does NOT log ->
Steve JenningsSr Manager Cloud Networking OpsAuthor Commented:
pkts bytes target     prot opt in     out     source               destination        
    7   280 LOG        all  --  *      *        LOG flags 6 level 6 prefix "192 to 192  "

Chain FORWARD (policy ACCEPT 141 packets, 5744 bytes)
 pkts bytes target     prot opt in     out     source               destination        
    7   280 LOG        all  --  *      *             LOG flags 6 level 6 prefix "192 to .2  "
    0     0 LOG        all  --  *      *             LOG flags 6 level 6 prefix "192 to .1  "
Maximize Customer Retention with Superior Service

The IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more to help build customer satisfaction and retention.

Steve JenningsSr Manager Cloud Networking OpsAuthor Commented:
Sorry . . . should have set that to a fixed font
nociSoftware EngineerCommented:
It may show FORWARD because it is First routed internally to the other interface and then enter the system..., never checked how the firewall would handle that case.
You probably mean it does not log: ->
What does the following show:
iptables -L -nv FORWARD
iptables -L -nv INPUT

Open in new window

Steve JenningsSr Manager Cloud Networking OpsAuthor Commented:
yes . . . sorry . . . does not log ->
nociSoftware EngineerCommented:
What does tcpdump show?  while running scapy?.... the iptables rules look ok to me.
Steve JenningsSr Manager Cloud Networking OpsAuthor Commented:
That's also very odd . . . tcpdump shows identical entries when taken from VM2 . . . that is the packets -- other than the dst addr -- look identical.

Also, -> also works / logs and the only difference is that VM2 doesn't have a interface.

Steve JenningsSr Manager Cloud Networking OpsAuthor Commented:
For what it's worth, I added another secondary IP to VM2,, and it doesn't log either . . . the problem seems to relate only to IP subnet addresses that appear on both the iptables machine and VM3. Then I removed from VM3 and on VM2 still does not log.

Clearly I have some sort of non-configuration issue . . .
nociSoftware EngineerCommented:
For forwarding to work you also need routing, otherwise the routing engine will swallow the packets...,
Is routing setup?
ip route show
netstat -rn

BTW, i just verified that a packet that ends up on the local system IS NOT logged on a forwarding rule.
So please check your setup carefully.

So if VM2 has and then those will not be handled by FORWARD.  but only on INPUT. (BOTH).
Steve JenningsSr Manager Cloud Networking OpsAuthor Commented:
All works as expected now. I changed the interface type to "internal" for the connection between VM1 and VM2 and everything works as I would expect. For whatever reason, when the interface type was set to "host only" between VM1 and VM2, VM3 was getting traffic directly from VM1, bypassing VM2 and iptables . . . even though this isn't how I understand the "host only" interface to work.

thanks for your input.

nociSoftware EngineerCommented:
If you say Hostly only network you need to create TWO:
   - One between VM1 and VM2 and
   - Another one between VM2 - VM3.
Like you seem to show in your drawing.
Appearantly you created one hostonly network to connect all.
By introducing the internal "network" you split it into two networks causing the routing to work as expected.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.