LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 04-27-2021, 07:14 AM   #1
danm_user
LQ Newbie
 
Registered: Apr 2021
Posts: 2

Rep: Reputation: Disabled
Is possible to configure multiple interfaces in one rule in/out for default and custom chains?


Hi all,

I'm having the following scenario:
- multiple custom chains;
- multiple default chains rules that points to those custom chains;

Below is an example:

Chain INPUT (policy ACCEPT)
num pkts bytes target prot opt in out source destination
1 0 0 DanM_test1 all -- eth2 * 0.0.0.0/0 0.0.0.0/0
2 0 0 DanM_test1 all -- lo * 0.0.0.0/0 0.0.0.0/0

Chain FORWARD (policy ACCEPT)
num pkts bytes target prot opt in out source destination
1 0 0 DanM_test2 all -- vlan350 * 0.0.0.0/0 0.0.0.0/0
2 0 0 DanM_test2 all -- * vlan350 0.0.0.0/0 0.0.0.0/0
3 0 0 DanM_test2 all -- * lo 0.0.0.0/0 0.0.0.0/0
4 0 0 DanM_test3 all -- eth2 eth1 0.0.0.0/0 0.0.0.0/0

Chain OUTPUT (policy ACCEPT)
num pkts bytes target prot opt in out source destination

Chain DanM_test1 (2 references)
num pkts bytes target prot opt in out source destination
1 0 0 ACCEPT tcp -- eth2 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
2 0 0 REJECT tcp -- eth1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 reject-with icmp-port-unreachable
3 0 0 ACCEPT tcp -- eth1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
4 0 0 ACCEPT tcp -- * eth2 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
5 0 0 REJECT tcp -- * lo 0.0.0.0/0 0.0.0.0/0 tcp dpt:23 reject-with icmp-port-unreachable


Chain DanM_test2 (3 references)
num pkts bytes target prot opt in out source destination
1 0 0 ACCEPT tcp -- vlan350 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22

Chain DanM_test3 (1 references)
num pkts bytes target prot opt in out source destination
1 0 0 ACCEPT tcp -- eth0 eth1 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
2 0 0 ACCEPT tcp -- eth0 vlan350 0.0.0.0/0 0.0.0.0/0 tcp dpt:22

My question/questions is/are related if I can configure multiple interfaces for one rule, custom chain or default chains?

For example in custom-chain rules:

sudo iptables -A DanM_test1 -i eth1,eth2 -o eth3,eth4 -j ACCEPT -> eth1 eth2, eth3, eth4 are all different interfaces

After adding this line my iptables rules look as bellow:

Chain DanM_test1 (2 references)
num pkts bytes target prot opt in out source destination
1 0 0 ACCEPT tcp -- eth2 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
2 0 0 REJECT tcp -- eth1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 reject-with icmp-port-unreachable
3 0 0 ACCEPT tcp -- eth1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
4 0 0 ACCEPT tcp -- * eth2 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
5 0 0 REJECT tcp -- * lo 0.0.0.0/0 0.0.0.0/0 tcp dpt:23 reject-with icmp-port-unreachable
6 0 0 ACCEPT all -- eth1,eth2 eth3,eth4 0.0.0.0/0 0.0.0.0/0

Example for default INPUT/FORWARD chains:

sudo iptables -A FORWARD -i eth1, vlan350 -o eth3, vlan351 -j DanM_test1 -> eth1, vlan350, eth3, vlan351 are different interfaces

I'm receiving:
Bad argument `vlan350'
Try `iptables -h' or 'iptables --help' for more information.

Thank you,
Dan
 
Old 05-01-2021, 12:15 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,256

Rep: Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321
I'm not the world's expert on this by any means, but at 555 views and no answers, let me call it.


It's not good to do as you suggest. Stick to 1 interface, one address range, one instruction. Read the configuration man page, e.g. 'man iptables.conf' or download internet examples. Test your results by connecting your nic to another pc, giving it a static ip of your choice, and sending packets.

The resulting config will also be easier to read, and edit. Group things intelligently. If it's firewall rules, you can rest assured you will be back, and it's good to at least start with an easy-to-read file.

I (not the world's expert on this by any means) also thought the standard order was
allow this
allow that
allow the other
deny all

which ensures that everything you haven't thought of gets blocked. I'd really suggest you read some more, and get a feel for it yourself.
 
1 members found this post helpful.
Old 05-04-2021, 02:47 AM   #3
elcore
Senior Member
 
Registered: Sep 2014
Distribution: Slackware
Posts: 1,753

Rep: Reputation: Disabled
Quote:
Originally Posted by business_kid View Post
I (not the world's expert on this by any means) also thought the standard order was
allow this
allow that
allow the other
deny all
It's sometimes better to specify a drop before and after the accept (if they are added to chain, if they are injected to chain that's a different story).
Mine have always looked something like this:

- many multiport, iprange, and protocol drops.
- couple of wide range statefull accepts
- drop all

And for the OP: may be possible but never really looked into it, personally I just specify separate rules for each interface.
 
1 members found this post helpful.
Old 05-04-2021, 04:31 AM   #4
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,256

Rep: Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321
Quote:
Originally Posted by elcore
It's sometimes better to specify a drop before and after the accept (if they are added to chain, if they are injected to chain that's a different story).
Yes.
 
1 members found this post helpful.
Old 05-05-2021, 12:40 AM   #5
amrs
LQ Newbie
 
Registered: Mar 2020
Posts: 6

Rep: Reputation: Disabled
Quote:
Originally Posted by danm_user View Post

sudo iptables -A FORWARD -i eth1, vlan350 -o eth3, vlan351 -j DanM_test1 -> eth1, vlan350, eth3, vlan351 are different interfaces

I'm receiving:
Bad argument `vlan350'
Try `iptables -h' or 'iptables --help' for more information.
Assuming you copy-pasted the exact command I think the specific issue here causing the error message is that your interfaces aren't comma separated, they are separated by comma and space. So iptables sees vlan350 as a separate argument and hence reports bad argument.

As for specifying multiple interfaces in one go, I don't see a problem.
 
1 members found this post helpful.
Old 05-17-2021, 09:19 AM   #6
danm_user
LQ Newbie
 
Registered: Apr 2021
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you so much for your responses, we solved the problem , is a hard scenario indeed and we figure out what was needed for our scenario.
 
  


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
iptables multiple interfaces same subnet to multiple vlan interfaces krobinson Linux - Server 3 04-22-2015 04:25 AM
mangle and custom chains rs232 Linux - Networking 2 03-14-2015 07:25 PM
Custom chains for IPTables Beorn1357 Linux - Security 5 09-07-2014 04:12 AM
Custom chains in Iptables colucix Linux - Networking 2 07-11-2008 08:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:05 AM.

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