LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-08-2014, 12:44 PM   #1
kamran.ayub
Member
 
Registered: Jan 2012
Posts: 72

Rep: Reputation: Disabled
Assigning variables in Iptables centos


Dear All,

I want to assign variables in iptables file.(/etc/sysconfig/iptables) generated by iptables-save script. But its not working.
Following is my iptables file. and OS is Centos.

##################################
*filter
:INPUT ACCEPT [189:21747]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [174:24924]
Jesse="73.185.155.233"
rmrg="23.24.136.233"
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 811 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m tcp -s $Jesse -j ACCEPT
-A INPUT -p udp -m udp -s $Jesse -j ACCEPT
-A INPUT -p tcp -m tcp -s $rmrg -j ACCEPT
-A INPUT -p udp -m udp -s $rmrg -j ACCEPT
-A INPUT -p tcp -m tcp -j DROP
-A INPUT -p udp -m udp -j DROP
COMMIT
##############################

Please help. What is correct way of assigning variables in iptables file.

Regards.
Kamran

Last edited by kamran.ayub; 11-08-2014 at 01:00 PM. Reason: replacing iotables with iptables
 
Old 11-09-2014, 08:25 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,494

Rep: Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841
As far as I know you need to use a bash script to load rules based on variables. There are many examples that can be found on the net.

Last edited by michaelk; 11-09-2014 at 08:26 PM.
 
Old 11-10-2014, 12:37 AM   #3
kamran.ayub
Member
 
Registered: Jan 2012
Posts: 72

Original Poster
Rep: Reputation: Disabled
Dear michaelk,

Can you please guide me about any link for bash script of iptables which is tested one.
I have already tried one with script but failed.

Regards,
Kamran
 
Old 11-10-2014, 07:00 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,494

Rep: Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841
What have you tried?

http://wiki.centos.org/HowTos/Network/IPTables
http://www.cyberciti.biz/faq/rhel-fe...ation-tutorial
 
Old 11-10-2014, 10:31 PM   #5
kamran.ayub
Member
 
Registered: Jan 2012
Posts: 72

Original Poster
Rep: Reputation: Disabled
Dear michaelk,

I have tried this script before. Issue with my script is when ever I activate my script, my SSH connection goes down.
I think below default policies don't let my traffic to go pass through my ssh traffic.

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT


Can you please help if I am wrong or right on this? A workaround which I have done to clear this situation is I rebooted my machine physically and then firewall script stopped automatically and I am able to ssh my machine.

regards,
Kamran
 
Old 11-10-2014, 11:07 PM   #6
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 587

Rep: Reputation: 72
From post #3's first link:

Quote:
Code:
iptables -P INPUT ACCEPT
If connecting remotely we must first temporarily set the default policy on the INPUT chain to ACCEPT otherwise once we flush the current rules we will be locked out of our server.
 
Old 11-10-2014, 11:40 PM   #7
kamran.ayub
Member
 
Registered: Jan 2012
Posts: 72

Original Poster
Rep: Reputation: Disabled
Dear ilestrg,

Don't u think that "iptables -P INPUT ACCEPT" will accept all incoming traffic.
Because iptables rules run by their order. Rules for incoming traffic under this must not be worthable after this.

Am i right or wrong?

regards,
Kamran Ayub
 
Old 11-11-2014, 07:44 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,494

Rep: Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841Reputation: 5841
With drop as the default policy you need to add rules for input and output. Having a default policy as accept and then as the last rule drop everything in the end works the same.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
repetition and variables : declaring and assigning technomeister Programming 5 02-12-2010 11:23 AM
Assigning variables in a bash for loop JDska55 Linux - Newbie 6 06-18-2009 04:37 PM
Assigning variables by awk(?) bioinformatics_guy Linux - Newbie 2 02-19-2009 01:01 PM
help with a little perl script and assigning variables sal_paradise42 Programming 8 10-15-2008 01:44 PM
C++ Assigning attributes to variables ? xconspirisist Programming 16 11-05-2003 07:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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