WriteInterfaces

Aus Programmers Guide

Version vom 17:50, 6. Sep. 2010 bei Roy (Diskussion | Beiträge)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Die /etc/network/interfaces mit PHP schreiben

<?php
function writeInterfaces($ip,$gw,$dns){
/**
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
 
# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
auto eth1
iface eth1 inet static
        address 192.168.1.245
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.253
        dns-nameservers 192.168.1.253
        dns-search elektrohauffe.intern
*/
$tmpSplit=preg_split("/\./",$ip);
$subnet=$tmpSplit[0].".".$tmpSplit[1].".".$tmpSplit[2];
 
$inhalt="
auto lo
iface lo inet loopback
 
# The primary network interface
auto eth1
iface eth1 inet static
        address $ip
        netmask 255.255.255.0
        network $subnet.0
        broadcast $subnet.255
        gateway $gw
        dns-nameservers $gw
        dns-search $dns";
 
if(file_put_contents("/etc/network/interfaces",$inhalt)){
	return true;
}
return false;
}
 
//Beispiel
writeInterfaces('192.168.100.50','192.168.100.1','192.168.100.100');
?>


ReadInterfaces

Persönliche Werkzeuge