-2

I want to statically assign the IP address of my Arch linux using php. I want to change the IP by using netmask,interface,broadcast,address & gateway. The user puts up the values into a html page. The html page posts the data to the PHP page. I want to change the ip using this data. ho to do this?? please help me on this.

Can Files be used?

I was thinking of writing directly into the rc.conf using files!!...will this work and how??.. I have my arch linux up with apache & php..any of the help is appreciate.

  • 3
    If you are going to roll edits back, at least have the courtesy to improve upon the edited version in the process... – jasonwryan Jun 7 '12 at 22:05
1

If you want to change IP permanently you need to modify values in rc.conf. After that modification you need to restart network service. You can do that in two ways:

/etc/rc.d/network restart

or

rc.d restart network

To modify rc.conf and restart service you need root privileges. As running apache as root isn't good idea I would recommend creating some wrapper that is started using sudo for restarting services and modifying rc.conf.

PHP script -> start shell script sudo ./modify-network IP NETMASK GW

Sudo entry for this should be in format:

www ALL=(root) NOPASSWD: /path/to/modify-network

Remember to filter your input in PHP script. Check if IP number is real IP not rc.conf-injection ;) like 192.168.0.100"\nDAEMONS=(!apache).

And remember to redirect user to new address after you change it (when user press "Change IP" button, post data, do some javascript sleep 1 and window.location.href = 'http://NEW_IP/';

You could also use SELinux to add more security to this solution...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.