2

I am trying to save iptables rules file to /etc/sysconfig/iptables. I want to do this without logging in to root. I tried to using

sudo iptables-save > /etc/sysconfig/iptables

but it throws permission denied error.

How can i save the file without logging in to root ? I am using this in my app so i don't want to login to root through the app.

Thanks

john
  • 45
  • 1
  • 6

2 Answers2

6

To use sudo, you can do sudo iptables-save | sudo tee /etc/sysconfig/iptables

The shell don't have the right to write in /etc/sysconfig/iptables, as it is run in your user.

Dom
  • 6,628
  • 1
  • 19
  • 24
1

the standard out redirect is being issued by you not root ... this one-liner works

sudo bash -c "iptables-save > /etc/iptables/rules.v4 "
Scott Stensland
  • 225
  • 4
  • 10