Run iptables as normal

2 views
Skip to first unread message

Nooh Pulakkal

unread,
Oct 15, 2015, 11:00:51 AM10/15/15
to mes-...@googlegroups.com
Hi all,


I have came across a situation to save my iptables configuration using normal user without touching sudoers file.

Deeper:

I want to run 'sudo iptables -I INPUT -p tcp --dport 1950 -j ACCEPT;sudo iptables-save > /etc/sysconfig/iptables.log' logged in as normal user.

(I am able to run sudo runuser -l root -c 'iptables-save > /etc/sysconfig/iptables.log') //to explain that I(with sudo) have all write permissions

Is there anyway to run iptables-save and append to new log file /etc/sysconfig.log without touching sudoers ?

I dont have runuser installed on my target VMs, and I have huge number of target VMs which is making me lazy to login to each servers. Stuck in between a script.. :(

Any helps appreciated please..!

Great Thanks in advance..!!

--
With Regards,
Nooh P P
+919633195109

Nooh

unread,
Oct 16, 2015, 7:45:54 AM10/16/15
to MES-FSUG
Hi all,

Lucky..!

I have found it out;

sudo su - root << EOF

iptables -I INPUT -p tcp --dport 1950 -j ACCEPT;
iptables-save > /etc/sysconfig/iptables.log;
EOF


, but now got a different issue:

script is not taking next values in 'for' loop:

for i in `cat $1`
do
scp -o "StrictHostKeyChecking no" test.sh my_user@$i:/tmp/
ssh -o "StrictHostKeyChecking no" my_user@$i "sudo chmod +x /tmp/test.sh ; sh /tmp/test.sh"
done


test.sh is here
----------------
#!/bin/bash

sudo hostname;

function iptable_saving
{
sudo su - root << EOF

iptables -I INPUT -p tcp --dport 1950 -j ACCEPT;
iptables-save > /etc/sysconfig/iptables.log;
EOF
}

echo " Saving iptables and logs to /etc/sysconfig/iptables.log..";
iptable_saving;

echo "########################################..Completed..#############################################";
sudo rm -f /tmp/test.sh

But it seems like(output in my terminal) :

localhost
########################################..Completed..#############################################
^CKilled by signal 2.

>>> It is stuck at the stage and when I try to kill using Ctrl+C, then it will take the next value..

Any helps are appreciated please.

Great Thanks in Advance ..!!
Reply all
Reply to author
Forward
0 new messages