LinuxQuestions.org
Review your favorite Linux distribution.
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 07-28-2015, 01:21 PM   #1
Rohant
Member
 
Registered: Oct 2011
Location: India, Mumbai
Distribution: RHEL, Fedora,Ubuntu, Centos, Windows XP & Windows 7
Posts: 44

Rep: Reputation: Disabled
Assign IPtables rules to three different Ethernet Interfaces on same Server


HI,

Please help / suggest on my iptables issue. i having a server Centos 6.5 which ip is "10.0.0.2". server is in NIC bonding using eth0 & eth1. i am able to successfully implement iptables rule using below mentioned script on bond0.

##########################################
#!/bin/bash
/sbin/iptables -F
/sbin/iptables -A INPUT -i lo -j ACCEPT

###For Accessing Port 22
/sbin/iptables -A INPUT -i bond0 -s 10.0.0.5 -d $1 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -i bond0 -s 10.0.0.6 -d $1 -p tcp --dport 22 -j ACCEPT

###For Accessing Port 80
/sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

###For Accessing Port 3306
/sbin/iptables -A INPUT -i bond0 -s 10.0.0.5 -d $1 -p tcp --dport 3306 -j ACCEPT

###For Ping Reply
/sbin/iptables -A INPUT -i bond0 -s 10.0.0.5 -d $1 -p icmp -j ACCEPT

### For Established connections
/sbin/iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

### Drop All connections
/sbin/iptables --policy INPUT DROP

### Accept only Related and established connections
/sbin/iptables -A FORWARD -i bond0 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables --policy OUTPUT ACCEPT
/sbin/iptables-save
##########################################

But now we wanted to assign two more ip's on the same server by creating interface alias. i successfully created & assigned ip to newly created bond0:1 (IP 10.0.0.3) & bond0:2 (IP 10.0.0.4)

But i face the issue that after running above mentioned script using command "sh iptables.sh 10.0.0.2" i am not able to connect ip's which assigned to bond0:1 & bond0:2 interface. i am confused that even after mentioning interface name in script iptables applying its rule to all interface & rejecting incoming request for other interface IP's (eg. bond0:1 & bond0:2).

Please advice how can implement three different iptables rules for three different Ethernet interfaces. i also tried using below mentioned script but still unsuccessful.

Please guide what i am missing or my mistake.

######################################
#!/bin/bash
/sbin/iptables -F
/sbin/iptables -A INPUT -i lo -j ACCEPT

###For Accessing Port 22
/sbin/iptables -A INPUT -i bond0 -s 10.0.0.5 -d $1 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -i bond0:1 -s 10.0.0.5 -d $1 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -i bond0:2 -s 10.0.0.5 -d $1 -p tcp --dport 22 -j ACCEPT

###For Accessing Port 80
/sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

###For Accessing Port 3306
/sbin/iptables -A INPUT -i bond0 -s 10.0.0.5 -d $1 -p tcp --dport 3306 -j ACCEPT
/sbin/iptables -A INPUT -i bond0:1 -s 10.0.0.5 -d $1 -p tcp --dport 3306 -j ACCEPT
/sbin/iptables -A INPUT -i bond0:2 -s 10.0.0.5 -d $1 -p tcp --dport 3306 -j ACCEPT

###For Ping Reply
/sbin/iptables -A INPUT -i bond0 -s 10.0.0.5 -d $1 -p icmp -j ACCEPT
/sbin/iptables -A INPUT -i bond0:1 -s 10.0.0.5 -d $1 -p icmp -j ACCEPT
/sbin/iptables -A INPUT -i bond0:2 -s 10.0.0.5 -d $1 -p icmp -j ACCEPT

### For Established connections
/sbin/iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

### Drop All connections
/sbin/iptables --policy INPUT DROP

### Accept only Related and established connections
/sbin/iptables -A FORWARD -i bond0 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i bond0:1 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i bond0:2 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables --policy OUTPUT ACCEPT
/sbin/iptables-save
######################################
 
Old 07-29-2015, 05:55 AM   #2
wildwizard
Member
 
Registered: Apr 2009
Location: Oz
Distribution: slackware64-14.0
Posts: 875

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by Rohant View Post
But now we wanted to assign two more ip's on the same server by creating interface alias. i successfully created & assigned ip to newly created bond0:1 (IP 10.0.0.3) & bond0:2 (IP 10.0.0.4)

But i face the issue that after running above mentioned script using command "sh iptables.sh 10.0.0.2" i am not able to connect ip's which assigned to bond0:1 & bond0:2 interface. i am confused that even after mentioning interface name in script iptables applying its rule to all interface & rejecting incoming request for other interface IP's (eg. bond0:1 & bond0:2).
You only have one interface it is bond0

Any documentation your looking at that uses the int:alias notation is over a decade out of date and I don't think it ever applied to iptables.
 
Old 07-29-2015, 08:29 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
I've always been very lazy and used Shorewall to set up and manage iptables rules. You can very easily apply rules to multiple interfaces.
 
  


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
Maximum interfaces or rules for iptables scrupul0us Linux - Networking 3 04-20-2013 04:37 AM
Require iptables rules for web server splinux Linux - Server 7 07-12-2011 05:11 AM
iptables rules for an FTP server jsmith6 Slackware 0 07-30-2009 03:58 PM
iptables rules for web server email server,ftp and ssh,please help lightwing Linux - Networking 1 03-25-2009 08:58 PM
Some iptables rules are not working on Ubuntu 8.10 server PossumJerky Linux - Security 1 02-04-2009 07:47 AM

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

All times are GMT -5. The time now is 01:59 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