I’m trying to execute route add command with PHP this way:
exec("/sbin/route -net 127.0.0.1", $output); and I’m getting SIOCADDRT operation not permitted. I suppose this is because I don’t execute the route command through sudo.
But I can’t do sudo from php because the command asks for the su password. So how can I run route add without sudo?
Thanks!
The best way to do this is, IMHO, is to create a shell script which use this command. After that, allow this shell script to be executed as root in
/etc/sudoers.The syntax to add in sudoers file can be found in this question’s accepted answer.
So you just need to:
This way, your root password is not exposed and you can add any command you’d like in your script.