LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-22-2015, 07:50 AM   #1
secrets88
LQ Newbie
 
Registered: Jun 2015
Posts: 17
Blog Entries: 1

Rep: Reputation: Disabled
Manipulate variables with iptables (script.sh)


Hello,

For example I have 10 servers and wanted to do a configuration (at the iptables) for a single server, but this configuration should be taken into account by other servers.

For example I have the @ 192.168.22.190 of my server and @ 171.135.1.23 of the router,
I want to create a script that aims to:

If I change the @ SERVER = "192.168.22.190", the other servers should consider the change.

Here is a try that I did and I know is that it will work or not



SERVER="192.168.22.190"
for ROUTER in 171.135.1.23;
do
iptables -A INPUT -m state --state NEW -m tcp -s $SERVER -p tcp -- match multiport --dports 22,8080 -j ACCEPT
done


I'am sorry for my english and thanks
 
Old 06-23-2015, 07:55 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by secrets88 View Post
For example I have 10 servers and wanted to do a configuration (at the iptables) for a single server, but this configuration should be taken into account by other servers.
When you run iptables on one server, it only affects this one server. You will have to run iptables on each of the other servers as well.

Quote:
SERVER="192.168.22.190"
for ROUTER in 171.135.1.23;
do
iptables -A INPUT -m state --state NEW -m tcp -s $SERVER -p tcp --match multiport --dports 22,8080 -j ACCEPT
done
This code opens ports 22 and 8080 for packets from 192.168.22.190. I don't understand the purpose of the for loop - it does effectively nothing, and the ROUTER variable is not used at all. The semicolon is superfluous as well.

In other words, your code is 100% equivalent to
Code:
SERVER="192.168.22.190"
iptables -A INPUT -m state --state NEW -m tcp -s $SERVER -p tcp --match multiport --dports 22,8080 -j ACCEPT
If you want to open these ports on all your servers, perhaps something like this will be the solution:
Code:
for SERVER in <list of all your IP addresses or server hostnames>
do
    ssh $SERVER iptables -A INPUT -m state --state NEW -m tcp -s 192.168.22.190 -p tcp --match multiport --dports 22,8080 -j ACCEPT
done
 
Old 06-25-2015, 06:16 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,363

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
.. which would add it to the in-memory cfg. Ensure you save it to disk to persist across reboots.
 
  


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
A script to manipulate a wordlist Jajamd Programming 7 12-03-2011 09:15 AM
[SOLVED] how to manipulate sysctl_tcp_... variables hayf Programming 1 08-23-2011 03:48 AM
Bash Script: parse active process stderr, strip, dump into variables, use variables TimeFade Programming 1 02-13-2010 06:09 AM
how to manipulate iptables in RHEL3 using ssh dsids Red Hat 4 06-23-2006 04:44 AM
how to manipulate string in script? ringerxyz Programming 2 02-17-2005 01:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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