LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-03-2016, 10:05 AM   #1
ankit,garg
LQ Newbie
 
Registered: Jan 2012
Location: Noida,India
Posts: 20

Rep: Reputation: Disabled
iptables command gets executed successfully but its impact is not visible.


Hi!

I am facing a problem where I want to use iptables commands to drop the incoming packets, I execute the iptables command, it gets executed but its effect is not visible.

Details:

OS: Cent OS 7 / Fedora 21
Kernel: 3.11.7

Network setup:

I have two ethernet interface on my machine eth0 and eth1 where eth0 is connected to the internet (say with IP 192.168.1.10) and eth1 is connected to a stb. I create a bridge with below commands and bridge eth0 and eth1 so that the stb gets IP and network connectivity through this bridge. STB obtains IP 192.168.1.20

brctl addbr test_stb
brctl addif test_stb eth0
brctl addif test_stb eth1

ifconfig test_stb up

Usgae of this setup: From an another machine with IP 192.168.1.5 I am multicasting a H264 udp transport stream on IGMP group 233.0.0.248:1112. STB joins this multicast group and plays the incoming transport stream on it.

So, my machine having bridge between eth0 and eth1 is receiving the transport stream in form of udp packets on interface eth0 and getting redirected to interface eth1 through the bridge interface test_Stb.

Requirement of iptables: I am using below iptables command to drop the incoming udp packets so that stb do not get the transport stream.

iptables -A FORWARD -i test_stb -d 233.0.0.248 -p udp --dport 1112 -j DROP

or

iptables -A FORWARD -i test_stb -d 233.0.0.0/24 -p udp -j DROP
iptables-save

Above commands gets executed successfully but it's impact is not visible i.e. the incoming udp packets are not getting dropped.

I googled about this problem and I found that the newer versions of Cent OS and Fedora has included firewalld and replaced the iptables but; It is still possible to use the iptables by disabling the firewalld module on the machine. I tried below commands to disable the firewalld and using the iptables but it didn't help me as the outcome of executing iptables command is still same as stated above

systemctl mask firewalld

systemctl stop firewalld

yum -y install iptables-services

systemctl enable iptables

systemctl enable ip6tables

systemctl start iptables

systemctl start ip6tables

I even checked the running status of firewalld by command "firewall-cmd --state" and it returns status as "not running".

Please help me to troubleshoot this issue. The strange thing is that above mentioned iptables commands runs and gives its impact perfectly fine on using a older version of fedora 18 / CentOS 5 which do not have firewalld module in it.

TIA
Ankit
 
Old 05-03-2016, 11:12 AM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Try using the Preroute for this:

Code:
iptables -t mangle -A PREROUTING -i eth0 -d 233.0.0.248 -p udp --dport 1112 -j DROP
or
iptables -t mangle -A PREROUTING -i eth0 -d 233.0.0.0/24 -p udp -j DROP
The second being the better choice as you don't always know.

I too am not a fan of firewalld so I also replaced it with iptables.
 
Old 05-04-2016, 02:37 AM   #3
ankit,garg
LQ Newbie
 
Registered: Jan 2012
Location: Noida,India
Posts: 20

Original Poster
Rep: Reputation: Disabled
Hi lazydog!

Thanks for your reply.

I tried the commands as suggested by you but the result is still same i.e. The command got executed but it's effect is not visible.

I even tried below command which also works on a older version of fedora 18 / CentOS 5 which do not have firewalld module in it. But, below commands are also not working on Cent OS 7

iptables -t raw -A PREROUTING -i eth0 -d 233.0.0.0/24 -p udp -j DROP

or

iptables -t raw -A PREROUTING -i eth0 -d 233.0.0.248 -p udp --dport 1112 -j DROP

Is there any log file in which iptables writes its log where we can check what could be happening )
 
Old 05-04-2016, 02:53 PM   #4
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Are you sure your system is using iptables? You should check.
 
Old 05-06-2016, 05:49 AM   #5
ankit,garg
LQ Newbie
 
Registered: Jan 2012
Location: Noida,India
Posts: 20

Original Poster
Rep: Reputation: Disabled
That is about I have suspicion if my system is using iptables or not. How can I check that ?
 
Old 05-06-2016, 10:38 AM   #6
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quick way would be:

Code:
systemctl | grep firewall
 
Old 05-09-2016, 03:54 AM   #7
ankit,garg
LQ Newbie
 
Registered: Jan 2012
Location: Noida,India
Posts: 20

Original Poster
Rep: Reputation: Disabled
I have made sure that firewall is not running. In my first post I verified this by running command "firewall-cmd --state" and it returns status as "not running".

So, I am sure that firewalld is not running.
 
Old 05-09-2016, 07:04 AM   #8
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
OK so what do you get with the following command?

Code:
iptables -nL
If everything here checks out the next step is going to be a capture of your traffic to see exactly what IP and port are being used.
 
Old 05-09-2016, 07:41 AM   #9
ankit,garg
LQ Newbie
 
Registered: Jan 2012
Location: Noida,India
Posts: 20

Original Poster
Rep: Reputation: Disabled
I ran the suggested commands and below is the result

Code:
[root@localhost 6.1.1_1]# systemctl | grep firewall
ip6tables.service                                                                         loaded active exited    IPv6 firewall with ip6tables
iptables.service                                                                          loaded active exited    IPv4 firewall with iptables


[root@localhost 6.1.1_1]# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
DROP       udp  --  0.0.0.0/0            224.0.251.1          udp dpt:8002

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination      


[root@localhost 6.1.1_1]# iptables-save
# Generated by iptables-save v1.4.21 on Mon May  9 14:38:36 2016
*mangle
:PREROUTING ACCEPT [748:693151]
:INPUT ACCEPT [4:336]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4:336]
:POSTROUTING ACCEPT [4:336]
-A PREROUTING -d 224.0.251.1/32 -i br_iface -p udp -j DROP
-A PREROUTING -d 224.0.251.0/24 -i br_iface -p udp -j DROP
COMMIT
# Completed on Mon May  9 14:38:36 2016
# Generated by iptables-save v1.4.21 on Mon May  9 14:38:36 2016
*filter
:INPUT ACCEPT [4:336]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4:336]
-A FORWARD -d 224.0.251.1/32 -i br_iface -p udp -m udp --dport 8002 -j DROP
COMMIT
# Completed on Mon May  9 14:38:36 2016

Last edited by ankit,garg; 05-09-2016 at 08:46 AM.
 
Old 05-09-2016, 08:42 AM   #10
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Those "-d 224" should be "-s 224".
 
Old 05-09-2016, 08:52 AM   #11
ankit,garg
LQ Newbie
 
Registered: Jan 2012
Location: Noida,India
Posts: 20

Original Poster
Rep: Reputation: Disabled
I tried it replacing the command from

Code:
iptables -A FORWARD -i br_iface -d 224.0.251.1 -p udp --dport 8002 -j DROP
to

Code:
iptables -A FORWARD -i br_iface -s 224.0.251.1 -p udp --dport 8002 -j DROP
Code:
[root@localhost 6.1.1_1]# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
DROP       udp  --  224.0.251.1          0.0.0.0/0          udp dpt:8002

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

But it did not have any effect on it. STB is still receiving the multicast stream. Please note that I am applying these rules on my bridge interface.

Last edited by ankit,garg; 05-09-2016 at 08:54 AM.
 
Old 05-09-2016, 09:23 AM   #12
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
How about applying them to the internet interface eth1 or eth0?
 
Old 05-10-2016, 03:17 AM   #13
ankit,garg
LQ Newbie
 
Registered: Jan 2012
Location: Noida,India
Posts: 20

Original Poster
Rep: Reputation: Disabled
Hi Again,

I tried applying iptables rules on each interface. This time to be very simple I applied the rule in the INPUT chain to drop every type of packet and not specific packets like udp. But the ipables are still not leaving its effect. Below is the snapshot what I did from reboot of the machine.

When machine is rebooted then the interface configuration looks like below

Code:
[root@localhost ~]# ifconfig
em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::3e97:eff:fef0:cca8  prefixlen 64  scopeid 0x20<link>
        ether 3c:97:0e:f0:cc:a8  txqueuelen 1000  (Ethernet)
        RX packets 157  bytes 41818 (40.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 260  bytes 19128 (18.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xf2500000-f2520000  

enp0s20u1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:50:b6:59:46:21  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 464  bytes 40432 (39.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 464  bytes 40432 (39.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
After that I created the bridge interface and added both ethernet devices to it

Code:
[root@localhost ~]# brctl addbr br_iface
[root@localhost ~]# brctl addif br_iface em1
[root@localhost ~]# brctl addif br_iface enp0s20u1
[root@localhost ~]# ifconfig br_iface up
[root@localhost ~]# ifconfig br_iface hw ether 3c:97:0e:f0:cc:a8

br_iface: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::250:b6ff:fe59:4621  prefixlen 64  scopeid 0x20<link>
        ether 3c:97:0e:f0:cc:a8  txqueuelen 0  (Ethernet)
        RX packets 626  bytes 840617 (820.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5  bytes 418 (418.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::3e97:eff:fef0:cca8  prefixlen 64  scopeid 0x20<link>
        ether 3c:97:0e:f0:cc:a8  txqueuelen 1000  (Ethernet)
        RX packets 10732  bytes 14403886 (13.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 270  bytes 19896 (19.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xf2500000-f2520000  

enp0s20u1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:50:b6:59:46:21  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 464  bytes 40432 (39.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 464  bytes 40432 (39.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
Checked if the bridge is successfully created or not

Code:
[root@localhost ~]# brctl show
bridge name	bridge id		STP enabled	interfaces
br_iface		8000.3c970ef0cca8	no		em1
							enp0s20u1
Checked if the iptables service is running or not

Code:
[root@localhost 6.1.1_1]# systemctl | grep firewall
ip6tables.service                                                    loaded active exited    IPv6 firewall with ip6tables
iptables.service                                                     loaded active exited    IPv4 firewall with iptables
Checked the iptables rules if there are any

Code:
[root@localhost ~]# iptables -nL
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@localhost ~]#
Added iptables rules in the INPUT chain and later listed the rules

Code:
[root@localhost ~]# iptables -A INPUT -i br_iface -j DROP
[root@localhost ~]# iptables -A INPUT -i em1 -j DROP
[root@localhost ~]# iptables -A INPUT -i enp0s20u1 -j DROP
[root@localhost ~]# 
[root@localhost ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       all  --  0.0.0.0/0            0.0.0.0/0           
DROP       all  --  0.0.0.0/0            0.0.0.0/0           
DROP       all  --  0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
[root@localhost ~]#
No effect of iptables is visible. I can access everything from stb.
 
Old 05-10-2016, 04:25 AM   #14
ankit,garg
LQ Newbie
 
Registered: Jan 2012
Location: Noida,India
Posts: 20

Original Poster
Rep: Reputation: Disabled
One more thing I found during my investigation, the iptables rules are effective on an ethernet interface without adding it to the bridge interface i.e. I rebooted the machine and applied the below iptables rule on em1

Code:
iptables -A INPUT -i em1 -p all -j DROP
then I was not able to access anything from my machine. On applying below iptables rule

Code:
iptables -A INPUT -i em1 -p tcp -j DROP
I was not able to browse websites from a webbrowser but I was able to ping 8.8.8.8 and received the icmp packets. On applying below iptables rule

Code:
iptables -A INPUT -i em1 -p icmp -j DROP
The ping stopped working and I was able to browse website through web browser.

It looks like that these iptables are not getting effective when I add my both ethernet interface in a bridge and also not effective on a bridge interface.
 
Old 05-10-2016, 08:20 AM   #15
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
OK, so you have the following interfaces:
  1. em1
  2. enp0s20u1

Which one of these is the external interface?
In which direction are you trying to stop the flow?

Lets start with the basics and work our way up.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] timestamp of command history doesn't show time command was executed? UprLftCstr Linux - Newbie 3 04-17-2014 12:31 PM
ShellScript executed from command prmpt but not executed from crontab or at command BMMadhav Linux - Newbie 1 11-16-2012 07:20 PM
How can I lessen the impact of bandwidth attacks with IPTables or APF? seisatsu Linux - Server 1 04-27-2011 12:51 AM
LXer: Open Source Impact on Software Innovation Outweighs Impact on ... LXer Syndicated Linux News 0 08-15-2006 01:54 PM
iptables disallowd port becomes visible antken Linux - Networking 4 11-25-2002 04:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration